:root {
    --md-primary: #1976d2;
    --md-primary-variant: #1565c0;
    --md-bg: #f8f9fa;
    --md-surface: #ffffff;
    --md-on-surface: #1f1f1f;
    --md-on-surface-variant: #616161;
    --md-outline: #e0e0e0;
    
    --color-join: #2e7d32;
    --bg-join: #e8f5e9;
    --color-left: #c62828;
    --bg-left: #ffebee;
    --color-wait: #ed6c02;
    --bg-wait: #fff3e0;

    --radius-card: 16px;
    --radius-chip: 8px;
    --shadow-1: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.12);
    --shadow-2: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  }

  * { box-sizing: border-box; }

  body {
    font-family: 'Roboto', system-ui, -apple-system, sans-serif;
    margin: 0;
    background-color: var(--md-bg);
    color: var(--md-on-surface);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-bottom: 24px;
  }

  header {
    color: #000000;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(25,118,210,0.2), 0 1px 3px rgba(0,0,0,0.1);
  }

  .header-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
  }

  .app-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255,255,255,0.2);
    padding: 4px;
    flex-shrink: 0;
    object-fit: contain;
  }

  .header-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    color: #000000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .last-updated {
    font-size: 0.75rem;
    color: rgba(48, 46, 46, 0.75);
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  .header-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.18);
    color: #000000;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.2s;
    white-space: nowrap;
  }

  .header-btn:hover {
    background: rgba(255,255,255,0.3);
    color: #000000;
  }

  .header-btn .material-symbols-outlined {
    font-size: 18px;
  }

  /* ── Header page menu: left drawer ── */
  .nav-menu {
    position: relative;
    display: flex;
    flex: 0 0 auto;
  }

  /* Mobile-only page switcher (see the max-width: 600px block at the end) */
  .bottom-nav { display: none; }

  .nav-scrim {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.24s ease, visibility 0s linear 0.24s;
  }

  body.nav-open .nav-scrim {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.24s ease, visibility 0s;
  }

  @media (min-width: 601px) {
    body.nav-open { overflow: hidden; }
  }

  .nav-menu-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1001;
    width: 288px;
    max-width: 85vw;
    padding: 14px 12px;
    background: var(--md-surface);
    border-right: 1px solid var(--md-outline);
    box-shadow: 4px 0 24px rgba(0,0,0,0.16);
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.24s ease, visibility 0s linear 0.24s;
  }

  body.nav-open .nav-menu-panel {
    transform: none;
    visibility: visible;
    transition: transform 0.24s ease, visibility 0s;
  }

  .nav-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 4px 10px 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--md-outline);
  }

  .nav-drawer-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--md-on-surface-variant);
  }

  .nav-drawer-close {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .nav-drawer-close:hover { background: rgba(0,0,0,0.06); }
  .nav-drawer-close .material-symbols-outlined { font-size: 20px; }

  .nav-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 10px;
    color: var(--md-on-surface);
    text-decoration: none;
    line-height: 1.25;
  }

  .nav-menu-item:hover { background: rgba(25,118,210,0.08); }
  .nav-menu-item[aria-current="page"] { background: rgba(25,118,210,0.1); }

  .nav-menu-icon {
    font-size: 20px;
    color: var(--md-primary);
    flex: 0 0 auto;
  }

  .nav-menu-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .nav-menu-text b { font-size: 0.85rem; font-weight: 600; }
  .nav-menu-text small { font-size: 0.72rem; color: var(--md-on-surface-variant); }
  .nav-menu-check { margin-left: auto; font-size: 18px; color: var(--md-primary); }

  @media (hover: none) {
    .nav-menu-item:hover { background: transparent; }
    .nav-menu-item[aria-current="page"]:hover { background: rgba(25,118,210,0.1); }
    .nav-menu-item:active { background: rgba(25,118,210,0.08); }
  }

  .icon-btn {
    background: transparent;
    border: none;
    color: rgba(96, 169, 252, 0.85);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0;
  }

  .icon-btn:hover { background: rgba(255,255,255,0.15); }
  .icon-btn:active { background: rgba(255,255,255,0.25); }
  .icon-btn.spinning .material-symbols-outlined {
    animation: spin 1s linear infinite;
  }

  @keyframes spin { 100% { transform: rotate(360deg); } }

  main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
  }

  .section-title {
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--md-on-surface-variant);
    margin: 24px 0 12px 4px;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .date-group-header {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--md-primary);
    background: #e3f2fd;
    padding: 6px 12px;
    border-radius: 8px;
    margin: 20px 0 8px 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  details.card {
    background: var(--md-surface);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-1);
    margin-bottom: 12px;
    border: 1px solid var(--md-outline);
    overflow: hidden;
    transition: box-shadow 0.2s, border-color 0.2s;
  }

  details.card[open] {
    box-shadow: var(--shadow-2);
    border-color: #bbdefb;
  }

  details.card.latest {
    border: 2px solid #ffa726;
  }

  summary {
    padding: 14px 16px;
    cursor: pointer;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    user-select: none;
    position: relative;
  }

  summary::-webkit-details-marker { display: none; }

  .summary-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .summary-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--md-on-surface);
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .expand-icon {
    color: var(--md-on-surface-variant);
    transition: transform 0.2s ease;
  }

  details[open] summary .expand-icon {
    transform: rotate(180deg);
  }

  .badges-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 2px;
  }

  .chip {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: var(--radius-chip);
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }

  .chip-reg { background: #e3f2fd; color: #1565c0; }
  .chip-wait { background: #fff3e0; color: #e65100; }
  .chip-open { background: #e8f5e9; color: #2e7d32; }
  .chip-full { background: #ffebee; color: #c62828; font-weight: 700; }
  .chip-latest { background: #fff8e1; color: #b78103; border: 1px solid #ffe082; font-weight: 700; }
  .chip-relative { background: #f3e5f5; color: #7b1fa2; font-weight: 600; }

  .event-subtitle {
    font-size: 0.8rem;
    color: var(--md-on-surface-variant);
  }

  .card-body {
    padding: 0 16px 16px 16px;
    border-top: 1px solid var(--md-outline);
    background: #fafafa;
  }

  /* 4-column layout for desktop browsers */
  .event-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1.2fr;
    gap: 16px;
    margin-top: 16px;
  }

  .box-container {
    background: var(--md-surface);
    border: 1px solid var(--md-outline);
    border-radius: 12px;
    padding: 12px;
  }

  .box-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--md-on-surface-variant);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
  }

  /* Two inner columns specifically for registered roster */
  .roster-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
  }

  ol.people-list {
    margin: 0;
    padding-left: 20px;
    font-size: 0.875rem;
  }

  ol.people-list li {
    padding: 2px 0;
  }

  /* Unfilled capacity: numbered but blank rows, e.g. "24. __________" */
  ol.people-list li.open-slot,
  .cal-roster-list li.open-slot {
    color: #cfd8dc;
    letter-spacing: 1px;
    user-select: none;
  }

  .empty-state {
    color: #9e9e9e;
    font-size: 0.85rem;
    font-style: italic;
  }

  .log-card {
    background: var(--md-surface);
    border-radius: var(--radius-card);
    border: 1px solid var(--md-outline);
    padding: 6px 14px;
    box-shadow: var(--shadow-1);
  }

  .row {
    padding: 5px 0;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: baseline;
    gap: 10px;
  }

  .row:last-child { border-bottom: none; }

  .row-main {
    flex: 1;
    min-width: 0;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .action-chip {
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.74rem;
  }

  .j { background: var(--bg-join); color: var(--color-join); }
  .l { background: var(--bg-left); color: var(--color-left); }
  .w { background: var(--bg-wait); color: var(--color-wait); }

  .time {
    flex-shrink: 1;
    min-width: 0;
    max-width: 46%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--md-on-surface-variant);
    font-size: 0.7rem;
  }

  .err {
    background: var(--bg-left);
    color: var(--color-left);
    padding: 16px;
    border-radius: var(--radius-card);
    font-weight: 500;
  }

  /* Navigation Toolbar */
  .nav-toolbar {
    background: var(--md-surface);
    border-radius: var(--radius-card);
    padding: 10px 16px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-1);
    border: 1px solid var(--md-outline);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
  }

  .view-segmented-btn {
    display: inline-flex;
    background: #f1f3f4;
    padding: 3px;
    border-radius: 24px;
    border: 1px solid var(--md-outline);
  }

  .seg-btn {
    border: none;
    background: transparent;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
  }

  .seg-btn:hover {
    color: var(--md-on-surface);
  }

  .seg-btn.active {
    background: var(--md-surface);
    color: var(--md-primary);
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  }

  .date-nav-controls {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .date-display-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--md-on-surface);
    min-width: 170px;
    text-align: center;
  }

  .nav-btn {
    border: 1px solid var(--md-outline);
    background: var(--md-surface);
    color: var(--md-on-surface);
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s;
  }
  .nav-btn:hover { background: #f5f5f5; }
  .nav-btn:active { background: #eeeeee; }
  .nav-btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
  }

  /* Weekly Calendar Grid */
  .calendar-week-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .calendar-week-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(300px, 1fr));
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 12px;
    -webkit-overflow-scrolling: touch;
  }

  .week-day-col {
    background: var(--md-surface);
    border-radius: var(--radius-card);
    border: 1px solid var(--md-outline);
    display: flex;
    flex-direction: column;
    min-height: 520px;
    box-shadow: var(--shadow-1);
    overflow: hidden;
  }

  .week-day-col.is-today {
    border: 2px solid var(--md-primary);
  }

  .week-col-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--md-outline);
    background: #fafafa;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    transition: background-color 0.15s;
    user-select: none;
  }

  .week-col-header:hover {
    background: #f0f4f8;
  }

  .week-day-col.is-today .week-col-header {
    background: #e3f2fd;
  }

  .week-day-name {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--md-on-surface-variant);
  }

  .week-day-col.is-today .week-day-name {
    color: var(--md-primary);
  }

  .week-day-num {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--md-on-surface);
    line-height: 1.1;
  }

  .week-day-col.is-today .week-day-num {
    color: var(--md-primary);
  }

  .week-col-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    background: #e8eaf6;
    color: #283593;
    margin-top: 2px;
  }

  .week-col-content {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-grow: 1;
    background: #fbfbfb;
  }

  .cal-event-card {
    background: var(--md-surface);
    border: 1px solid var(--md-outline);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  }

  .cal-event-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-2);
    border-color: #90caf9;
  }

  .cal-event-card.latest-card {
    border-left: 4px solid #ffa726;
  }

  .cal-event-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .cal-event-time-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
  }

  .cal-event-time {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--md-primary);
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .cal-event-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--md-on-surface);
    line-height: 1.25;
  }

  .cal-badges-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
  }

  .cal-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
  }

  .cal-badge-reg { background: #e3f2fd; color: #1565c0; }
  .cal-badge-wait { background: #fff3e0; color: #e65100; }
  .cal-badge-open { background: #e8f5e9; color: #2e7d32; }
  .cal-badge-full { background: #ffebee; color: #c62828; font-weight: 700; }
  .cal-badge-latest { background: #fff8e1; color: #b78103; border: 1px solid #ffe082; }

  .cal-roster-section {
    background: #fafafa;
    border: 1px solid #eeeeee;
    border-radius: 8px;
    padding: 8px;
  }

  .cal-roster-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--md-on-surface-variant);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
  }

  .cal-roster-list {
    margin: 0;
    padding-left: 18px;
    font-size: 0.78rem;
    max-height: 150px;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .cal-roster-list li {
    padding: 1px 0;
    color: var(--md-on-surface);
    word-break: break-word;
  }

  .cal-roster-list.waitlist-list li {
    color: #e65100;
  }

  .cal-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--md-primary);
    font-weight: 500;
    padding-top: 4px;
    border-top: 1px dashed #e0e0e0;
  }

  .cal-empty-col {
    color: #9e9e9e;
    font-size: 0.8rem;
    font-style: italic;
    text-align: center;
    padding: 40px 8px;
  }

  /* Open court availability */
  .court-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 4px 0;
    border-top: 1px dashed var(--md-outline);
  }

  .box-title + .court-row { border-top: none; }

  .court-name {
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 72px;
    flex-shrink: 0;
  }

  .court-windows {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  .court-updated {
    margin-left: auto;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.7rem;
  }

  .court-week-list {
    margin: 0;
    padding-left: 16px;
    font-size: 0.75rem;
  }

  .court-count {
    color: #2e7d32;
    font-weight: 600;
  }

  /* Day View */
  .day-view-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .day-ribbon {
    position: relative;
    display: flex;
    gap: 6px;
    background: var(--md-surface);
    padding: 8px;
    border-radius: var(--radius-card);
    border: 1px solid var(--md-outline);
    box-shadow: var(--shadow-1);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }

  .day-ribbon-btn {
    flex: 0 0 auto;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 10px;
    padding: 10px 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: all 0.15s;
    min-width: 84px;
  }

  /* Small break between weeks on the long day strip. */
  .day-ribbon-btn.week-gap {
    margin-left: 8px;
  }

  /* Touch devices swipe the strip, so keep the scrollbar out of the way there. */
  @media (hover: none) {
    .day-ribbon {
      scrollbar-width: none;
    }
    .day-ribbon::-webkit-scrollbar {
      display: none;
    }
  }

  .day-ribbon-btn:hover {
    background: #f0f4f8;
  }

  .day-ribbon-btn.active {
    background: #e3f2fd;
    border-color: #90caf9;
  }

  .ribbon-day-name {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--md-on-surface-variant);
  }

  .day-ribbon-btn.active .ribbon-day-name {
    color: var(--md-primary);
  }

  .ribbon-day-val {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--md-on-surface);
  }

  .day-ribbon-btn.active .ribbon-day-val {
    color: var(--md-primary);
  }

  .ribbon-event-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--md-primary);
    margin-top: 2px;
  }

  .day-compact-date {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    background: var(--md-surface);
    border-radius: 12px;
    border: 1px solid var(--md-outline);
    margin-bottom: 12px;
  }
  .day-compact-date .compact-date-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--md-on-surface);
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .day-header-card {
    background: var(--md-surface);
    border-radius: var(--radius-card);
    border: 1px solid var(--md-outline);
    box-shadow: var(--shadow-1);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
  }

  .day-header-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--md-on-surface);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .day-slot-card {
    background: var(--md-surface);
    border-radius: var(--radius-card);
    border: 1px solid var(--md-outline);
    box-shadow: var(--shadow-1);
    overflow: hidden;
    margin-bottom: 16px;
  }

  .day-slot-header {
    padding: 16px;
    background: #fafafa;
    border-bottom: 1px solid var(--md-outline);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
  }

  .day-slot-title-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .day-slot-time {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--md-primary);
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .day-slot-events {
    font-size: 0.85rem;
    color: var(--md-on-surface-variant);
  }

  .day-slot-body {
    padding: 16px;
  }

  /* Modal Pop-up */
  .modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
  }

  .modal-overlay.open {
    opacity: 1;
    visibility: visible;
  }

  .modal-window {
    background: var(--md-surface);
    border-radius: var(--radius-card);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 820px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.96);
    transition: transform 0.2s ease;
  }

  .modal-overlay.open .modal-window {
    transform: scale(1);
  }

  .modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--md-outline);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    background: #ffffff;
  }

  .modal-title-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
  }

  .modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--md-on-surface);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .modal-subtitle {
    font-size: 0.85rem;
    color: var(--md-on-surface-variant);
  }

  .modal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }

  .modal-close-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--md-on-surface-variant);
    transition: background 0.15s;
  }

  .modal-close-btn:hover {
    background: #eeeeee;
    color: var(--md-on-surface);
  }

  .modal-summary-bar {
    padding: 10px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--md-outline);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }

  .modal-tab-nav {
    display: flex;
    border-bottom: 1px solid var(--md-outline);
    background: #f8f9fa;
    padding: 0 16px;
    gap: 8px;
  }

  .modal-tab-btn {
    background: transparent;
    border: none;
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
  }

  .modal-tab-btn:hover {
    color: var(--md-on-surface);
  }

  .modal-tab-btn.active {
    color: var(--md-primary);
    border-bottom-color: var(--md-primary);
    font-weight: 700;
  }

  .tab-count-badge {
    background: #e0e0e0;
    color: #424242;
    font-size: 0.72rem;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
  }

  .modal-tab-btn.active .tab-count-badge {
    background: #bbdefb;
    color: #1565c0;
  }

  .modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(90vh - 180px);
  }

  .modal-roster-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .search-wrap {
    position: relative;
    margin-bottom: 12px;
  }

  .search-wrap .material-symbols-outlined {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: #9e9e9e;
  }

  .search-input-box {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--md-outline);
    border-radius: 8px;
    font-size: 0.85rem;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s;
  }

  .search-input-box:focus {
    border-color: var(--md-primary);
  }

  /* ── Stacked roster: registered, waitlist, activity each full-width ── */
  .event-grid-stacked {
    grid-template-columns: 1fr !important;
  }

  /* Responsive Adjustments for Mobile & Tablets */
  @media (max-width: 992px) {
    .event-grid {
      grid-template-columns: 1fr;
    }
  }

  @media (max-width: 768px) {
    .badges-row {
      gap: 4px;
    }
    .badges-row .header-btn {
      padding: 2px 6px;
      font-size: 0.7rem;
    }
    .badges-row .chip {
      font-size: 0.68rem;
      padding: 1px 6px;
    }
    summary { padding: 10px 12px; }
    .card-body { padding: 0 10px 10px 10px; }
  }

  @media (max-width: 600px) {
    /* ── Header: compact layout ── */
    header {
      padding: 8px 10px;
      gap: 6px;
    }
    .header-title-group { gap: 6px; }
    .app-icon {
      width: 28px;
      height: 28px;
      padding: 3px;
      border-radius: 8px;
    }
    header h1 { font-size: 0.95rem; }
    .last-updated { display: none; }
    .header-actions { gap: 4px; min-width: 0; flex-shrink: 1; }
    .header-actions .header-btn { flex: 0 0 auto; }
    .user-name-wrap, .user-welcome { min-width: 0; }
    .user-welcome .welcome-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

    /* Phones use the bottom navigation bar instead of the header menu */
    .nav-menu { display: none; }

    /* Header buttons: icon-only circles */
    .header-btn .btn-label { display: none; }
    .header-btn {
      width: 36px;
      height: 36px;
      padding: 0;
      border-radius: 50%;
      justify-content: center;
      background: transparent;
      border: none;
    }
    .header-btn:hover { background: rgba(255,255,255,0.25); }
    .header-btn:active { background: rgba(255,255,255,0.35); }
    .header-btn .material-symbols-outlined { font-size: 22px; }

    /* User name input: compact */
    .user-name-wrap .material-symbols-outlined { font-size: 16px; }
    .user-name-input {
      width: 150px;
      font-size: 0.8rem;
      padding: 3px 8px;
    }
    .user-name-saved { font-size: 14px; }

    /* Reload button: slightly smaller */
    .icon-btn { width: 36px; height: 36px; }

    /* ── Tab menu: icon-only, full-width ── */
    .nav-toolbar {
      flex-direction: column;
      padding: 8px 10px;
      gap: 8px;
    }
    .view-segmented-btn {
      width: 100%;
      justify-content: space-around;
    }
    .seg-btn {
      padding: 6px 8px;
      font-size: 0.8rem;
      gap: 4px;
      flex: 1;
      justify-content: center;
    }
    .seg-btn .seg-label { display: none; }
    .seg-btn .material-symbols-outlined { font-size: 20px; }

    /* Date nav: full-width row below tabs */
    .date-nav-controls {
      width: 100%;
      justify-content: space-between;
    }
    .date-display-title { font-size: 0.9rem; min-width: unset; }
    .nav-btn { padding: 5px 8px; font-size: 0.82rem; }
    .nav-btn-icon { width: 32px; height: 32px; }

    main { padding: 10px 6px; }
    summary { padding: 10px; }
    .card-body { padding: 0 10px 10px 10px; }
    .modal-roster-grid { grid-template-columns: 1fr; }

    /* ── Mobile Day View ── */
    .day-compact-date {
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: 8px;
      padding: 10px 12px;
      background: var(--md-surface);
      border-radius: 12px;
      border: 1px solid var(--md-outline);
      margin-bottom: 12px;
    }
    .day-compact-date .compact-date-label {
      font-size: 0.9rem;
      font-weight: 600;
      color: var(--md-on-surface);
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .day-header-card {
      padding: 8px 12px;
      flex-wrap: nowrap;
      gap: 8px;
    }
    .day-header-title { font-size: 1rem; }
    .day-header-card .chip-relative {
      font-size: 0.7rem;
      padding: 2px 6px;
    }
    .day-slot-header {
      padding: 10px 12px;
      gap: 6px;
    }
    .day-slot-time { font-size: 1rem; }
    .day-slot-events { font-size: 0.82rem; }
    .day-slot-header .header-btn { display: none; }
    .day-slot-body { padding: 10px 12px; }
    .day-slot-body .event-grid {
      grid-template-columns: 1fr 1fr;
      gap: 10px;
    }
    .day-slot-body .box-container { padding: 8px; }
    .day-slot-body .box-title { font-size: 0.78rem; margin-bottom: 4px; }
    .day-slot-body .people-list { font-size: 0.9rem; padding-left: 16px; }
    .day-slot-body .people-list li { padding: 3px 0; }
    .day-slot-body .empty-state { font-size: 0.85rem; }

    /* Day ribbon compact: exactly 7 days fit across the screen, then scroll for more. */
    .day-ribbon { gap: 4px; padding: 6px; }
    .day-ribbon-btn {
      /* 100% is the strip's content width inside its 6px padding, minus six 4px gaps. */
      flex: 0 0 calc((100% - 24px) / 7);
      min-width: 0;
      padding: 6px 2px;
    }
    .day-ribbon-btn.week-gap { margin-left: 0; }
    .ribbon-day-name { font-size: 0.7rem; }
    .ribbon-day-val { font-size: 1.1rem; }

    /* ── Name prompt: mobile fixes ── */
    .prompt-overlay {
      background: rgba(0,0,0,0.7);
      backdrop-filter: none;
      padding: 16px;
    }
    .prompt-card {
      padding: 24px 20px 20px;
      border-radius: 16px;
      gap: 10px;
    }
    .prompt-icon { font-size: 40px; padding: 12px; }
    .prompt-card h2 { font-size: 1.1rem; }
    .prompt-card p { font-size: 0.8rem; }
    .prompt-input { font-size: 16px; padding: 10px 12px; }
    .prompt-actions { flex-direction: column; gap: 8px; }
    .prompt-btn { padding: 12px 16px; font-size: 0.9rem; }
  }

  /* ── User name input ── */
  /* ── User name display & edit ── */
  .user-welcome {
    display: none;
    align-items: center;
    gap: 6px;
    color: rgba(46, 46, 46, 0.9);
    font-size: 0.82rem;
    cursor: default;
  }
  .user-welcome.visible { display: inline-flex; }
  .user-welcome .welcome-text { white-space: nowrap; }
  .user-welcome .welcome-text b { color: #242424; }
  .edit-name-btn {
    font-size: 16px;
    color: rgba(92, 91, 91, 0.6);
    cursor: pointer;
    transition: color 0.15s;
  }
  .edit-name-btn:hover { color: #272727; }

  .user-input-wrap {
    display: none;
    align-items: center;
    gap: 4px;
  }
  .user-input-wrap.visible { display: inline-flex; }

  .user-name-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .user-name-input {
    border: 1px solid var(--md-outline);
    border-radius: 16px;
    padding: 4px 10px;
    font-size: 0.8rem;
    font-family: inherit;
    color: var(--md-on-surface);
    background: var(--md-surface);
    outline: none;
    width: 110px;
    transition: border-color 0.2s, box-shadow 0.2s;
  }
  .user-name-input:focus {
    border-color: var(--md-primary);
    box-shadow: 0 0 0 2px rgba(25,118,210,0.15);
  }
  .user-name-input::placeholder {
    color: #bdbdbd;
  }
  .user-name-saved {
    color: #2e7d32;
    font-size: 16px;
  }

  /* ── User highlight in registrant lists ── */
  .user-match {
    display: inline-block;
    font-weight: 700;
    color: #1565c0;
    background: #e3f2fd;
    border-radius: 4px;
    padding: 2px 6px;
    margin: 1px -6px;
  }
  .user-match-waitlist {
    display: inline-block;
    font-weight: 700;
    color: #e65100;
    background: #fff3e0;
    border-radius: 4px;
    padding: 2px 6px;
    margin: 1px -6px;
  }

  /* ── User registration status badge ── */
  .user-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    margin-top: 4px;
  }
  .user-status-badge.registered {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
  }
  .user-status-badge.waitlisted {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid #ffcc80;
  }
  .user-status-badge.not-registered {
    background: #f5f5f5;
    color: #9e9e9e;
    border: 1px solid #e0e0e0;
  }

  /* ── Countdown chip for registration window ── */
  .chip-countdown {
    background: #e8eaf6;
    color: #283593;
    border: 1px solid #c5cae9;
    font-weight: 600;
  }

  /* ── Day view swipe navigation ── */
  .day-view-container {
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior-x: contain;
  }
  .day-view-container.is-swiping {
    transition: none;
    will-change: transform;
  }

  /* Slide the incoming day in from the side the user swiped from. */
  #viewContainer.day-slide-in {
    animation: daySlideFromLeft 0.22s cubic-bezier(0.2, 0.7, 0.3, 1) both;
  }
  #viewContainer.day-slide-in.from-next {
    animation-name: daySlideFromRight;
  }
  @keyframes daySlideFromLeft {
    from { opacity: 0.4; transform: translateX(-26px); }
    to   { opacity: 1; transform: none; }
  }
  @keyframes daySlideFromRight {
    from { opacity: 0.4; transform: translateX(26px); }
    to   { opacity: 1; transform: none; }
  }
  @media (prefers-reduced-motion: reduce) {
    #viewContainer.day-slide-in { animation: none; }
    .day-view-container { transition: none !important; }
  }

  /* ── Activity view (compact list) ── */
  .activity-view-container {
    display: block;
  }
  .activity-log-card {
    background: var(--md-surface);
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-1);
    padding: 2px 12px;
  }
  .activity-log-row {
    display: grid;
    grid-template-columns: 16px minmax(64px, 130px) auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    padding: 5px 0;
    border-bottom: 1px solid #f2f2f2;
    font-size: 0.8rem;
    line-height: 1.25;
  }
  .activity-log-row:last-child { border-bottom: none; }
  .activity-day-separator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0 3px;
    color: var(--md-on-surface-variant);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  .activity-day-separator:first-child { padding-top: 4px; }
  .activity-day-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--md-outline);
  }
  .activity-log-row .act-icon {
    font-size: 16px;
  }
  .activity-log-row .act-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .activity-log-row .action-chip {
    padding: 1px 5px;
    font-size: 0.68rem;
    gap: 0;
    white-space: nowrap;
  }
  .activity-log-row .act-meta {
    min-width: 0;
    color: var(--md-on-surface-variant);
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .activity-log-row .act-time {
    color: var(--md-on-surface-variant);
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  /* Narrow screens: keep name/status/time on one line, drop the event context below it. */
  @media (max-width: 480px) {
    .user-welcome .welcome-prefix { display: none; }
    .activity-log-row {
      grid-template-columns: 16px minmax(0, 1fr) auto auto;
      grid-template-areas:
        "icon name chip time"
        "icon meta meta meta";
      row-gap: 1px;
    }
    .activity-log-row .act-icon { grid-area: icon; align-self: start; }
    .activity-log-row .act-name { grid-area: name; }
    .activity-log-row .action-chip { grid-area: chip; }
    .activity-log-row .act-time { grid-area: time; }
    .activity-log-row .act-meta { grid-area: meta; }
  }

  /* ── Toast notifications ── */
  .toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
  }
  .toast {
    background: var(--md-surface);
    border: 1px solid var(--md-outline);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: toastIn 0.3s ease;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1.35;
  }
  .toast.dismissing { animation: toastOut 0.25s ease forwards; }
  .toast .toast-icon { flex-shrink: 0; margin-top: 1px; }
  .toast .toast-body { flex: 1; min-width: 0; }
  .toast .toast-title { font-weight: 700; margin-bottom: 2px; }
  .toast .toast-when {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--md-primary);
  }
  .toast .toast-when .material-symbols-outlined { font-size: 14px; }
  .toast .toast-event {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--md-on-surface);
    overflow-wrap: anywhere;
  }
  .toast .toast-detail { color: var(--md-on-surface-variant); font-size: 0.8rem; margin-top: 2px; }
  /* Named roster movements (who joined / left / moved lists) */
  .toast .toast-changes {
    list-style: none;
    margin: 6px 0 0 0;
    padding: 6px 0 0 0;
    border-top: 1px solid var(--md-outline);
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.78rem;
  }
  .toast .toast-changes li { display: flex; align-items: flex-start; gap: 4px; overflow-wrap: anywhere; }
  .toast .toast-changes .material-symbols-outlined { font-size: 14px; flex-shrink: 0; }
  .toast .toast-changes .tc-j .material-symbols-outlined { color: #2e7d32; }
  .toast .toast-changes .tc-w .material-symbols-outlined { color: #ed6c02; }
  .toast .toast-changes .tc-l .material-symbols-outlined { color: #c62828; }
  .toast .toast-changes .toast-more { color: var(--md-on-surface-variant); font-style: italic; }
  .toast.spot-open { border-left: 4px solid #2e7d32; }
  .toast.change { border-left: 4px solid #1976d2; }

  /* Toasts never auto-dismiss, so each one carries an explicit close button */
  .toast .toast-close {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    margin: -4px -8px -2px 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #9e9e9e;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
  }
  .toast .toast-close:hover { background: #f0f0f0; color: var(--md-on-surface); }
  .toast .toast-close .material-symbols-outlined { font-size: 16px; }

  .toast-clear-all {
    display: none;
    align-self: flex-end;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--md-outline);
    border-radius: 999px;
    background: var(--md-surface);
    color: var(--md-on-surface-variant);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-1);
    transition: color 0.15s, border-color 0.15s;
  }
  .toast-clear-all.visible { display: inline-flex; }
  .toast-clear-all:hover { color: #c62828; border-color: #ef9a9a; }
  .toast-clear-all .material-symbols-outlined { font-size: 15px; }
  @keyframes toastIn { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }
  @keyframes toastOut { from { opacity:1; transform:translateY(0); } to { opacity:0; transform:translateY(20px); } }

  /* ── Watch star button ── */
  .watch-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #bdbdbd;
    padding: 2px 4px;
    border-radius: 50%;
    transition: color 0.15s, transform 0.15s;
    flex-shrink: 0;
    line-height: 1;
  }
  .watch-btn:hover { color: #f9a825; transform: scale(1.2); }
  .watch-btn.watching { color: #f9a825; }
  .watch-btn .material-symbols-outlined { font-size: 18px; font-variation-settings: 'FILL' 1; }
  .watch-btn:not(.watching) .material-symbols-outlined { font-variation-settings: 'FILL' 0; }

  /* ── Name prompt overlay ── */
  .prompt-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s, visibility 0.25s;
  }
  .prompt-overlay.open {
    opacity: 1;
    visibility: visible;
  }
  .prompt-card {
    background: var(--md-surface);
    border-radius: 20px;
    padding: 32px 28px 24px;
    max-width: 380px;
    width: 100%;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }
  .prompt-icon {
    font-size: 48px;
    color: var(--md-primary);
    background: #e3f2fd;
    border-radius: 50%;
    padding: 14px;
  }
  .prompt-card h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--md-on-surface);
  }
  .prompt-card p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--md-on-surface-variant);
    line-height: 1.4;
  }
  .prompt-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--md-outline);
    border-radius: 12px;
    font-size: 0.95rem;
    font-family: inherit;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
  }
  .prompt-input:focus { border-color: var(--md-primary); }
  .prompt-actions {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-top: 4px;
  }
  .prompt-btn {
    flex: 1;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
  }
  .prompt-btn.primary {
    background: var(--md-primary);
    color: #fff;
  }
  .prompt-btn.primary:hover { background: #1565c0; }
  .prompt-btn.secondary {
    background: #f5f5f5;
    color: var(--md-on-surface-variant);
  }
  .prompt-btn.secondary:hover { background: #e0e0e0; }

  /* ── Open courts panel: tappable affordance ── */
  .courts-panel {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  .courts-panel:hover { border-color: #a5d6a7; box-shadow: var(--shadow-2); }
  .courts-panel:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
  .courts-more {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--md-outline);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--md-primary);
    letter-spacing: 0.2px;
  }

  /* ── Court availability timeline modal ── */
  body.modal-open { overflow: hidden; }

  .courts-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
  }
  .courts-modal-overlay.open { opacity: 1; visibility: visible; }

  .courts-modal {
    background: var(--md-surface);
    border-radius: 18px;
    width: 100%;
    max-width: 780px;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.28);
    transform: translateY(10px);
    transition: transform 0.2s;
  }
  .courts-modal-overlay.open .courts-modal { transform: translateY(0); }

  .courts-modal-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--md-outline);
  }
  .courts-modal-heading { min-width: 0; }
  .courts-modal-heading h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--md-on-surface);
  }
  .courts-modal-sub {
    font-size: 0.75rem;
    color: var(--md-on-surface-variant);
  }
  .courts-modal-close {
    margin-left: auto;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: #f5f5f5;
    color: var(--md-on-surface-variant);
    display: grid;
    place-items: center;
    cursor: pointer;
  }
  .courts-modal-close:hover { background: #e0e0e0; }
  .courts-modal-close .material-symbols-outlined { font-size: 20px; }

  .courts-modal-legend {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--md-outline);
    background: #fafafa;
    font-size: 0.72rem;
    color: var(--md-on-surface-variant);
  }
  .courts-modal-legend .cl-item { display: inline-flex; align-items: center; gap: 5px; }
  .cl-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
  .cl-swatch.free { background: #a5d6a7; border: 1px solid #2e7d32; }
  .cl-swatch.booked { background: #eceff1; border: 1px solid #b0bec5; }
  .cl-swatch.now {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c62828;
  }
  .cl-link {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--md-primary);
    font-weight: 700;
    text-decoration: none;
  }
  .cl-link:hover { text-decoration: underline; }

  .courts-modal-body {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .courts-grid {
    display: grid;
    grid-template-columns: 42px repeat(var(--court-cols, 1), minmax(72px, 1fr));
    column-gap: 6px;
    padding: 0 14px 14px;
  }

  .cg-corner,
  .cg-head {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--md-surface);
    padding: 8px 2px 6px;
  }
  .cg-corner { z-index: 5; left: 0; }
  .cg-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    border-bottom: 2px solid var(--md-outline);
    text-align: center;
  }
  .cg-head-name {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--md-on-surface);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .cg-head-meta { font-size: 0.62rem; font-weight: 600; color: #2e7d32; }
  .cg-head-meta.none { color: #c62828; }

  .cg-ruler {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--md-surface);
    border-right: 1px solid var(--md-outline);
  }
  .court-tick {
    position: absolute;
    right: 4px;
    transform: translateY(-50%);
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--md-on-surface-variant);
    white-space: nowrap;
  }
  .court-tick::after {
    content: '';
    position: absolute;
    top: 50%;
    left: calc(100% + 4px);
    width: 4px;
    height: 1px;
    background: var(--md-outline);
  }
  .court-tick.first { transform: translateY(0); }
  .court-tick.last { transform: translateY(-100%); }

  .cg-col {
    position: relative;
    border-radius: 8px;
    background-color: #fafafa;
    background-image: repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(var(--slot-h, 34px) - 1px),
      rgba(0,0,0,0.07) calc(var(--slot-h, 34px) - 1px),
      rgba(0,0,0,0.07) var(--slot-h, 34px)
    );
  }

  .court-seg {
    position: absolute;
    left: 2px;
    right: 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    overflow: hidden;
    border-radius: 6px;
    padding: 2px;
    text-align: center;
    line-height: 1.15;
    font-size: 0.62rem;
  }
  .court-seg.free {
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    color: #1b5e20;
    font-weight: 700;
  }
  .court-seg.booked {
    background-color: #eceff1;
    background-image: repeating-linear-gradient(45deg, #eceff1 0 5px, #e2e8ea 5px 10px);
    border: 1px solid #dde3e6;
    color: #90a4ae;
    font-weight: 600;
  }
  .court-seg .seg-time { white-space: nowrap; }
  .court-seg.tall { justify-content: flex-start; padding-top: 6px; }
  .court-seg .seg-tag {
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    opacity: 0.75;
  }

  .court-now-line {
    position: absolute;
    left: -2px;
    right: -2px;
    height: 2px;
    background: #c62828;
    border-radius: 2px;
    z-index: 4;
    pointer-events: none;
  }

  @media (max-width: 600px) {
    .courts-modal-overlay { padding: 0; }
    .courts-modal {
      max-width: none;
      height: 100%;
      border-radius: 0;
    }
    .courts-modal-head { padding: 12px 12px 8px; padding-top: max(12px, env(safe-area-inset-top)); }
    .courts-grid { padding: 0 10px 10px; }
    .cl-link { margin-left: 0; }
  }

  /* ── Mobile bottom navigation: floating glass bar ── */
  @media (max-width: 600px) {
    body { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

    .bottom-nav {
      position: fixed;
      left: max(12px, env(safe-area-inset-left));
      right: max(12px, env(safe-area-inset-right));
      bottom: calc(12px + env(safe-area-inset-bottom));
      z-index: 900;
      display: flex;
      gap: 2px;
      padding: 6px;
      background: rgba(255, 255, 255, 0.15);
      backdrop-filter: blur(20px);
      -webkit-backdrop-filter: blur(20px);
      border-radius: 20px;
      border: 1px solid rgba(255, 255, 255, 0.3);
      box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        inset 0 -1px 0 rgba(255, 255, 255, 0.1),
        inset 0 0 12px 6px rgba(255, 255, 255, 0.6);
      overflow: hidden;
    }

    /* Glass edge highlights */
    .bottom-nav::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 1px;
      background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.8),
        transparent
      );
      pointer-events: none;
    }

    .bottom-nav::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 1px;
      height: 100%;
      background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.8),
        transparent,
        rgba(255, 255, 255, 0.3)
      );
      pointer-events: none;
    }

    /* Where backdrop blur is unavailable, fall back to an opaque surface. */
    @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
      .bottom-nav { background: rgba(255, 255, 255, 0.92); }
    }

    .bottom-nav-item {
      flex: 1 1 0;
      min-width: 0;
      min-height: 56px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 2px;
      padding: 6px 4px;
      color: var(--md-on-surface-variant);
      text-decoration: none;
      font-size: 0.68rem;
      font-weight: 500;
      -webkit-tap-highlight-color: transparent;
    }

    .bottom-nav-icon {
      display: grid;
      place-items: center;
      width: 56px;
      height: 28px;
      border-radius: 999px;
      transition: background-color 0.15s;
    }

    .bottom-nav-icon .material-symbols-outlined { font-size: 22px; }

    .bottom-nav-item[aria-current="page"] {
      color: var(--md-primary);
      font-weight: 600;
    }
    .bottom-nav-item[aria-current="page"] .bottom-nav-icon { background: rgba(25, 118, 210, 0.16); }
    .bottom-nav-item[aria-current="page"] .material-symbols-outlined { font-variation-settings: 'FILL' 1; }
    .bottom-nav-item:active .bottom-nav-icon { background: rgba(25, 118, 210, 0.22); }

    /* Keep toasts above the floating bar */
    .toast-container {
      bottom: calc(96px + env(safe-area-inset-bottom));
      left: 12px;
      right: 12px;
      max-width: none;
      max-height: calc(100vh - 200px);
      overflow-y: auto;
    }
  }
