/* ─── RESET & BASE ─────────────────────────────────────────── */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --bg:        #f8f9fa;
      --surface:   #ffffff;
      --border:    #e0e0e0;
      --text:      #1f2329;
      --text-muted:#6b7280;
      --accent:    #1a73e8;
      --accent-bg: #e8f0fe;
      --header-h:  56px;
      --time-col:  42px;
      --mob-left:  2px;   /* left edge safe margin on mobile */
      --hour-h:    60px;  /* height per 1 hour block in calendar grid */
      --radius:    8px;
      --shadow:    0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
      --today-ring:#1a73e8;
    }

    html, body {
      height: 100%;
      font-family: 'Google Sans', 'Roboto', system-ui, -apple-system, sans-serif;
      background: var(--bg);
      color: var(--text);
      overflow: hidden;
    }

    /* ─── HEADER ───────────────────────────────────────────────── */
    #header {
      position: fixed;
      top: 0; left: 0; right: 0;
      height: var(--header-h);
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      padding: 0 12px;
      gap: 8px;
      z-index: 100;
      box-shadow: 0 1px 4px rgba(0,0,0,.08);
    }

    #header .logo {
      font-size: 18px;
      font-weight: 600;
      color: var(--text);
      white-space: nowrap;
      flex-shrink: 0;
    }
    #header .logo span { color: var(--accent); }

    #nav-controls {
      display: flex;
      align-items: center;
      gap: 4px;
      margin-left: 4px;
    }

    .icon-btn {
      width: 36px; height: 36px;
      border: none; background: none;
      border-radius: 50%;
      cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      color: var(--text-muted);
      transition: background .15s;
      flex-shrink: 0;
    }
    .icon-btn:hover { background: var(--bg); }
    .icon-btn svg { width: 20px; height: 20px; fill: currentColor; }

    #period-label {
      font-size: 16px;
      font-weight: 500;
      color: var(--text);
      white-space: nowrap;
      min-width: 130px;
    }


    #header-spacer { flex: 1; }

    /* view toggle tabs (desktop) */
    #view-tabs {
      display: flex;
      gap: 2px;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 2px;
    }
    .view-tab {
      padding: 5px 12px;
      border: none;
      background: none;
      border-radius: 4px;
      font-size: 13px;
      font-weight: 500;
      color: var(--text-muted);
      cursor: pointer;
      transition: background .15s, color .15s;
    }
    .view-tab.active {
      background: var(--surface);
      color: var(--accent);
      box-shadow: var(--shadow);
    }

    /* ─── FILTER BAR ───────────────────────────────────────────── */
    #filter-bar {
      position: fixed;
      top: var(--header-h);
      left: 0; right: 0;
      height: 48px;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      padding: 0 12px;
      gap: 8px;
      z-index: 99;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none;
    }
    #filter-bar::-webkit-scrollbar { display: none; }

    .filter-select {
      height: 32px;
      padding: 0 28px 0 10px;
      border: 1px solid var(--border);
      border-radius: 16px;
      background: var(--surface);
      font-size: 13px;
      color: var(--text);
      cursor: pointer;
      appearance: none;
      -webkit-appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='%236b7280'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 6px center;
      min-width: 110px;
      white-space: nowrap;
      flex-shrink: 0;
      transition: border-color .2s;
    }
    .filter-select:focus {
      outline: none;
      border-color: var(--accent);
    }

    /* ─── MAIN SCROLL AREA ─────────────────────────────────────── */
    #main {
      position: fixed;
      top: calc(var(--header-h) + 48px);
      left: 0; right: 0; bottom: 0;
      overflow: hidden;
    }

    /* ─── DESKTOP CALENDAR (week view) ────────────────────────── */
    #cal-wrap {
      width: 100%; height: 100%;
      overflow-y: auto;
      overflow-x: hidden;
    }

    #cal-wrap::-webkit-scrollbar { width: 6px; }
    #cal-wrap::-webkit-scrollbar-track { background: transparent; }
    #cal-wrap::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

    /* sticky day-header row */
    #day-header-row {
      position: sticky;
      top: 0;
      display: grid;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      z-index: 10;
    }
    .day-header-cell {
      padding: 6px 4px;
      text-align: center;
      font-size: 11px;
      font-weight: 600;
      color: var(--text-muted);
      letter-spacing: .5px;
      text-transform: uppercase;
    }
    .day-header-cell .day-num {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 32px; height: 32px;
      border-radius: 50%;
      font-size: 18px;
      font-weight: 400;
      color: var(--text);
      letter-spacing: 0;
      text-transform: none;
    }
    .day-header-cell.today .day-num {
      background: var(--accent);
      color: #fff;
    }

    /* grid body */
    #cal-grid {
      display: grid;
      position: relative;
    }

    .time-col-header {
      /* corner cell placeholder */
    }

    .hour-row {
      display: contents;
    }

    .time-label {
      position: absolute;
      display: flex;
      align-items: flex-start;
      justify-content: flex-end;
      padding-right: 8px;
      font-size: 11px;
      font-weight: 500;
      color: var(--text-muted);
      white-space: nowrap;
      user-select: none;
      z-index: 3;
      line-height: 1.2;
    }

    .hour-cell {
      border-top: 1px solid var(--border);
      height: var(--hour-h);
      position: relative;
    }
    .hour-cell::after {
      content: '';
      position: absolute;
      top: 50%; left: 0; right: 0;
      border-top: 1px dashed #eee;
    }

    /* lesson blocks */
    .lesson-block {
      position: absolute;
      border-radius: var(--radius);
      padding: 5px 8px;
      overflow: hidden;
      cursor: pointer;
      z-index: 5;
      transition: filter .15s, transform .1s;
      border: none;
      outline: none;
      box-shadow: 0 1px 3px rgba(0,0,0,0.06);
      text-align: left;
      /* 2-col corner layout: name | room / teacher / bottom row
         (time left + type right, spanning both columns) */
      display: grid;
      grid-template-columns: 1fr auto;
      grid-template-rows: auto 1fr auto;
      gap: 2px 6px;
      align-items: start;
      box-sizing: border-box;
      -webkit-appearance: none;
    }
    .lesson-block:hover { filter: brightness(.93); transform: scale(1.01); }

    .lesson-block .lb-name {
      grid-column: 1; grid-row: 1;
      font-size: 13px; font-weight: 700;
      text-align: left;
      overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .lesson-block .lb-room {
      grid-column: 2; grid-row: 1;
      font-size: 12px; font-weight: 600;
      white-space: nowrap; text-align: right;
    }
    .lesson-block .lb-teacher {
      grid-column: 1; grid-row: 2;
      font-size: 11px; font-weight: 400; opacity: .85;
      text-align: left;
      overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
      align-self: start;
    }
    /* bottom row: time (left) always visible + healthy gap + type (right).
       When the row overflows, the type squeezes below its text width and
       the .lb-fade mask dissolves its tail instead of a hard clip; when
       it fits, the badge hugs the card's right edge, fully crisp. */
    .lesson-block .lb-bottom {
      grid-column: 1 / -1; grid-row: 3;
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      gap: 12px;
      align-self: end;
      min-width: 0;
    }
    .lesson-block .lb-time {
      font-size: 11px; opacity: .85;
      white-space: nowrap; text-align: left;
      flex: 0 0 auto;
    }
    .lesson-block .lb-type-badge {
      font-size: 10px; font-weight: 700;
      letter-spacing: .5px; text-transform: uppercase; opacity: .9;
      text-align: right;
      white-space: nowrap;
      overflow: hidden;
      min-width: 0;
      flex: 0 1 auto;
    }

    /* current-time indicator */
    .time-indicator {
      position: absolute;
      left: 0; right: 0;
      height: 2px;
      background: #ea4335;
      z-index: 8;
      pointer-events: none;
    }
    /* ─── MOBILE VIEWS ─────────────────────────────────────────── */
    #mobile-wrap {
      width: 100%; height: 100%;
      display: none;
      flex-direction: column;
    }

    /* mobile day tabs */
    #mobile-day-tabs {
      display: flex;
      justify-content: space-between;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }
    #mobile-day-tabs::-webkit-scrollbar { display: none; }

    .mob-day-tab {
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 6px 0;
      flex: 1;
      cursor: pointer;
      border-bottom: 3px solid transparent;
      transition: border-color .2s, background .2s;
    }
    .mob-day-tab .mdt-day { font-size: 10px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
    .mob-day-tab .mdt-num {
      font-size: 18px;
      color: var(--text);
      width: 34px; height: 34px;
      display: flex; align-items: center; justify-content: center;
      border-radius: 50%;
    }
    .mob-day-tab.active { border-color: var(--accent); background: #f0f5ff; }
    .mob-day-tab.active .mdt-day { color: var(--accent); }
    .mob-day-tab.today .mdt-num { background: var(--accent); color: #fff; }

    /* mobile swipeable container */
    #mobile-days-container {
      flex: 1;
      overflow: hidden;
      position: relative;
    }

    #mobile-days-slider {
      display: flex;
      height: 100%;
      transition: transform .3s cubic-bezier(.4,0,.2,1);
      will-change: transform;
    }

    .mobile-day-pane {
      flex-shrink: 0;
      width: 100%;
      height: 100%;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      position: relative;
      /* Every gesture on the pane is owned by JS (js/mobile-gestures.js):
         two-finger pinch zoom, one-finger vertical pan, one-finger
         horizontal day switch. (pan-y would let the browser handle the
         two-finger vertical pan natively too — it then fought the JS
         re-anchoring mid-pinch, which made the lessons jump.) */
      touch-action: none;
    }
    .mobile-day-pane::-webkit-scrollbar { width: 4px; }
    .mobile-day-pane::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

    /* grid inside each pane */
    .mob-grid {
      display: grid;
      grid-template-columns: var(--mob-left) var(--time-col) 1fr;
      position: relative;
      min-height: 100%;
    }

    .mob-time-label {
      position: absolute;
      display: flex;
      align-items: flex-start;
      justify-content: flex-end;
      padding-right: 6px;
      font-size: 11px;
      font-weight: 500;
      color: var(--text-muted);
      user-select: none;
      white-space: nowrap;
      z-index: 3;
      line-height: 1.2;
    }

    .mob-hour-cell {
      border-top: 1px solid var(--border);
      height: var(--hour-h);
      position: relative;
    }
    .mob-hour-cell::after {
      content: '';
      position: absolute;
      top: 50%; left: 0; right: 0;
      border-top: 1px dashed #eee;
    }

    .mob-lesson-block {
      position: absolute;
      border-radius: var(--radius);
      padding: 6px 8px;
      overflow: hidden;
      cursor: pointer;
      z-index: 5;
      transition: filter .15s;
      border: none;
      outline: none;
      box-shadow: 0 1px 3px rgba(0,0,0,0.06);
      text-align: left;
      /* 2-column grid: left info | right info, bottom row spans both */
      display: grid;
      grid-template-columns: 1fr auto;
      grid-template-rows: auto 1fr auto;
      gap: 2px 6px;
      align-items: start;
      box-sizing: border-box;
      -webkit-appearance: none;
    }
    .mob-lesson-block:hover { filter: brightness(.93); }
    .mob-lesson-block .lb-name {
      grid-column: 1; grid-row: 1;
      font-size: 14px; font-weight: 700;
      text-align: left;
      overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .mob-lesson-block .lb-room {
      grid-column: 2; grid-row: 1;
      font-size: 13px; font-weight: 600;
      white-space: nowrap; text-align: right;
    }
    .mob-lesson-block .lb-teacher {
      grid-column: 1; grid-row: 2;
      font-size: 12px; font-weight: 400; opacity: .85;
      text-align: left;
      overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
      align-self: start;
    }
    .mob-lesson-block .lb-bottom {
      grid-column: 1 / -1; grid-row: 3;
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      gap: 12px;
      align-self: end;
      min-width: 0;
    }
    .mob-lesson-block .lb-time {
      font-size: 12px; opacity: .85;
      white-space: nowrap; text-align: left;
      flex: 0 0 auto;
    }
    .mob-lesson-block .lb-type-badge {
      font-size: 11px; font-weight: 700;
      letter-spacing: .5px; text-transform: uppercase; opacity: .9;
      text-align: right;
      white-space: nowrap;
      overflow: hidden;
      min-width: 0;
      flex: 0 1 auto;
    }

    /* ─── MOBILE WEEKLY VIEW ───────────────────────────────────── */
    #mobile-week-wrap {
      display: none;
      width: 100%; height: 100%;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      background: var(--surface);
    }
    #mobile-week-wrap::-webkit-scrollbar { width: 4px; }
    #mobile-week-wrap::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

    #mob-week-grid {
      position: relative;
      display: grid;
    }

    #mob-week-day-header {
      display: grid;
      position: sticky;
      top: 0;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      z-index: 10;
      box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    }
    .mob-week-day-cell {
      text-align: center;
      padding: 6px 2px;
      font-size: 10px;
      color: var(--text-muted);
      font-weight: 600;
      text-transform: uppercase;
    }
    .mob-week-day-cell .wdc-num {
      width: 28px; height: 28px;
      display: inline-flex; align-items: center; justify-content: center;
      border-radius: 50%;
      font-size: 14px;
      color: var(--text);
      letter-spacing: 0;
      text-transform: none;
      margin-top: 2px;
    }
    .mob-week-day-cell.today { color: var(--accent); }
    .mob-week-day-cell.today .wdc-num { background: var(--accent); color: #fff; font-weight: 600; }

    .mob-week-lesson-block {
      position: absolute;
      border-radius: var(--radius);
      padding: 6px 8px;
      overflow: hidden;
      cursor: pointer;
      z-index: 5;
      border: none;
      outline: none;
      box-shadow: 0 1px 3px rgba(0,0,0,0.06);
      text-align: left;
      display: flex;
      flex-direction: column;
      gap: 1px;
      transition: filter .15s, transform .1s;
      box-sizing: border-box;
      -webkit-appearance: none;
    }
    .mob-week-lesson-block:hover { filter: brightness(.93); }
    /* top rows (name → room → teacher) are always rendered — the name
       clamps to 2 lines so the room/teacher/time below stay visible */
    .mob-week-lesson-block .mw-name {
      font-size: 12px;
      font-weight: 700;
      line-height: 1.2;
      text-align: left;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      word-break: break-word;
    }
    .mob-week-lesson-block .mw-room {
      font-size: 12px;
      font-weight: 600;
      opacity: .85;
      text-align: left;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .mob-week-lesson-block .mw-teacher {
      font-size: 11px;
      font-weight: 400;
      opacity: .85;
      text-align: left;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    /* bottom row: time (left) is always visible, then a healthy gap, then
       the type. The type starts fully readable on its left side; only when
       it overflows the card's right edge does the .lb-fade mask (toggled
       per element by applyTypeFades in js/utils.js) dissolve its tail
       into a gradient instead of a hard clip. */
    .mob-week-lesson-block .mw-bottom {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      gap: 12px;
      margin-top: auto;
    }
    .mob-week-lesson-block .mw-time {
      font-size: 11px;
      opacity: .8;
      text-align: left;
      white-space: nowrap;
      flex: 0 0 auto;
    }
    .mob-week-lesson-block .mw-type {
      flex: 1 1 auto;
      min-width: 0;
      font-size: 11px;
      font-weight: 700;
      letter-spacing: .4px;
      text-transform: uppercase;
      opacity: .9;
      text-align: left;
      white-space: nowrap;
      overflow: hidden;
    }
    /* right-edge fade for type labels that overflow their space — the
       left side of the word stays readable, the tail dissolves before
       the card's right edge (applied on .lb-type-badge in desktop/Dan
       views as well, where the grid track squeezes the badge) */
    .lb-type-badge.lb-fade,
    .mob-week-lesson-block .mw-type.lb-fade {
      -webkit-mask-image: linear-gradient(to left, transparent 0, black 12px);
      mask-image: linear-gradient(to left, transparent 0, black 12px);
    }

    /* ─── LESSON TOOLTIP / MODAL ───────────────────────────────── */
    #lesson-modal {
      display: none;
      position: fixed;
      inset: 0;
      z-index: 200;
    }
    #lesson-modal.open { display: flex; }
    #modal-backdrop {
      position: absolute;
      inset: 0;
      background: rgba(0,0,0,.3);
    }
    #modal-card {
      position: relative;
      background: var(--surface);
      border-radius: 12px;
      box-shadow: 0 8px 30px rgba(0,0,0,.2);
      padding: 20px;
      max-width: 360px;
      width: calc(100% - 32px);
      margin: auto;
      z-index: 1;
      animation: modalIn .2s ease;
    }
    @keyframes modalIn {
      from { transform: scale(.92); opacity: 0; }
      to   { transform: scale(1);   opacity: 1; }
    }
    #modal-color-strip {
      height: 6px;
      border-radius: 3px;
      margin-bottom: 14px;
    }
    #modal-name { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
    #modal-type { font-size: 12px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; opacity: .7; margin-bottom: 12px; }
    .modal-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; color: var(--text-muted); font-size: 14px; }
    .modal-row svg { width: 18px; height: 18px; fill: var(--text-muted); flex-shrink: 0; }
    #modal-close {
      position: absolute; top: 12px; right: 12px;
      width: 30px; height: 30px;
      border: none; background: var(--bg);
      border-radius: 50%; cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      color: var(--text-muted);
    }
    #modal-close svg { width: 16px; height: 16px; fill: currentColor; }

    /* ─── RESPONSIVE ───────────────────────────────────────────── */
    @media (max-width: 768px) {
      #cal-wrap       { display: none !important; }
      #mobile-wrap    { display: flex !important; }
      #view-tabs      { display: flex; }
      #peek-hint      { display: block; }

      #header .logo { font-size: 15px; }
      #period-label { font-size: 14px; min-width: 90px; }
    }

    @media (min-width: 769px) {
      #mobile-wrap    { display: none !important; }
      #mobile-week-wrap { display: none !important; }
      #peek-hint      { display: none !important; }
      #cal-wrap       { display: block !important; }
      #view-tabs      { display: none; }
    }

    /* mobile view mode */
    body.mob-view-week #mobile-wrap    { display: none !important; }
    body.mob-view-week #mobile-week-wrap { display: block !important; }
    body.mob-view-day  #mobile-wrap    { display: flex !important; }
    body.mob-view-day  #mobile-week-wrap { display: none !important; }

    /* ─── UTILITY ──────────────────────────────────────────────── */
    .sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); }

    /* no lessons message */
    .no-lessons {
      padding: 40px 20px;
      text-align: center;
      color: var(--text-muted);
      font-size: 14px;
    }
