/* =========================================================================
   Figo Flashcards — design system (§1.10)
   Calm, clean, academic. Mobile-first; the sidebar appears from 900px up.
   ========================================================================= */

:root {
  /* Core palette */
  --bg:            #FAFAF8;
  --surface:       #FFFFFF;
  --text:          #1D252C;
  --text-2:        #6B7280;
  --text-3:        #9AA1AA;
  --border:        #E8E8E3;
  --border-strong: #D8D8D1;
  --accent:        #356859;
  --accent-hover:  #2B5548;
  --accent-soft:   #EDF3F0;

  /* Study semantics */
  --easy:          #3F7D62;
  --easy-soft:     #E9F1EC;
  --again:         #C0685A;
  --again-soft:    #FAEDEA;
  --favorite:      #B98A22;
  --favorite-soft: #FBF4E3;
  --danger:        #B4443A;
  --danger-soft:   #FAEBE9;

  /* Type */
  --font: 'Inter', 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI',
          Roboto, Helvetica, Arial, sans-serif;

  /* Space */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;
  --shadow: 0 1px 2px rgba(29, 37, 44, .04);
  --shadow-lift: 0 2px 8px rgba(29, 37, 44, .07);

  --sidebar-w: 236px;
  --content-w: 720px;
  --bottomnav-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  /* clip, not hidden: overflow-x:hidden makes body a scroll container, which
     silently disables position:sticky everywhere inside it. */
  overflow-x: clip;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.011em; line-height: 1.3; }
p { margin: 0; }
button { font-family: inherit; font-size: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* =========================================================================
   Buttons
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;                /* comfortable tap target */
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--accent-hover); }

.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:not(:disabled):hover { background: #F4F4F0; }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:not(:disabled):hover { background: #F1F1EC; color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:not(:disabled):hover { filter: brightness(.94); }

.btn-block { width: 100%; }
.btn-lg { min-height: 52px; padding: 14px 26px; font-size: 16px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* The home screen's two primary actions read better stacked full-width on a
   phone, and side by side once there is room. */
.home-actions .btn { flex: 1 1 100%; }
@media (min-width: 560px) { .home-actions .btn { flex: 0 1 auto; } }

/* =========================================================================
   Forms
   ========================================================================= */

.field { display: block; margin-bottom: 16px; }
.field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}
.input, .textarea, .select {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;               /* 16px stops iOS Safari zooming on focus */
  line-height: 1.5;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { min-height: 200px; resize: vertical; font-size: 15px; }

/* =========================================================================
   Login
   ========================================================================= */

#login-screen, #boot-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 396px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lift);
  padding: 34px 30px;
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand .wordmark { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.login-brand .tagline { margin-top: 5px; font-size: 13.5px; color: var(--text-2); }
.login-admin-badge {
  display: inline-block;
  margin-top: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.form-error {
  margin-bottom: 16px;
  padding: 11px 13px;
  border: 1px solid #EDD3CF;
  border-radius: var(--r);
  background: var(--danger-soft);
  color: #8E332B;
  font-size: 14px;
}

/* Boot splash — shown while the stored token is validated */
.boot-mark { color: var(--text-3); font-size: 14px; letter-spacing: .02em; }

/* =========================================================================
   App shell
   ========================================================================= */

/* The app shell fills the frame exactly and never lets the document scroll;
   only .main scrolls. This is what keeps the header and bottom bar put. */
#app { min-height: 100vh; min-height: 100dvh; }

body.is-app { overflow: hidden; }
body.is-app #app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
body.is-app .main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sidebar { display: none; }

.mobile-header {
  flex: 0 0 auto;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  background: rgba(250, 250, 248, .92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.mobile-header .wordmark { font-size: 16px; font-weight: 600; letter-spacing: -0.015em; }

.main {
  padding: 22px 18px 34px;
}
.content {
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto;
}

/* Bottom navigation (mobile).

   Deliberately NOT position:fixed. The app is served inside an Apps Script
   iframe, and when it is launched from the home screen that iframe is not
   always the size of the visible area — a fixed bar then drifts with the
   page. Instead the shell is a flex column that fills the frame, `.main` is
   the only thing that scrolls, and this bar is simply the last row. It cannot
   scroll away, whatever the wrapper does. */
.bottom-nav {
  flex: 0 0 auto;
  z-index: 30;
  display: flex;
  min-height: var(--bottomnav-h);
  padding-bottom: max(env(safe-area-inset-bottom), 6px);
  background: rgba(255, 255, 255, .97);
  border-top: 1px solid var(--border);
}
.bottom-nav button {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 2px;
}
.bottom-nav button .nav-icon { font-size: 18px; line-height: 1; }
.bottom-nav button[aria-current="page"] { color: var(--accent); }

/* =========================================================================
   Views, headers, cards
   ========================================================================= */

.view-head { margin-bottom: 22px; }
.view-head h1 { font-size: 24px; }
.view-head .sub { margin-top: 5px; color: var(--text-2); font-size: 14.5px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 22px;
}
.panel + .panel { margin-top: 18px; }
.panel-title { font-size: 13px; font-weight: 600; letter-spacing: .04em;
               text-transform: uppercase; color: var(--text-3); margin-bottom: 14px; }

/* Stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 15px 16px;
  box-shadow: var(--shadow);
}
.stat .stat-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.stat .stat-label { margin-top: 3px; font-size: 12.5px; color: var(--text-2); }
.stat.is-unread .stat-value { color: var(--again); }
.stat.is-studied .stat-value { color: var(--easy); }
.stat.is-favorite .stat-value { color: var(--favorite); }
.stat.is-wide { grid-column: 1 / -1; }

/* Greeting */
.greeting { margin-bottom: 20px; }
.greeting h1 { font-size: 26px; letter-spacing: -0.02em; }
.greeting .sub { margin-top: 4px; color: var(--text-2); font-size: 14.5px; }

/* Subject list */
.subject-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.subject-row:last-child { border-bottom: 0; padding-bottom: 0; }
.subject-row:first-child { padding-top: 0; }
.subject-row .s-name { font-weight: 500; }
.subject-row .s-chapter { display: block; font-size: 12.5px; color: var(--text-3); font-weight: 400; }
.subject-row .s-count { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.subject-row .s-count b { color: var(--again); font-weight: 600; }

/* Onboarding / empty states */
.empty {
  text-align: center;
  padding: 30px 20px;
}
.empty h2 { font-size: 19px; margin-bottom: 10px; }
.empty p { color: var(--text-2); font-size: 14.5px; }
.onboard-steps {
  margin: 18px auto 22px;
  padding: 0;
  max-width: 400px;
  list-style: none;
  counter-reset: onboard;
  text-align: left;
}
.onboard-steps li {
  counter-increment: onboard;
  position: relative;
  padding: 9px 0 9px 38px;
  color: var(--text-2);
  font-size: 14.5px;
}
.onboard-steps li::before {
  content: counter(onboard);
  position: absolute;
  left: 0; top: 9px;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.placeholder-note {
  padding: 26px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
}

/* =========================================================================
   Add Cards — steps, combobox, preview list
   ========================================================================= */

.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.step-head h2 { font-size: 16px; font-weight: 600; }
.step-num {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px; font-weight: 600;
}

/* --- Combobox: type to search, type something new to create it --- */
.combo { position: relative; }
.combo-input[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.combo-input:disabled { background: #F4F4F0; color: var(--text-3); cursor: not-allowed; }

.combo-list {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0; right: 0;
  max-height: 244px;
  overflow-y: auto;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  box-shadow: var(--shadow-lift);
}
.combo-option {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 15px;
}
.combo-option:hover, .combo-option.is-active { background: var(--accent-soft); }
.combo-option .opt-count { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.combo-option.is-create { color: var(--accent); font-weight: 500; }
.combo-empty { padding: 10px 11px; font-size: 13.5px; color: var(--text-3); }

.combo-hint { margin-top: 5px; font-size: 12.5px; color: var(--text-3); min-height: 17px; }
.combo-hint.is-new { color: var(--accent); }

/* --- Preview --- */
.preview-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.preview-count { font-size: 16px; font-weight: 600; }
.preview-count .pc-num { color: var(--accent); }

.notice {
  padding: 12px 14px;
  border-radius: var(--r);
  font-size: 13.5px;
  margin-bottom: 14px;
}
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.notice li { margin-bottom: 3px; }
.notice-warn { background: var(--favorite-soft); border: 1px solid #EFE0BC; color: #7A5B12; }
.notice-error { background: var(--danger-soft); border: 1px solid #EDD3CF; color: #8E332B; }

.pcard {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 13px 14px;
  margin-bottom: 10px;
  background: var(--surface);
}
.pcard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}
.pcard-num { font-size: 12px; font-weight: 600; color: var(--text-3); letter-spacing: .03em; }
.pcard-remove {
  border: 0; background: none; cursor: pointer;
  color: var(--text-3); font-size: 13px; padding: 4px 8px; border-radius: var(--r-sm);
  min-height: 32px;
}
.pcard-remove:hover { background: var(--danger-soft); color: var(--danger); }

.pfield { margin-bottom: 8px; }
.pfield:last-child { margin-bottom: 0; }
.pfield-label {
  font-size: 10.5px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-3); margin-bottom: 3px;
}
.pfield textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: #FAFAF8;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.55;
  resize: none;
  overflow: hidden;
}
.pfield textarea:hover { border-color: var(--border); }
.pfield textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.pfield textarea.is-empty { border-color: #E7C3BE; background: var(--danger-soft); }

.commit-bar { margin-top: 18px; }
.commit-note { margin-top: 9px; text-align: center; font-size: 13px; color: var(--text-3); }
.commit-note.is-error { color: var(--danger); }

/* --- Success --- */
.success-panel { text-align: center; padding: 34px 22px; }
.success-mark {
  width: 46px; height: 46px; margin: 0 auto 15px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--easy-soft); color: var(--easy);
  font-size: 22px;
}
.success-panel h2 { font-size: 19px; margin-bottom: 6px; }
.success-panel .success-where { color: var(--text-2); font-size: 14px; margin-bottom: 20px; }

/* =========================================================================
   Study — filter screen
   ========================================================================= */

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #F1F1EC;
  border-radius: var(--r);
}
.segmented button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 38px;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.check-list { display: flex; flex-direction: column; gap: 2px; }
.check-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 14.5px;
}
.check-row:hover { background: #F6F6F2; }
.check-row input { width: 17px; height: 17px; accent-color: var(--accent); flex: 0 0 auto; cursor: pointer; }
.check-row .cr-label { flex: 1 1 auto; min-width: 0; }
.check-row .cr-count { font-size: 12.5px; color: var(--text-3); white-space: nowrap; }
.check-row.is-empty .cr-label { color: var(--text-3); }
.check-group + .check-group { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.check-hint { font-size: 12.5px; color: var(--text-3); margin-top: 8px; }

.count-line {
  margin: 18px 0 12px;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
}
.count-line .cl-num { color: var(--accent); font-weight: 600; }
.count-line .cl-cap { display: block; margin-top: 4px; font-size: 13px; font-weight: 400; color: var(--text-3); }

/* =========================================================================
   Study — the running session
   ========================================================================= */

/* While a session runs the surrounding chrome gets out of the way. */
body.is-studying .mobile-header,
body.is-studying .bottom-nav { display: none; }

.study-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 6px;
}
.study-counter { font-size: 14px; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }
.btn-end {
  border: 0; background: none; cursor: pointer;
  color: var(--text-3); font-size: 13px; padding: 6px 10px;
  border-radius: var(--r-sm); min-height: 36px;
}
.btn-end:hover { background: #F1F1EC; color: var(--text); }

.study-bar {
  height: 3px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 18px;
}
.study-bar > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s ease; }

.study-path {
  font-size: 12.5px;
  color: var(--text-3);
  text-align: center;
  margin-bottom: 14px;
  overflow-wrap: anywhere;
}

.flashcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 30px 26px;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.fc-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 12px;
}
.fc-text {
  font-size: 20px;
  line-height: 1.62;
  white-space: pre-wrap;        /* multi-line answers keep their line breaks */
  overflow-wrap: anywhere;
  text-align: left;
}
.fc-divider { height: 1px; background: var(--border); margin: 24px 0; }
.fc-answer .fc-text { font-size: 19px; }

.study-actions { margin-top: 20px; }
.reveal-row { display: flex; }
.reveal-row .btn { flex: 1 1 auto; }

.grade-row { display: flex; align-items: stretch; gap: 10px; }
.grade-row .btn { flex: 1 1 0; min-height: 56px; font-size: 16px; font-weight: 600; }
.btn-again { background: var(--again-soft); color: #8E3D31; border-color: #EFD5CF; }
.btn-again:not(:disabled):hover { background: #F6E1DC; }
.btn-easy { background: var(--easy-soft); color: #2E6047; border-color: #CFE2D6; }
.btn-easy:not(:disabled):hover { background: #DEEBE3; }

.btn-fav {
  flex: 0 0 auto !important;
  width: 56px;
  min-height: 56px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text-3);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.btn-fav[aria-pressed="true"] {
  background: var(--favorite-soft);
  border-color: #EFE0BC;
  color: var(--favorite);
}
.btn-fav:hover { border-color: var(--favorite); color: var(--favorite); }

.key-hint { margin-top: 12px; text-align: center; font-size: 12px; color: var(--text-3); }
.key-hint kbd {
  padding: 1px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 4px; background: var(--surface); font-family: inherit; font-size: 11px;
}

/* On a phone the grading controls sit in thumb reach, pinned to the bottom.
   Fixed, not sticky: the app runs inside an Apps Script iframe where fixed
   holds and sticky does not. */
@media (max-width: 899px) {
  /* During a session the runner fills the scroll area, so `margin-top: auto`
     pushes the grading row to the bottom of the screen even when the card is
     short — and `sticky` keeps it there once a long answer starts scrolling.
     Between them the buttons are always under the thumb, with no reliance on
     position:fixed. */
  body.is-studying .main { display: flex; flex-direction: column; padding-bottom: 0; }
  body.is-studying .main > .content { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  body.is-studying #view-study { flex: 1 1 auto; display: flex; flex-direction: column; }
  body.is-studying #study-runner { flex: 1 1 auto; display: flex; flex-direction: column; }

  .study-actions.is-pinned {
    position: sticky;
    bottom: 0;
    z-index: 40;
    margin: auto -18px 0;
    padding: 12px 18px;
    background: rgba(255, 255, 255, .97);
    border-top: 1px solid var(--border);
  }
  .key-hint { display: none; }          /* no physical keyboard to hint at */
  .fc-text { font-size: 18px; }
  .flashcard { padding: 24px 20px; }
}

/* =========================================================================
   Study — completion
   ========================================================================= */

.complete-panel { text-align: center; padding: 34px 22px; }
.complete-panel h2 { font-size: 22px; margin-bottom: 6px; }
.complete-lead { color: var(--text-2); font-size: 15px; margin-bottom: 22px; }
.complete-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 22px;
  padding: 16px 12px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}
.complete-stat { font-size: 13.5px; color: var(--text-2); }
.complete-stat b { display: block; font-size: 19px; font-weight: 600; color: var(--text); line-height: 1.3; }
.complete-stat.is-again b { color: var(--again); }
.complete-stat.is-easy b { color: var(--easy); }
.complete-stat.is-fav b { color: var(--favorite); }

/* =========================================================================
   Confirmation dialog
   ========================================================================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(29, 37, 44, .34);
  backdrop-filter: blur(2px);
}
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 32px rgba(29, 37, 44, .18);
  padding: 26px 24px 20px;
}
.modal h2 { font-size: 18px; margin-bottom: 10px; }
.modal #confirm-body { color: var(--text-2); font-size: 14.5px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn { flex: 1 1 0; }

/* =========================================================================
   My Cards / Favorites — filters, search, list
   ========================================================================= */

.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 620px) { .filter-grid { grid-template-columns: repeat(3, 1fr); } }

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236B7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}

.search-wrap { margin-top: 12px; }

.filter-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.btn-tiny {
  min-height: 32px;
  padding: 5px 11px;
  font-size: 12.5px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
}
.btn-tiny:hover { background: #F4F4F0; color: var(--text); }

.result-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 2px 10px;
  font-size: 13.5px;
  color: var(--text-2);
}
.result-line b { color: var(--text); font-weight: 600; }

.card-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 15px;
  margin-bottom: 10px;
}
.card-item.is-editing { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ci-path { font-size: 11.5px; color: var(--text-3); margin-bottom: 7px; overflow-wrap: anywhere; }
.ci-q { font-size: 15.5px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.ci-a {
  margin-top: 10px;
  padding: 11px 13px;
  border-radius: var(--r-sm);
  background: #F6F6F2;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ci-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 11px;
  flex-wrap: wrap;
}
.ci-reveal {
  border: 0; background: none; cursor: pointer; padding: 5px 8px;
  border-radius: var(--r-sm); color: var(--accent); font-size: 12.5px; font-weight: 500;
  min-height: 32px; margin-right: auto;
}
.ci-reveal:hover { background: var(--accent-soft); }
.ci-btn {
  border: 0; background: none; cursor: pointer; padding: 5px 9px;
  border-radius: var(--r-sm); color: var(--text-2); font-size: 12.5px; min-height: 32px;
}
.ci-btn:hover { background: #F1F1EC; color: var(--text); }
.ci-btn.is-delete:hover { background: var(--danger-soft); color: var(--danger); }
.ci-star {
  border: 0; background: none; cursor: pointer; padding: 4px 8px;
  border-radius: var(--r-sm); color: var(--text-3); font-size: 17px; line-height: 1; min-height: 32px;
}
.ci-star[aria-pressed="true"] { color: var(--favorite); }
.ci-star:hover { background: var(--favorite-soft); color: var(--favorite); }

.ci-edit .field { margin-bottom: 12px; }
.ci-edit textarea { min-height: 84px; font-size: 15px; }

.load-more { margin: 6px 0 4px; text-align: center; }

/* =========================================================================
   Progress page
   ========================================================================= */

.progress-bar-wrap { margin: 6px 0 4px; }
.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: #EFEFE9;
  overflow: hidden;
}
.progress-bar > div { height: 100%; background: var(--accent); border-radius: 999px; }
.progress-figure {
  margin-top: 10px;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.progress-figure .pf-pct { color: var(--accent); }

.subject-progress { padding: 12px 0; border-bottom: 1px solid var(--border); }
.subject-progress:last-child { border-bottom: 0; padding-bottom: 0; }
.subject-progress:first-child { padding-top: 0; }
.sp-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 7px;
}
.sp-name { font-size: 14.5px; font-weight: 500; }
.sp-name span { display: block; font-size: 11.5px; color: var(--text-3); font-weight: 400; }
.sp-count { font-size: 13px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sp-bar { height: 5px; border-radius: 999px; background: #EFEFE9; overflow: hidden; }
.sp-bar > div { height: 100%; background: var(--accent); border-radius: 999px; }

.sub-remaining {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-2);
}
.sub-remaining.is-soon { color: var(--favorite); font-weight: 500; }

.danger-zone { margin-top: 18px; }
.danger-zone .panel-title { color: var(--danger); }

/* =========================================================================
   Admin console
   ========================================================================= */

.admin-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(250, 250, 248, .94);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.admin-brand {
  border: 0; background: none; cursor: pointer; padding: 4px 0;
  font-family: inherit; font-size: 16px; font-weight: 600;
  letter-spacing: -0.015em; color: var(--text);
}
.admin-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  vertical-align: 2px;
}
.admin-header-actions { display: flex; gap: 2px; }
.admin-header-actions .btn { min-height: 36px; padding: 6px 12px; font-size: 14px; }

.admin-content { max-width: 980px; }

@media (min-width: 900px) {
  #admin-app .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #admin-app .stat.is-wide { grid-column: auto; }
}

#admin-app .main { padding: 26px 20px 60px; }
@media (min-width: 900px) { #admin-app .main { padding: 34px 28px 70px; } }

.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.admin-head h1 { font-size: 23px; }
.admin-head .sub { margin-top: 4px; color: var(--text-2); font-size: 14px; }

/* Wide table scrolls inside its own container, never the page. */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}
table.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 720px; }
.admin-table th {
  text-align: left;
  padding: 11px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover { background: #FBFBF8; }
.admin-table .t-name { font-weight: 500; }
.admin-table .t-user { color: var(--text-2); font-size: 13px; }
.admin-table .t-num { font-variant-numeric: tabular-nums; }
.admin-table .t-dim { color: var(--text-3); font-size: 13px; white-space: nowrap; }
/* Six actions per row is a lot; letting them wrap inside the cell keeps the
   whole set reachable without scrolling the table sideways. */
.admin-table .t-actions { white-space: normal; min-width: 232px; }
.admin-table .t-actions .btn-tiny { margin: 2px 3px 2px 0; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-active { background: var(--easy-soft); color: #2E6047; }
.badge-expired { background: var(--favorite-soft); color: #7A5B12; }
.badge-disabled { background: var(--danger-soft); color: #8E332B; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px 20px;
}
.info-item .il { font-size: 11.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.info-item .iv { margin-top: 3px; font-size: 14.5px; overflow-wrap: anywhere; }

.credentials {
  margin: 16px 0;
  padding: 16px 18px;
  border: 1px dashed var(--accent);
  border-radius: var(--r);
  background: var(--accent-soft);
}
.credentials .cred-row { display: flex; justify-content: space-between; gap: 14px; padding: 4px 0; font-size: 14.5px; }
.credentials .cred-row span:first-child { color: var(--text-2); }
.credentials .cred-row b { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.credentials .cred-warn { margin-top: 10px; font-size: 12.5px; color: #7A5B12; }

.breakdown-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.breakdown-row:last-child { border-bottom: 0; }
.breakdown-row .bd-path span { color: var(--text-3); }
.breakdown-row .bd-count { color: var(--text-2); font-size: 13px; white-space: nowrap; }

.activity-row {
  display: flex; gap: 12px; padding: 9px 0;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.activity-row:last-child { border-bottom: 0; }
.activity-row .ac-time { color: var(--text-3); white-space: nowrap; font-size: 12px; min-width: 120px; }
.activity-row .ac-what { color: var(--text-2); overflow-wrap: anywhere; }
.activity-row .ac-what b { color: var(--text); font-weight: 600; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 620px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-grid .field-full { grid-column: 1 / -1; }

/* =========================================================================
   Toasts
   ========================================================================= */

#toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bottomnav-h) + 20px);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 400px;
  pointer-events: none;
}
.toast {
  padding: 12px 15px;
  border-radius: var(--r);
  background: var(--text);
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-lift);
  animation: toast-in .18s ease;
}
.toast.is-error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Inline loading text */
.loading-line { color: var(--text-2); font-size: 14.5px; padding: 20px 0; text-align: center; }

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: -2px;
  margin-right: 7px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* =========================================================================
   Desktop — narrow sidebar, centred reading column
   ========================================================================= */

@media (min-width: 900px) {
  .mobile-header { display: none; }
  .bottom-nav { display: none; }

  #app { display: block; }
  body.is-app { overflow: visible; }
  body.is-app #app { height: auto; display: block; }
  body.is-app .main { overflow: visible; }

  /* Fixed rather than sticky. The app is served inside an Apps Script iframe;
     fixed positioning holds there, sticky does not. */
  .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 20;
    width: var(--sidebar-w);
    padding: 24px 16px;
    border-right: 1px solid var(--border);
    background: var(--bg);
    overflow-y: auto;          /* the nav scrolls itself on a short window */
  }
  .sidebar .brand { padding: 0 10px 22px; }
  .sidebar .brand .wordmark { font-size: 16.5px; font-weight: 600; letter-spacing: -0.015em; }
  .sidebar .brand .tagline { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar nav button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: var(--r-sm);
    background: none;
    color: var(--text-2);
    font-size: 14.5px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
  }
  .sidebar nav button .nav-icon { font-size: 15px; width: 18px; text-align: center; }
  .sidebar nav button:hover { background: #F1F1EC; color: var(--text); }
  .sidebar nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

  .sidebar .sidebar-foot { margin-top: auto; padding-top: 16px; }

  .main { margin-left: var(--sidebar-w); padding: 44px 40px 80px; }
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat.is-wide { grid-column: auto; }
  .view-head h1, .greeting h1 { font-size: 28px; }
  #toasts { bottom: 24px; left: auto; right: 24px; transform: none; }
}

/* Import log ------------------------------------------------------------- */
.import-log {
  margin-top: 16px;
  padding: 12px 14px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: #F6F6F2;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-2);
}
.import-log .il-line.is-ok { color: var(--easy); font-weight: 600; }
.import-log .il-line.is-error { color: var(--danger); font-weight: 600; }
input[type="file"].input { padding: 9px 11px; font-size: 14px; }
