/* ==========================================================================
   SilvaCoda home - v3 composition
   First-run and returning learner states share one app frame.
   Base tokens and Material You roles live in features/shared/tokens.css.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
[hidden] { display: none !important; }

::selection { background: var(--olive-200); color: var(--olive-950); }

:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 3px;
}

.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;
}

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */

.app {
  display: flex;
  min-height: 100vh;
}

.rail {
  width: 232px;
  flex: 0 0 232px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 14px 18px;
  background: var(--paper-2);
  border-right: 1px solid var(--line);
  z-index: 20;
}

.brand {
  padding: 0 10px 30px;
}

.brand-link {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  text-align: left;
}

.brand-name {
  display: block;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
  color: var(--olive-950);
}

.brand-dot { color: var(--olive-500); }

.brand-sub {
  display: block;
  margin-top: 6px;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-label {
  margin: 0;
  padding: 0 12px 8px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 50px;
  padding: 7px 11px;
  border-radius: 11px;
  color: var(--ink-2);
  text-align: left;
  position: relative;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}

.nav-item:hover {
  background: var(--olive-50);
  color: var(--olive-900);
}

.nav-item[aria-current="page"] {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}

.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 13px;
  bottom: 13px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--olive-600);
}

.nav-icon {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
}

.nav-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.nav-title {
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.nav-sub {
  margin-top: 2px;
  font-size: 9.5px;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
}

.nav-item[aria-current="page"] .nav-sub { color: var(--md-secondary); }

.rail-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.profile {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
}

.profile-first { display: none; }

body.is-first-run .profile-returning { display: none; }
body.is-first-run .profile-first { display: flex; }

.profile:hover { background: var(--olive-50); }

.profile-main {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 4px;
  border-radius: 9px;
  text-align: left;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--olive-200);
  color: var(--olive-900);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.avatar-icon { width: 17px; height: 17px; }

.avatar-first { display: none; }

body.is-first-run .avatar-returning { display: none; }
body.is-first-run .avatar-first { display: grid; }

.profile-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.profile-name {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.profile-meta {
  font-size: 9.5px;
  color: var(--muted);
  white-space: nowrap;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-2);
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}

.icon-btn:hover {
  background: var(--olive-50);
  border-color: var(--olive-200);
  color: var(--olive-900);
}

.icon-btn-sm {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  color: var(--muted);
}

.icon-btn-sm:hover { background: var(--olive-100); color: var(--olive-800); }

/* --------------------------------------------------------------------------
   Main canvas
   -------------------------------------------------------------------------- */

.main {
  flex: 1;
  min-width: 0;
  padding: 44px 48px 56px;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
}

.mobile-head { display: none; }

/* First visit is a state of the same app, not a second app. */
.home-first, .progress-first { display: none; }

body.is-first-run .home-first,
body.is-first-run .progress-first { display: block; }

body.is-first-run .home-returning,
body.is-first-run .progress-returning { display: none; }

body.is-first-run .wrap { max-width: 760px; }
body.is-first-run .head-actions { display: none; }
body.is-first-run .mobile-search { display: none; }

.mobile-brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.035em;
  color: var(--olive-950);
}

.mobile-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 0;
  font-size: 11px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(28px, 3.2vw, 40px);
  font-weight: 600;
  line-height: 1.06;
  letter-spacing: -0.04em;
  color: var(--ink);
  text-wrap: balance;
}

.lede {
  max-width: 56ch;
  margin: 10px 0 0;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink-2);
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 2px;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: var(--r-control);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.btn-primary {
  background: var(--md-dynamic-primary);
  color: var(--md-dynamic-on-primary);
}

.btn-primary:hover { background: var(--md-dynamic-primary-container); }
.btn-primary:active { transform: translateY(1px); }

.btn-icon {
  width: 15px;
  height: 15px;
}

.tiny-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
}

/* --------------------------------------------------------------------------
   Home — continue + this week
   -------------------------------------------------------------------------- */

.top-grid {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: 18px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}

.continue {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
}

.continue-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.continue-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--olive-700);
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--olive-500);
}

.continue-module { color: var(--muted); font-weight: 500; }

.continue h2 {
  margin: 0;
  font-size: clamp(22px, 2.3vw, 27px);
  font-weight: 600;
  line-height: 1.14;
  letter-spacing: -0.035em;
  color: var(--ink);
}

.continue-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--ink-2);
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 11px;
}

.progress-track {
  position: relative;
  height: 6px;
  flex: 1;
  background: var(--olive-100);
  border-radius: var(--r-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--md-secondary);
}

.progress-num {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--olive-800);
  font-variant-numeric: tabular-nums;
}

.continue-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: auto;
  padding-top: 2px;
}

.time {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.week {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  background: var(--olive-50);
  border-color: var(--olive-100);
}

.week-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.week h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.week-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--olive-700);
}

.week-link::after {
  content: "";
  position: absolute;
  inset: -15px -8px;
}

.week-link:hover { color: var(--olive-900); }

.bars {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  height: 66px;
  padding-top: 4px;
  border-bottom: 1px solid var(--olive-200);
}

.bar-col {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
}

.bar {
  width: 100%;
  max-width: 20px;
  min-height: 4px;
  border-radius: 4px 4px 0 0;
  background: var(--olive-300);
  transition: background var(--fast) var(--ease);
}

.bar.is-today { background: var(--olive-700); }

.bar-labels {
  display: flex;
  gap: 7px;
  margin-top: -4px;
}

.bar-label {
  flex: 1;
  text-align: center;
  font-size: 9px;
  font-weight: 500;
  color: var(--muted);
}

.week-summary {
  margin: auto 0 0;
  font-size: 11.5px;
  color: var(--ink-2);
  line-height: 1.5;
}

.week-summary strong {
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.week-summary .sep { color: var(--olive-400); padding: 0 2px; }

/* --------------------------------------------------------------------------
   Home — concept thread
   -------------------------------------------------------------------------- */

.thread {
  position: relative;
  overflow: hidden;
  padding: 34px;
  border-radius: 20px;
  background: var(--olive-900);
  color: var(--olive-50);
  margin-bottom: 20px;
}

.thread::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 150% at 88% -10%, rgba(142, 158, 112, 0.24), transparent 55%);
  pointer-events: none;
}

.thread-head {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin-bottom: 26px;
}

.thread .eyebrow { color: var(--olive-300); }

.thread h2 {
  margin: 0;
  font-size: clamp(30px, 3.6vw, 42px);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.045em;
  color: var(--olive-50);
}

.thread-sub {
  max-width: 54ch;
  margin: 10px 0 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--olive-200);
}

.thread-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.thread-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 190px;
  padding: 18px;
  border: 1px solid rgba(251, 249, 244, 0.16);
  border-radius: 13px;
  background: rgba(251, 249, 244, 0.025);
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.thread-card:hover {
  background: rgba(251, 249, 244, 0.07);
  border-color: rgba(251, 249, 244, 0.32);
  transform: translateY(-2px);
}

.thread-kicker {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--olive-300);
}

.thread-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.thread-title {
  margin: 0;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.28;
  letter-spacing: -0.02em;
  color: var(--olive-50);
  text-wrap: balance;
}

.thread-meta {
  margin: 0;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--olive-300);
}

.thread-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  margin-top: auto;
  padding-top: 11px;
  border-top: 1px solid rgba(251, 249, 244, 0.12);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--olive-50);
  text-align: left;
}

.thread-action:hover { color: var(--olive-200); }

/* --------------------------------------------------------------------------
   Home — first visit
   -------------------------------------------------------------------------- */

.start-band {
  position: relative;
  overflow: hidden;
  padding: 32px;
  border-radius: 20px;
  background: var(--olive-900);
  color: var(--olive-50);
  margin-bottom: 16px;
}

.start-band::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 150% at 88% -10%, rgba(142, 158, 112, 0.24), transparent 55%);
  pointer-events: none;
}

.start-band > * {
  position: relative;
  z-index: 1;
}

.start-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 28px;
  align-items: end;
}

.start-band .eyebrow {
  margin-bottom: 14px;
  color: var(--olive-300);
}

.start-band h2 {
  margin: 0;
  font-size: clamp(30px, 3.6vw, 42px);
  font-weight: 600;
  line-height: 1.04;
  letter-spacing: -0.045em;
  color: var(--olive-50);
  text-wrap: balance;
}

.start-sub {
  max-width: 46ch;
  margin: 12px 0 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--olive-200);
}

.start-meta {
  margin: 14px 0 0;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--olive-300);
}

.start-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 230px;
  flex-shrink: 0;
}

.btn-start {
  background: var(--olive-50);
  color: var(--olive-950);
}

.btn-start:hover { background: #FFFFFF; }

.start-browse {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--olive-200);
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(233, 238, 220, 0.35);
}

.start-browse:hover {
  color: var(--olive-50);
  text-decoration-color: currentColor;
}

.start-alt {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.alt-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.alt-kicker {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.11em;
  line-height: 1.4;
  text-transform: uppercase;
  color: var(--olive-700);
}

.alt-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.alt-title {
  margin: 2px 0 0;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-wrap: balance;
}

.alt-meta {
  margin: 0;
  font-size: 10.5px;
  color: var(--muted);
}

.alt-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  margin-top: auto;
  padding-top: 11px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--olive-800);
  text-align: left;
}

.alt-action:hover { color: var(--olive-600); }

.start-line {
  max-width: 58ch;
  margin: 0 0 26px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-2);
}

.start-line strong {
  font-weight: 600;
  color: var(--ink);
}

/* First-run Progress: an honest empty record */
.empty-record {
  margin-bottom: 26px;
  padding: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 18px;
  border-radius: 50%;
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}

.empty-record h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.empty-record p {
  max-width: 52ch;
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-2);
}

.empty-record .btn { margin-top: 20px; }

.empty-record .empty-note {
  margin-top: 14px;
  font-size: 10.5px;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Progress
   -------------------------------------------------------------------------- */

.summary-label {
  margin: 0 0 8px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 20px;
  border-radius: 14px;
}

.stat-num {
  font-size: 28px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel {
  padding: 22px;
  border-radius: var(--r-card);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.panel-note {
  margin: 3px 0 0;
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--muted);
}

.skills { display: flex; flex-direction: column; }

.skill {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 16px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.skill:first-child { border-top: 0; padding-top: 0; }
.skill:last-child { padding-bottom: 0; }

.skill-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
}

.skill-evidence {
  grid-column: 1;
  font-size: 10px;
  color: var(--muted);
}

.skill-pct {
  grid-column: 2;
  grid-row: 1;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--olive-800);
  font-variant-numeric: tabular-nums;
}

.skill-track {
  grid-column: 1 / -1;
  height: 5px;
  margin-top: 6px;
  background: var(--olive-100);
  border-radius: var(--r-pill);
  overflow: hidden;
}

.skill-fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--md-secondary);
}

.lower-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.activity-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 92px;
  padding-top: 4px;
  border-bottom: 1px solid var(--line);
}

.activity-bars .bar { background: var(--olive-200); }
.activity-bars .bar.is-today { background: var(--olive-700); }
.activity-bars .bar-label { font-size: 9px; }

.activity-summary {
  margin: 12px 0 0;
  font-size: 10.5px;
  color: var(--muted);
}

.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink-2);
}

.check-item.is-done { color: var(--ink); }

.check-mark {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  color: transparent;
  margin-top: 1px;
}

.check-item.is-done .check-mark {
  background: var(--md-secondary);
  border-color: var(--md-secondary);
  color: var(--md-on-secondary);
}

.check-icon { width: 10px; height: 10px; }

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  color: var(--muted);
}

.foot-preview { color: var(--muted); }

.foot-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.foot-switch {
  position: relative;
  min-height: 44px;
  font-size: 10px;
  font-weight: 500;
  color: var(--olive-700);
}

.foot-switch::after {
  content: "";
  position: absolute;
  inset: -14px -8px;
}

.foot-switch:hover { color: var(--olive-900); }

/* --------------------------------------------------------------------------
   Surface focus mode
   -------------------------------------------------------------------------- */

.surface {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 24px clamp(24px, 6vw, 80px) 44px;
  background: var(--surface-bg);
  color: var(--surface-ink);
  overflow-y: auto;
  transition: background-color 200ms var(--ease), color 200ms var(--ease);
}

.surface::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(110% 130% at 82% -10%, rgba(142, 158, 112, 0.16), transparent 55%);
  pointer-events: none;
}

.surface[data-surface="citadel"] {
  --surface-bg: #2E381C;
  --surface-ink: #F5F7EF;
  --surface-accent: #B6C69B;
  --surface-line: rgba(245, 247, 239, 0.16);
}

.surface[data-surface="stream"] {
  --surface-bg: #384623;
  --surface-ink: #F5F7EF;
  --surface-accent: #D4DEC0;
  --surface-line: rgba(245, 247, 239, 0.16);
}

.surface[data-surface="tutor"] {
  --surface-bg: #14150F;
  --surface-ink: #F5F7EF;
  --surface-accent: #B6C69B;
  --surface-line: rgba(245, 247, 239, 0.14);
}

.surface-top {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
}

.surface-return {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--surface-line);
  border-radius: var(--r-pill);
  color: var(--surface-ink);
  font-size: 11.5px;
  font-weight: 500;
  transition: background var(--fast) var(--ease);
}

.surface-return:hover { background: rgba(245, 247, 239, 0.08); }

.surface-badge {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--surface-accent);
  opacity: 0.75;
}

.surface-body {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 720px;
  margin: auto;
  padding: 54px 0 120px;
  transition: opacity 160ms var(--ease), transform 160ms var(--ease);
}

.surface-body.is-switching {
  opacity: 0;
  transform: translateY(6px);
}

.surface-eyebrow {
  margin: 0 0 14px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--surface-accent);
}

.surface h2 {
  margin: 0;
  font-size: clamp(40px, 7vw, 74px);
  font-weight: 600;
  line-height: 0.98;
  letter-spacing: -0.055em;
  color: var(--surface-ink);
  text-wrap: balance;
}

.surface-lede {
  max-width: 50ch;
  margin: 18px 0 30px;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--surface-accent);
  opacity: 0.82;
}

.surface-artifact {
  padding: 20px;
  border: 1px solid var(--surface-line);
  border-radius: 14px;
  background: rgba(245, 247, 239, 0.035);
  margin-bottom: 22px;
}

.surface-artifact-label {
  display: block;
  margin-bottom: 8px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--surface-accent);
}

.surface-artifact-title {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--surface-ink);
}

.surface-artifact-meta {
  margin: 5px 0 0;
  font-size: 11px;
  color: var(--surface-accent);
  opacity: 0.8;
}

.surface-code {
  margin: 14px 0 0;
  padding: 13px 14px;
  border: 1px solid var(--surface-line);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.28);
  font-family: var(--font-code);
  font-size: 12.5px;
  line-height: 1.5;
  color: #C9DBA9;
  overflow-x: auto;
}

.btn-surface {
  border-color: var(--surface-line);
  background: transparent;
  color: var(--surface-ink);
}

.btn-surface:hover { background: rgba(245, 247, 239, 0.08); }

/* --------------------------------------------------------------------------
   Surface switcher — the thread dock
   One tap changes the mode; the concept and the last place stay.
   -------------------------------------------------------------------------- */

.surface-dock {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: calc(100vw - 32px);
  padding: 5px;
  border: 1px solid rgba(29, 36, 17, 0.18);
  border-radius: var(--r-pill);
  background: var(--paper);
  color: var(--olive-950);
}

.surface-dock-context {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 0 10px 0 13px;
  line-height: 1.1;
  white-space: nowrap;
}

.surface-dock-label {
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.surface-dock-name {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--olive-950);
}

.surface-dock-divider {
  width: 1px;
  height: 26px;
  flex: 0 0 1px;
  margin: 0 4px;
  background: var(--line);
}

.surface-mode {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--olive-700);
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}

.surface-mode:hover {
  background: var(--olive-100);
  color: var(--olive-900);
}

.surface-mode.is-active {
  background: var(--md-primary);
  border-color: var(--md-primary);
  color: var(--md-on-primary);
}

.surface-mode.is-active:hover {
  background: var(--md-dynamic-primary-container);
  border-color: var(--md-dynamic-primary-container);
  color: var(--md-dynamic-on-primary-container);
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1080px) {
  .main { padding: 36px 32px 48px; }
  .top-grid { grid-template-columns: 1fr; }
  .week { min-height: 0; }
}

@media (max-width: 900px) {
  .app { display: block; }

  .rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: auto;
    height: auto;
    flex-direction: row;
    padding: 5px 8px calc(5px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
    background: rgba(244, 241, 232, 0.96);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    z-index: 50;
  }

  .brand, .rail-foot, .nav-label { display: none; }

  .nav {
    flex-direction: row;
    gap: 1px;
    width: 100%;
    justify-content: space-between;
  }

  .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    min-height: 54px;
    padding: 5px 2px;
    justify-content: center;
    text-align: center;
    border-radius: 9px;
  }

  .nav-item[aria-current="page"]::before { display: none; }

  .nav-icon { width: 20px; height: 20px; flex: 0 0 20px; }

  .nav-title { font-size: 9.5px; letter-spacing: 0; }
  .nav-sub { display: none; }

  .main { padding: 6px 20px 92px; }

  .mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0 10px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--line);
  }

  .head-actions .icon-btn { display: none; }

  .page-head { gap: 18px; margin-bottom: 22px; }

  .thread { padding: 24px; border-radius: 18px; }

  .thread-grid { grid-template-columns: 1fr; gap: 8px; }

  .thread-card { min-height: 0; padding: 16px; }

  .thread-head { margin-bottom: 20px; }

  .start-band { padding: 26px; }
  .start-top { grid-template-columns: 1fr; gap: 22px; align-items: start; }
  .start-actions { align-items: stretch; width: 100%; }
  .start-actions .btn { width: 100%; }
  .start-browse { text-align: left; }

  .surface { padding: 16px 20px 32px; }
  .surface-body { padding: 36px 0 110px; }
}

@media (max-width: 560px) {
  .summary-grid { grid-template-columns: 1fr; gap: 8px; }

  .stat {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    padding: 14px 16px;
  }

  .stat-num { font-size: 22px; }
  .stat-label { margin-top: 0; }

  .page-head { flex-direction: column; }
  .head-actions { padding-top: 0; }

  .continue { padding: 20px; }
  .week { padding: 18px; }

  .start-band { padding: 22px; border-radius: 16px; }
  .start-band h2 { font-size: 30px; }
  .start-alt { grid-template-columns: 1fr; }
  .start-line { margin-bottom: 22px; }
  .empty-record { padding: 22px; }
  .foot-meta { gap: 10px; }

  .continue-foot {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .continue-foot .btn { width: 100%; }

  .lower-grid { grid-template-columns: 1fr; }

  .foot { flex-direction: column; align-items: flex-start; }

  .surface-dock {
    left: 12px;
    right: 12px;
    bottom: 12px;
    transform: none;
    max-width: none;
    padding: 4px;
    gap: 2px;
  }

  .surface-dock-context { padding: 0 8px 0 10px; }
  .surface-dock-label { font-size: 7.5px; }
  .surface-dock-name { font-size: 10.5px; }
  .surface-dock-divider { height: 22px; margin: 0 2px; }
  .surface-mode { flex: 1; min-height: 44px; padding: 0 6px; font-size: 10.5px; }
}

@media (min-width: 901px) {
  body.is-first-run .progress-first {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 100px);
  }

  body.is-first-run .progress-first .empty-record {
    margin-top: auto;
    margin-bottom: auto;
  }

  body.is-first-run .progress-first .foot { margin-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
