/* Tango web: 375 px first, dark mode follows the system as the iPhone app does.
   One accent, Airbnb's Rausch: --accent for marks (bars, the active tab, focus rings),
   --accent-strong under white text (about 4.9:1), --accent-ink for accent text and links. */
:root {
  --bg: #ffffff;
  --surface: #f4f4f5;
  --text: #222222;
  --muted: #6a6a6a;
  --line: #e6e6e6;
  --accent: #ff385c;
  --accent-strong: #e00b41;
  --accent-press: #b8083a;
  --accent-ink: #e00b41;
  --on-accent: #ffffff;
  --again: #8b5e5e;
  --hard: #8a6a1c;
  --good: #2f7d4f;
  --easy: #3a6ea5;
  --bar-track: #ececec;
  --switch-off: #d9d9dc;
  --card-bg: #ffffff;
  --body-size: 17px;
  --small-size: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #222225;
    --text: #ececec;
    --muted: #a8a8ad;
    --line: #2f2f33;
    --accent-ink: #ff385c;
    --again: #c58f8f;
    --again-ink: #1a1a1a;
    --hard: #d4b061;
    --good: #6cc28f;
    --easy: #84aee0;
    --bar-track: #2c2c30;
    --switch-off: #3a3a3e;
    --card-bg: #121212;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--body-size)/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
a { color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: var(--small-size); }
.num { font-variant-numeric: tabular-nums; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Header and tabs */
.app-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  min-height: 52px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 2;
}
.app-header .title {
  margin: 0;
  font-size: var(--body-size);
  font-weight: 600;
  text-align: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-left { justify-self: start; min-width: 0; }
.header-right { justify-self: end; display: flex; align-items: center; gap: 4px; min-width: 0; }
.header-actions { display: flex; gap: 4px; }
.back, .text-btn {
  display: inline-flex; align-items: center;
  min-height: 40px; padding: 0 4px;
  border: none; background: none; color: var(--accent-ink);
  font: inherit; font-size: var(--small-size); font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.text-btn:disabled { color: var(--muted); opacity: 0.5; cursor: default; }

.status {
  display: inline-flex; align-items: center;
  min-height: 40px; padding: 0 4px;
  border: none; background: none; color: var(--accent-ink);
  font: inherit; font-size: var(--small-size); white-space: nowrap; cursor: pointer;
}
.status.offline { color: var(--muted); }

.tabs {
  display: flex;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.tabs a {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

.app-main { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 720px; margin: 0 auto; min-height: 0; }
.loading, .message { padding: 32px 16px; text-align: center; }
.message h1 { margin: 0 0 12px; }

/* Buttons */
.btn {
  font: inherit;
  font-size: 16px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent-strong); color: var(--on-accent); font-weight: 600; }
.btn.primary:active { background: var(--accent-press); }
.btn.danger { color: var(--accent-ink); }
.btn.wide { min-height: 52px; font-weight: 600; }
.link-btn {
  border: none; background: none; padding: 8px 4px; min-height: 40px;
  font: inherit; font-size: var(--small-size); font-weight: 600;
  color: var(--accent-ink); cursor: pointer;
}

.banner { margin: 8px 16px; padding: 8px 12px; border-radius: 8px; font-size: var(--small-size); overflow-wrap: anywhere; }
.banner.error { background: var(--accent-strong); color: var(--on-accent); }
.banner.info { background: var(--surface); color: var(--text); }

/* Deck list */
.stats-line { margin: 20px 16px 8px; font-size: var(--small-size); color: var(--muted); }
.deck-list { list-style: none; margin: 0; padding: 0 16px; }
.deck-list li + li { border-top: 1px solid var(--line); }
.deck-link {
  display: flex; flex-direction: column; gap: 2px;
  padding: 16px 0;
  color: var(--text); text-decoration: none;
}
.deck-name { font-weight: 600; overflow-wrap: anywhere; }
.deck-counts { font-size: var(--small-size); color: var(--muted); overflow-wrap: anywhere; }

/* Study */
.study { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.study-card { flex: 1; display: flex; flex-direction: column; min-height: 240px; }
.caption { margin: 8px 16px 0; text-align: center; font-size: var(--small-size); color: var(--muted); }
.card-frame { flex: 1; width: 100%; border: none; background: var(--card-bg); min-height: 240px; display: block; }
.card-tools { display: flex; justify-content: center; padding: 0 16px; }
.controls { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px 16px; background: var(--bg); }
.type-row { display: flex; gap: 8px; }
.answer-input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 18px;
  min-height: 44px; padding: 8px 12px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.answer-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.front-buttons { display: flex; justify-content: center; gap: 16px; }
.front-buttons:empty { display: none; }
.answer-extras { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.typed-result { margin: 0; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.typed-result p { margin: 0; }
.typed-result.right { color: var(--good); font-weight: 600; }
.typed-result.wrong { color: var(--muted); font-size: var(--small-size); }
.typed-result .typed-answer { color: var(--text); font-size: var(--body-size); font-weight: 600; }
.grades { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.grade { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; padding: 6px 2px; min-width: 0; }
.grade .ivl { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.grade .grade-title { font-weight: 600; }
.grade.again .grade-title { color: var(--again); }
.grade.hard .grade-title { color: var(--hard); }
.grade.good .grade-title { color: var(--good); }
.grade.easy .grade-title { color: var(--easy); }
.grade.again.prominent { background: var(--again); }
.grade.again.prominent .grade-title, .grade.again.prominent .ivl { color: var(--again-ink, #ffffff); }

.done { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px 16px; text-align: center; }
.done h2 { margin: 0; font-size: 20px; }
.done p { margin: 0; }
.done .btn { width: 100%; max-width: 420px; margin-top: 12px; flex: none; }

/* Settings */
.settings { padding: 8px 0 32px; }
.group { margin: 20px 16px; }
.group h3 { margin: 0 0 4px; font-size: var(--small-size); font-weight: 600; color: var(--muted); }
.group-body > * + * { border-top: 1px solid var(--line); }
.group .footer { margin: 6px 0 0; font-size: var(--small-size); color: var(--muted); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 6px 0; }
.setting-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.row-btn {
  display: block; width: 100%;
  font: inherit; text-align: left;
  min-height: 52px; padding: 13px 0;
  border: none; background: none; color: var(--accent-ink); cursor: pointer;
}
.row-btn:disabled { color: var(--muted); opacity: 0.6; cursor: default; }
.stepper { display: flex; align-items: center; gap: 8px; flex: none; }
.stepper .btn { min-width: 44px; padding: 0; font-size: 20px; }
.stepper-value { min-width: 36px; text-align: center; font-variant-numeric: tabular-nums; }
.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 51px; height: 31px; margin: 0;
  border-radius: 16px; background: var(--switch-off);
  position: relative; cursor: pointer; transition: background 0.15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.sign-out { display: block; margin: 32px auto 0; color: var(--muted); font-weight: 500; text-decoration: underline; }

/* Class board */
.board { padding: 8px 0 32px; display: flex; flex-direction: column; gap: 8px; }
.board > .btn { align-self: center; margin-top: 12px; }
.board > .muted { padding: 0 16px; }
.people { list-style: none; margin: 0; padding: 0 16px; }
.person { padding: 16px 0; }
.person + .person { border-top: 1px solid var(--line); }
.person-name { margin: 0; font-size: var(--body-size); overflow-wrap: anywhere; }
.you { margin-left: 6px; font-size: var(--small-size); font-weight: 400; color: var(--muted); }
.person-stats, .person-saved { margin: 2px 0 0; font-size: var(--small-size); color: var(--muted); }
.deck-bars { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bar-label { display: flex; justify-content: space-between; gap: 8px; font-size: var(--small-size); }
.bar-name { min-width: 0; overflow-wrap: anywhere; }
.bar-value { flex: none; color: var(--muted); }
.bar { position: relative; height: 4px; border-radius: 2px; background: var(--bar-track); overflow: hidden; margin-top: 4px; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; background: var(--accent); }

/* Dialogs */
.modal {
  border: none; border-radius: 14px; padding: 20px 16px 16px;
  width: min(420px, calc(100vw - 32px));
  background: var(--bg); color: var(--text);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 16px; color: var(--muted); overflow-wrap: anywhere; }
.modal-buttons { display: flex; flex-direction: column; gap: 8px; }
.modal-buttons .btn { width: 100%; }
.modal-buttons .btn.danger { background: var(--accent-strong); color: var(--on-accent); font-weight: 600; }

@media (min-width: 720px) {
  .app-main { padding: 0 16px; }
}
