/* platform: styles of this feature only.
   The course picker and its catalogue, the sign-in screen, the account box, and the phone
   layout (narrower than 768px): a top bar, the sidebar as a drawer, full-width content, the
   chat composer at the bottom, the source viewer full screen. Wider screens are unchanged. */

/* ---- course picker (sidebar) ---- */
.course-pick { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--card); cursor: pointer; text-align: left; }
.course-pick:hover { border-color: var(--ink-3); }
.course-pick:focus-visible, .topbar-course:focus-visible, .cat-item:focus-visible { outline: 2px solid var(--indigo); outline-offset: 1px; }
.course-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.course-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-pick .course-title { font-weight: 550; }
.course-meta { font-size: 11.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-meta:empty { display: none; }
.chevron { width: 16px; height: 16px; flex: none; color: var(--ink-3); }

/* ---- catalogue ---- */
.catalogue { padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); width: min(620px, calc(100vw - 32px)); max-height: min(720px, calc(100vh - 64px)); box-shadow: 0 24px 80px rgba(0, 0, 0, .25); overflow: hidden; }
.catalogue::backdrop { background: rgba(29, 28, 26, .38); }
.cat-inner { display: flex; flex-direction: column; max-height: min(720px, calc(100vh - 64px)); }
.cat-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px 20px; }
.cat-head .tiny { margin-right: auto; }
.cat-close { margin: 0; background: transparent; border-color: transparent; }
.cat-search { margin: 0 20px 8px; }
.cat-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 10px; }
.cat-group-title { display: flex; align-items: baseline; gap: 8px; padding: 12px 8px 6px; font: 600 11px/1.2 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.cat-group-title .tiny { letter-spacing: 0; }
.cat-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left; }
.cat-item:hover { background: #e6e1d3; }
.cat-item.on { background: #e1dbcb; font-weight: 550; }
.cat-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-now { font-size: 12px; color: var(--indigo); font-weight: 550; }
.cat-none { padding: 22px 8px; color: var(--ink-2); margin: 0; }
.cat-foot { display: flex; padding: 12px 20px 16px; border-top: 1px solid var(--line); }

/* ---- account box (sidebar) ---- */
.account { display: flex; align-items: center; gap: 8px; }
.account-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .account-student { margin-top: 10px; }

/* ---- sign-in screen ---- */
.login-screen { position: fixed; inset: 0; z-index: 100; overflow-y: auto; display: grid; place-items: center; background: var(--paper);
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.login-card { width: min(400px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 24px 24px 22px; box-shadow: 0 10px 40px rgba(0, 0, 0, .06); }
.login-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.login-brand { display: flex; align-items: center; gap: 10px; }
.login-lede { color: var(--ink-2); margin: 6px 0 18px; font-size: 14px; }
.login-tabs { display: flex; width: 100%; margin-bottom: 16px; }
.login-tabs button { flex: 1; padding: 9px 10px; font-size: 14px; }
.login-form { display: grid; gap: 12px; }
.login-field { display: grid; gap: 5px; font-size: 13px; font-weight: 550; color: var(--ink-2); }
.login-field .field { width: 100%; min-height: 42px; font-size: 16px; font-weight: 400; color: var(--ink); }
.login-hint { margin-top: -6px; }
.login-error { color: var(--weak); font-size: 13.5px; }
.login-error:empty { display: none; }
.login-submit { justify-content: center; min-height: 44px; font-size: 15px; margin-top: 4px; }

/* ---- phone: hidden on wider screens ---- */
.topbar, .drawer-backdrop { display: none; }

@media (max-width: 767.98px) {
  .topbar { display: flex; align-items: center; gap: 6px; position: fixed; top: 0; left: 0; right: 0; z-index: 30;
    height: calc(52px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
    background: #efebe0; border-bottom: 1px solid var(--line); }
  .topbar .icon-btn { width: 44px; height: 44px; margin: 0; border-color: transparent; background: transparent; color: var(--ink); text-decoration: none; }
  .topbar .icon-btn svg { width: 22px; height: 22px; }
  .topbar-course { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 44px; padding: 0 4px;
    border: 0; background: transparent; cursor: pointer; font-family: var(--serif); font-size: 17px; font-weight: 600; }

  #app, #app.with-viewer { display: block; height: 100vh; height: 100dvh; padding-top: calc(52px + env(safe-area-inset-top)); }
  #view { height: 100%; overflow-x: hidden; padding: 16px max(14px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }

  /* the sidebar as a drawer */
  .rail { position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; width: min(300px, 86vw); border-right: 0;
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    transform: translateX(-105%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; }
  body.drawer-open .rail { transform: none; visibility: visible; transition: transform .22s ease; box-shadow: 12px 0 40px rgba(0, 0, 0, .18); }
  .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(29, 28, 26, .38); }
  .drawer-backdrop[hidden] { display: none; }
  .brand { padding-bottom: 14px; }
  .links a { min-height: 44px; }
  .chat { min-height: 44px; padding-right: 46px; }
  .chat .del { display: grid; width: 40px; height: 40px; right: 2px; opacity: .55; }
  .chat .del.armed { opacity: 1; }
  .chat-list { max-height: none; }
  .chats { flex: none; }
  .who select, .course-pick { min-height: 44px; font-size: 16px; }
  .seg button { min-height: 40px; }

  /* touch targets and stacked content */
  .btn, .btn.sm, .btn.ghost { min-height: 40px; }
  .mode, .pick button, .chip button, .toggle { min-height: 40px; }
  .cite { position: relative; min-width: 26px; height: 26px; }
  .cite::after { content: ""; position: absolute; inset: -8px -4px; }          /* a 40px target, drawn small */
  .head { flex-wrap: wrap; align-items: flex-start; gap: 12px; }
  h1 { font-size: 24px; }
  .cols-2, .cols-3, .lesson { grid-template-columns: minmax(0, 1fr); }
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }    /* small stat tiles, two a row */
  .stat .n { font-size: 26px; }
  .card { padding: 14px; }
  .concept-row { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; }
  .concept-row > :nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .ev { grid-template-columns: 64px minmax(0, 1fr); }
  .ev > :nth-child(3) { grid-column: 2; }
  .metric { grid-template-columns: minmax(0, 1fr) 56px; }
  .metric > :nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .day, .unit { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .src { grid-template-columns: 26px minmax(0, 1fr); }
  .src > :nth-child(3) { grid-column: 2; }
  table { display: block; overflow-x: auto; }
  img, video, canvas { max-width: 100%; }
  .q-stem { font-size: 17.5px; }
  .opt { min-height: 44px; }
  .msg.student { max-width: 88%; }
  .starters button, .thread .btn { max-width: 100%; white-space: normal; text-align: left; }
  .thread { overflow-x: hidden; }
  .msg .body, .msg .problem, .msg .answer { overflow-wrap: anywhere; }
  .msg .katex-display { overflow-x: auto; overflow-y: hidden; }

  /* the chat: the composer stays at the bottom, above the home indicator */
  #view:has(> .tutor-view) { padding-bottom: 0; }
  .tutor-view { height: 100%; max-width: none; grid-template-columns: minmax(0, 1fr); }
  .composer-wrap { padding-bottom: calc(10px + env(safe-area-inset-bottom)); background: var(--paper); }
  .composer textarea { font-size: 16px; min-width: 0; }
  .composer .plus, .composer .icon-btn { width: 40px; height: 40px; }
  .composer .btn.primary { min-height: 40px; padding: 8px 12px; }
  .modes { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .modes::-webkit-scrollbar { display: none; }
  .mode { flex: none; }
  .tutor-bar { justify-content: flex-start; gap: 8px 12px; }

  /* the source viewer: full screen, with its close button in reach */
  #app.with-viewer .viewer { position: fixed; inset: 0; width: auto; max-width: none; z-index: 60; border-left: 0; box-shadow: none;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .viewer-head .btn.ghost { width: 44px; height: 44px; justify-content: center; background: var(--paper); border: 1px solid var(--line-2); border-radius: 10px; }
  .viewer-head .btn.ghost svg { width: 20px; height: 20px; }

  /* the catalogue: full screen */
  .catalogue { width: 100vw; max-width: 100vw; height: 100vh; height: 100dvh; max-height: none; margin: 0; border: 0; border-radius: 0; }
  .cat-inner { height: 100%; max-height: none; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .cat-head { padding: 10px 8px 8px 16px; }
  .cat-close { width: 44px; height: 44px; }
  .cat-search { margin: 0 16px 8px; min-height: 44px; font-size: 16px; }
  .cat-item { min-height: 48px; }
  .cat-foot { padding: 10px 16px 14px; }
  .cat-foot .btn { flex: 1; justify-content: center; min-height: 44px; }

  .login-card { padding: 20px 18px 18px; }
}
