/* ============================================================
   Qyzen design tokens — iOS 17-flavored palette & scale
   Light is default; dark via media query, [data-theme] overrides.
   ============================================================ */

:root {
  color-scheme: light dark;

  --blue: #007aff;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --purple: #af52de;
  --indigo: #5856d6;
  --teal: #30b0c7;
  --pink: #ff2d55;
  --yellow: #ffcc00;
  --tint: var(--blue);

  --bg: #f2f2f7;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-inset: #ffffff;

  --label-1: rgba(0, 0, 0, 0.92);
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --label-4: rgba(60, 60, 67, 0.18);

  --fill-1: rgba(120, 120, 128, 0.2);
  --fill-2: rgba(120, 120, 128, 0.16);
  --fill-3: rgba(118, 118, 128, 0.12);
  --fill-4: rgba(116, 116, 128, 0.08);

  --separator: rgba(60, 60, 67, 0.29);
  --separator-opaque: #c6c6c8;

  --glass-bg: rgba(249, 249, 249, 0.78);
  --glass-border: rgba(0, 0, 0, 0.08);

  --hero-gradient: linear-gradient(135deg, #0a84ff 0%, #5e5ce6 55%, #bf5af2 110%);
  --hero-glow: rgba(10, 132, 255, 0.35);

  --radius-s: 10px;
  --radius-m: 14px;
  --radius-l: 20px;
  --radius-xl: 28px;

  --font-largetitle: 700 34px/1.2 var(--font-stack);
  --font-title1: 700 28px/1.22 var(--font-stack);
  --font-title2: 700 22px/1.25 var(--font-stack);
  --font-title3: 600 20px/1.25 var(--font-stack);
  --font-headline: 600 17px/1.3 var(--font-stack);
  --font-body: 400 17px/1.42 var(--font-stack);
  --font-callout: 400 16px/1.35 var(--font-stack);
  --font-subhead: 400 15px/1.35 var(--font-stack);
  --font-footnote: 400 13px/1.38 var(--font-stack);
  --font-caption1: 400 12px/1.35 var(--font-stack);
  --font-caption2: 600 11px/1.3 var(--font-stack);
  --font-stack: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display',
    'Segoe UI Variable Display', 'Segoe UI', Inter, system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --navbar-h: 52px;
  --tabbar-h: 56px;
  --page-pad: 16px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-float: 0 8px 32px rgba(0, 0, 0, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --blue: #0a84ff;
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --purple: #bf5af2;
    --indigo: #5e5ce6;
    --teal: #40cbe0;
    --pink: #ff375f;
    --yellow: #ffd60a;

    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-card: #1c1c1e;
    --bg-inset: #2c2c2e;

    --label-1: rgba(255, 255, 255, 0.95);
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --label-4: rgba(235, 235, 245, 0.16);

    --fill-1: rgba(120, 120, 128, 0.36);
    --fill-2: rgba(120, 120, 128, 0.32);
    --fill-3: rgba(118, 118, 128, 0.24);
    --fill-4: rgba(116, 116, 128, 0.18);

    --separator: rgba(84, 84, 88, 0.6);
    --separator-opaque: #38383a;

    --glass-bg: rgba(18, 18, 20, 0.72);
    --glass-border: rgba(255, 255, 255, 0.08);

    --hero-glow: rgba(10, 132, 255, 0.45);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-float: 0 8px 32px rgba(0, 0, 0, 0.55);
  }
}

/* ============================================================
   Base reset + shared surfaces
   ============================================================ */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--label-1);
  font: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

#app { min-height: 100dvh; max-width: 560px; margin: 0 auto; position: relative; }

@media (min-width: 561px) {
  body {
    background: radial-gradient(1200px 800px at 70% -10%, var(--hero-glow), transparent 60%), var(--bg);
  }
  #app { box-shadow: 0 0 0 1px var(--glass-border), var(--shadow-float); }
}

h1, h2, h3, h4, p { margin: 0; }
a { color: var(--tint); text-decoration: none; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input, textarea, select {
  font: var(--font-body);
  color: var(--label-1);
}

::selection { background: color-mix(in srgb, var(--tint) 30%, transparent); }
::-webkit-scrollbar { display: none; }

.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-card);
}

.hairline-b { box-shadow: inset 0 -0.5px 0 var(--separator); }
.hairline-t { box-shadow: inset 0 0.5px 0 var(--separator); }

.list-group { background: var(--bg-card); border-radius: var(--radius-m); overflow: hidden; }

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  text-align: left;
}

.list-row + .list-row { box-shadow: inset 0 0.5px 0 var(--separator); }

.section-label {
  font: var(--font-footnote);
  color: var(--label-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 24px 0 8px;
}

.page {
  padding: calc(var(--safe-top) + var(--navbar-h)) var(--page-pad)
    calc(var(--safe-bottom) + var(--tabbar-h) + 24px);
  min-height: 100dvh;
}

.large-title { font: var(--font-largetitle); letter-spacing: -0.4px; margin: 4px 0 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: var(--font-headline);
  border-radius: var(--radius-m);
  padding: 14px 20px;
  transition: opacity 0.15s ease;
}
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-primary { background: var(--tint); color: #fff; width: 100%; }
.btn-secondary { background: var(--fill-3); color: var(--tint); width: 100%; }
.btn-plain { color: var(--tint); padding: 8px 4px; }
.btn-danger { color: var(--red); }

.field {
  width: 100%;
  background: var(--fill-4);
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  padding: 13px 15px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.field:focus { border-color: var(--tint); background: var(--bg-card); }

textarea.field { resize: vertical; font: var(--font-subhead); font-family: var(--font-mono); line-height: 1.5; min-height: 90px; }

@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.skeleton {
  border-radius: var(--radius-s);
  background: linear-gradient(90deg, var(--fill-4) 25%, var(--fill-2) 50%, var(--fill-4) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.empty-card {
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  color: var(--label-2);
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-radius: var(--radius-m);
  padding: 12px 14px;
  font: var(--font-subhead);
}
.notice svg { flex-shrink: 0; margin-top: 2px; }
.notice-warn { background: color-mix(in srgb, var(--orange) 14%, transparent); color: var(--orange); }
.notice-error { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.notice-success { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }

.ai-guess-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--orange) 16%, transparent);
  color: var(--orange);
  font: var(--font-caption2);
  font-weight: 600;
  white-space: nowrap;
}

@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; display: inline-flex; }

.icon { flex-shrink: 0; display: inline-block; vertical-align: middle; }

/* ============================================================
   Shell: navbar, tabbar, sheet, segmented control, ring
   ============================================================ */

.navbar {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  height: calc(var(--safe-top) + var(--navbar-h));
  padding: var(--safe-top) 8px 0;
  display: flex;
  align-items: center;
  z-index: 40;
}
.navbar-side { flex: 1; display: flex; align-items: center; min-width: 0; }
.navbar-right { justify-content: flex-end; padding-right: 8px; gap: 8px; }
.navbar-back {
  display: flex;
  align-items: center;
  color: var(--tint);
  font: var(--font-body);
  margin-left: -4px;
}
.navbar-title {
  flex: 2;
  text-align: center;
  font: var(--font-headline);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.navbar-title-visible { opacity: 1; transform: translateY(0); }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  height: calc(var(--safe-bottom) + var(--tabbar-h));
  padding-bottom: var(--safe-bottom);
  display: flex;
  z-index: 40;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--label-2);
  padding-top: 6px;
}
.tab-active { color: var(--tint); }
.tab-icon { display: flex; transition: transform 0.32s cubic-bezier(.34,1.56,.64,1); }
.tab-active .tab-icon { transform: scale(1.14); }
.tab-label { font: var(--font-caption2); letter-spacing: 0.01em; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 60; }
.sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-float);
  z-index: 61;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.32s cubic-bezier(.32,.72,0,1);
}
.sheet-grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--fill-1); margin: 8px auto 4px; flex-shrink: 0; }
.sheet-body { padding: 12px 20px calc(var(--safe-bottom) + 24px); overflow-y: auto; }

.segmented { display: flex; background: var(--fill-3); border-radius: 10px; padding: 2px; position: relative; }
.segment { flex: 1; position: relative; padding: 7px 8px; font: var(--font-subhead); font-weight: 500; color: var(--label-1); text-align: center; z-index: 1; }
.segment-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  background: var(--bg-elevated);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  transition: left 0.28s cubic-bezier(.34,1.2,.64,1), width 0.28s cubic-bezier(.34,1.2,.64,1);
  z-index: 0;
}
.segment-label { position: relative; z-index: 1; }
.segment-active .segment-label { font-weight: 600; }

.ring { position: relative; flex-shrink: 0; }
.ring-center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.ring circle:last-child { transition: stroke-dashoffset 0.6s cubic-bezier(.22,.9,.35,1); }

.route-view { position: relative; min-height: 100dvh; background: var(--bg); animation: fade-in 0.16s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   Screens
   ============================================================ */

/* ---- Auth ---- */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 40px);
}
.auth-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.auth-logo {
  width: 76px; height: 76px; border-radius: 20px;
  background: var(--hero-gradient);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 34px var(--hero-glow);
  margin-bottom: 6px;
}
.auth-card { width: 100%; max-width: 380px; padding: 20px; display: grid; gap: 14px; }

/* ---- Courses list ---- */
.course-card { overflow: hidden; }
.course-card.archived { opacity: 0.5; }
.course-card-main { display: block; padding: 16px; color: inherit; cursor: pointer; }
.course-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.course-card-title { font: var(--font-headline); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-card-desc { font: var(--font-footnote); color: var(--label-2); margin: 4px 0 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.course-card-meta { display: flex; align-items: center; gap: 10px; }
.progress-track { flex: 1; height: 6px; border-radius: 3px; background: var(--fill-3); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--blue), var(--indigo)); transition: width 0.5s cubic-bezier(.22,.9,.35,1); }
.course-card-pct { font: var(--font-caption1); font-weight: 700; color: var(--label-2); min-width: 34px; text-align: right; }
.course-card-sub { font: var(--font-caption1); color: var(--label-3); margin-top: 6px; }
.course-card-actions { display: flex; }
.course-action { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 12px; font: var(--font-subhead); font-weight: 500; color: var(--tint); }
.course-action + .course-action { box-shadow: inset 0.5px 0 0 var(--separator); }
.course-action-active { color: var(--green); }
.course-action-danger { color: var(--red); }

.today-card { overflow: hidden; }

/* ---- Course detail ---- */
.detail-summary { display: flex; align-items: center; gap: 16px; padding: 16px; margin-bottom: 20px; }
.detail-desc { font: var(--font-subhead); color: var(--label-2); }
.detail-stats { display: flex; align-items: center; gap: 10px; margin-top: 8px; font: var(--font-footnote); color: var(--label-2); }
.active-chip { display: inline-flex; align-items: center; gap: 4px; font: var(--font-caption2); color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); border-radius: 6px; padding: 3px 7px; }

/* ---- Module-style accordion (questions) ---- */
.module-group { overflow: hidden; }
.module + .module { box-shadow: inset 0 0.5px 0 var(--separator); }
.module-head { display: flex; align-items: center; gap: 12px; padding: 13px 14px; cursor: pointer; }
.module-badge {
  width: 25px; height: 25px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font: var(--font-caption2); font-weight: 700;
}
.module-badge-objective { background: var(--green); }
.module-badge-theory { background: var(--orange); }
.module-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.module-title { font: var(--font-subhead); font-weight: 590; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.module-summary { font: var(--font-footnote); color: var(--label-2); }
.module-chevron { display: flex; color: var(--label-3); transition: transform 0.22s ease; flex-shrink: 0; }
.module-chevron-open { transform: rotate(180deg); }
.module-body { padding: 4px 16px 18px; display: grid; gap: 10px; }
.module-section-title { font: var(--font-caption2); text-transform: uppercase; letter-spacing: 0.07em; color: var(--label-2); margin: 10px 0 4px; }

.options-list-ios { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.options-list-ios li { padding: 8px 10px; border-radius: var(--radius-s); background: var(--fill-4); font: var(--font-subhead); }
.options-list-ios li.correct-option { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); font-weight: 600; }

/* ---- Resource-style row (notes list) ---- */
.resource-list { display: grid; gap: 6px; }
.resource-row { display: flex; align-items: center; gap: 10px; background: var(--fill-4); border-radius: var(--radius-s); padding: 10px 12px; color: inherit; }
.resource-row:active { background: var(--fill-3); }
.resource-icon { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; background: var(--blue); }
.resource-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.resource-title { font: var(--font-subhead); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resource-note { font: var(--font-caption1); color: var(--label-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Settings-style icon chip ---- */
.settings-icon { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ---- Today / study session ---- */
.today-card { overflow: hidden; }
.today-focus { padding: 4px 2px 0; }
.today-focus-title { font: var(--font-title2); letter-spacing: -0.3px; }

.option-buttons { display: flex; flex-direction: column; gap: 8px; }
.option-btn {
  text-align: left;
  padding: 13px 15px;
  border-radius: var(--radius-m);
  background: var(--fill-4);
  color: var(--label-1);
  font: var(--font-subhead);
  transition: background 0.15s ease, border-color 0.15s ease;
  border: 1.5px solid transparent;
}
.option-btn:active { background: var(--fill-3); }
.option-btn.answered { cursor: default; }
.option-btn.correct { background: color-mix(in srgb, var(--green) 16%, transparent); border-color: var(--green); color: var(--green); font-weight: 600; }
.option-btn.incorrect { background: color-mix(in srgb, var(--red) 14%, transparent); border-color: var(--red); color: var(--red); }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.stat-card { padding: 16px; display: flex; flex-direction: column; gap: 2px; }
.stat-icon { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; margin-bottom: 8px; }
.stat-icon-flame { background: linear-gradient(135deg, var(--orange), var(--red)); }
.stat-icon-week { background: linear-gradient(135deg, var(--green), var(--teal)); }
.stat-value { font: var(--font-title1); letter-spacing: -0.5px; }
.stat-label { font: var(--font-footnote); color: var(--label-2); }

.today-cta-bar {
  position: fixed;
  bottom: calc(var(--safe-bottom) + var(--tabbar-h));
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  padding: 10px var(--page-pad);
  z-index: 39;
}
