:root {
  --bg: var(--page);
  --rust: #8b5e4b;
  --blue: #4c667d;
  --green: var(--success);
  --red: var(--danger);
}

body { background: var(--bg); }

/* ---- App shell ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  min-height: 58px;
  padding: 0 max(24px, calc((100% - 1040px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}
.brand { color: var(--ink); font-weight: 760; text-decoration: none; }
.primary-nav { display: flex; align-items: stretch; min-height: 58px; }
.mobile-account-link { display: none !important; }
.primary-nav a {
  display: grid;
  place-items: center;
  min-width: 104px;
  padding: 0 14px;
  border-bottom: 2px solid transparent;
  color: var(--ink-secondary);
  font-size: 14px;
  text-decoration: none;
}
.primary-nav a:hover { color: var(--accent); background: var(--accent-soft); }
.primary-nav a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--accent); font-weight: 700; }
.account-link { justify-self: end; color: var(--blue); font-size: 14px; font-weight: 700; text-decoration: none; }
.brand:focus-visible, .primary-nav a:focus-visible, .account-link:focus-visible, .primary-command:focus-visible, .text-link:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.app-main { width: min(960px, calc(100% - 40px)); margin: 0 auto; padding: 48px 0 80px; }
.site-footer { width: min(960px, calc(100% - 40px)); }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.eyebrow, .section-label { margin: 0 0 7px; color: var(--rust); font-size: 12px; font-weight: 750; }
h1, h2, p { letter-spacing: 0; }
h1 { margin: 0; font-size: 34px; line-height: 1.2; }
h2 { margin: 0; font-size: 20px; line-height: 1.35; }
p { color: var(--ink-secondary); line-height: 1.65; }
.sync-state { color: var(--muted); font-size: 13px; }
.sync-state.offline { color: var(--red); }

/* ---- Metric strip ---- */
.metric-strip { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.metric-strip div { min-height: 98px; padding: 22px 0; border-right: 1px solid var(--line); }
.metric-strip div + div { padding-left: 28px; }
.metric-strip div:last-child { border-right: 0; }
.metric-strip span, .metric-strip strong { display: block; }
.metric-strip span { color: var(--muted); font-size: 12px; }
.metric-strip strong { margin-top: 12px; font-size: 24px; }
.metric-strip strong small { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 4px; }

/* ---- Sections ---- */
.primary-section, .secondary-section, .empty-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 34px 0;
  border-bottom: 1px solid var(--line);
}
.primary-section p:not(.section-label), .secondary-section p:not(.section-label), .empty-state p:not(.section-label) { max-width: 620px; margin: 8px 0 0; }
.primary-command {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 10px 18px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--accent);
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}
.primary-command:hover { background: #34594b; }
.primary-command:disabled { opacity: 0.6; cursor: default; }
.text-link { color: var(--blue); font-weight: 720; text-decoration: none; cursor: pointer; background: none; border: 0; padding: 0; }
.text-link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---- State blocks (loading / error) ---- */
.state-block { padding: 40px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.state-block p { margin: 0; text-align: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-state h2 { margin-bottom: 4px; }

/* ---- Library ---- */
.library-tools { display: grid; grid-template-columns: minmax(260px, 1fr) auto; gap: 12px; padding: 22px 0; border-bottom: 1px solid var(--line); }
.search-field input { width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--ink); background: var(--surface); }
.search-field input:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; }
.segmented { display: grid; grid-template-columns: repeat(3, 72px); padding: 3px; border: 1px solid var(--line); border-radius: var(--radius); background: #e9edeb; }
.segmented button { border: 0; border-radius: 4px; color: var(--muted); background: transparent; cursor: pointer; padding: 6px 0; }
.segmented button[aria-pressed="true"] { color: var(--accent); background: var(--surface); font-weight: 700; }
.segmented button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.library-list { padding: 8px 0; }
.library-row { display: grid; grid-template-columns: 52px 1fr 1.2fr 48px; gap: 12px; align-items: center; width: 100%; padding: 14px 8px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.library-row:hover { background: var(--accent-soft); }
.library-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.lib-kind { font-size: 11px; color: var(--muted); }
.lib-form { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-meaning { color: var(--ink-secondary); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-status { font-size: 11px; text-align: center; padding: 2px 0; border-radius: 3px; }
.lib-status.new { background: var(--accent-soft); color: var(--accent); }
.lib-status.learning { background: #fdf0e6; color: var(--rust); }
.lib-status.reviewing { background: #eaf0f6; color: var(--blue); }
.lib-status.mastered { background: #e8f0ea; color: var(--green); }
.lib-status.suspended { background: #eee; color: var(--muted); }

/* ---- Item drawer ---- */
.item-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); background: var(--surface); border-left: 1px solid var(--line); box-shadow: -4px 0 24px rgba(0,0,0,0.08); transform: translateX(100%); transition: transform 200ms ease; z-index: 30; overflow-y: auto; }
.item-drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: start; justify-content: space-between; padding: 24px 24px 16px; border-bottom: 1px solid var(--line); }
.drawer-close { border: 0; background: none; font-size: 28px; color: var(--muted); cursor: pointer; line-height: 1; }
.drawer-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 12px; }
.drawer-meaning { font-size: 16px; color: var(--ink); font-weight: 600; }
.drawer-ipa { color: var(--blue); font-size: 15px; }
.drawer-gloss { color: var(--ink-secondary); }
.drawer-meta { font-size: 13px; }
.drawer-meta span { color: var(--muted); margin-right: 6px; }
.drawer-example { font-style: italic; color: var(--ink); border-left: 3px solid var(--accent); padding-left: 12px; }
.drawer-translation { color: var(--ink-secondary); font-size: 14px; }

/* ---- Progress dimensions ---- */
.progress-summary { display: flex; align-items: center; gap: 20px; padding: 18px 0; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.progress-summary a { margin-left: auto; }
.dimension-list { border-top: 1px solid var(--line); padding: 8px 0; }
.dim-bar { display: grid; grid-template-columns: 90px 1fr 44px; gap: 16px; align-items: center; min-height: 50px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.dim-label { color: var(--ink-secondary); font-size: 14px; }
.dim-track { height: 8px; background: var(--accent-soft); border-radius: 4px; overflow: hidden; }
.dim-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 400ms ease; }
.dim-value { text-align: right; font-size: 14px; font-weight: 700; color: var(--accent); }

/* ---- Task executor ---- */
.task-card { padding: 32px 0; border-bottom: 1px solid var(--line); }
.task-cue { font-size: 22px; font-weight: 700; color: var(--ink); margin: 0 0 16px; }
.task-instructions { color: var(--ink-secondary); margin: 0 0 20px; }
.task-choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.task-target { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.task-choice { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: center; min-height: 48px; gap: 10px; padding: 10px 16px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; text-align: left; }
.task-choice-key { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-size: 12px; }
.task-choice:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.task-choice:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.task-choice:disabled { opacity: 0.6; cursor: default; }
.task-input { width: 100%; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--ink); background: var(--surface); }
.task-input:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; }
.task-input:disabled { opacity: 0.6; }
.task-hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.task-audio { min-height: 40px; padding: 8px 16px; border: 1px solid var(--blue); border-radius: var(--radius); background: transparent; color: var(--blue); font-weight: 600; cursor: pointer; margin-bottom: 16px; }
.task-feedback { padding: 20px 0; border-bottom: 1px solid var(--line); }
.task-feedback.correct .feedback-label { color: var(--green); }
.task-feedback.wrong .feedback-label { color: var(--red); }
.feedback-label { font-size: 18px; font-weight: 700; margin: 0 0 6px; }
.feedback-detail { color: var(--ink-secondary); margin: 0 0 12px; }

/* ---- Onboarding form ---- */
.onboarding-form { padding: 32px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 20px; max-width: 480px; }
.onboarding-form > p:first-child { color: var(--ink-secondary); }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 13px; font-weight: 700; color: var(--ink); }
.form-field select, .form-field input { min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--ink); background: var(--surface); }
.form-field select:focus-visible, .form-field input:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; }
.form-error { color: var(--red); font-size: 13px; }

/* ---- Empty state ---- */
.empty-state { min-height: 220px; align-items: flex-start; flex-direction: column; justify-content: center; gap: 8px; }
/* ---- Mobile ---- */
@media (max-width: 720px) {
  .app-header { grid-template-columns: 1fr auto; min-height: 54px; padding: 0 16px; }
  .account-link { display: none; }
  .primary-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 20; min-height: 58px; border-top: 1px solid var(--line); background: var(--surface); }
  .primary-nav a { flex: 1; min-width: 0; border-top: 2px solid transparent; border-bottom: 0; font-size: 13px; }
  .mobile-account-link { display: grid !important; }
  .primary-nav a[aria-current="page"] { border-top-color: var(--accent); border-bottom: 0; }
  .app-main { width: min(100% - 32px, 960px); padding: 32px 0; }
  .site-footer { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
  h1 { font-size: 28px; }
  .metric-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric-strip div { min-height: 88px; padding: 18px 12px 18px 0; }
  .metric-strip div + div { padding-left: 12px; }
  .metric-strip strong { font-size: 20px; }
  .primary-section, .secondary-section { align-items: flex-start; flex-direction: column; gap: 18px; }
  .library-tools { grid-template-columns: 1fr; }
  .segmented { grid-template-columns: repeat(3, 1fr); min-height: 40px; }
  .library-row { grid-template-columns: 44px 1fr 40px; }
  .lib-meaning { display: none; }
  .task-choices { grid-template-columns: 1fr; }
  .dim-bar { grid-template-columns: 72px 1fr 36px; gap: 10px; }
  .item-drawer { width: 100%; }
}

@media (prefers-reduced-motion: no-preference) {
  .primary-nav a, .primary-command, .text-link { transition: color 160ms ease, background 160ms ease, border-color 160ms ease; }
  .item-drawer { transition: transform 200ms ease; }
  .dim-fill { transition: width 400ms ease; }
}
