:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-solid: #fff;
  --ink: #1d1d1f;
  --sub: #6e6e73;
  --line: rgba(60, 60, 67, .14);
  --line-strong: rgba(60, 60, 67, .22);
  --accent: #007aff;
  --accent-strong: #0063d1;
  --accent-soft: rgba(0, 122, 255, .12);
  --violet: #5856d6;
  --violet-soft: rgba(88, 86, 214, .13);
  --ok: #248a5a;
  --ok-soft: rgba(52, 199, 89, .14);
  --bad: #d70015;
  --bad-soft: rgba(255, 59, 48, .12);
  --warn: #a05b00;
  --warn-soft: rgba(255, 149, 0, .13);
  --radius-sm: 14px;
  --radius: 20px;
  --radius-lg: 28px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .07);
  --shadow: 0 5px 14px rgba(0, 0, 0, .08);
  --material: #ffffff;
  --ease-out: cubic-bezier(.2, .85, .25, 1);
  font: 100%/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-optical-sizing: auto;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  max-width: 900px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 18px 60px;
  color: var(--ink);
  background: var(--bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
::selection { color: #fff; background: var(--accent); }

.topbar {
  position: sticky;
  top: 10px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  min-height: 58px;
  margin: 10px 0 8px;
  padding: 9px 12px 9px 16px;
  border: 1px solid rgba(255, 255, 255, .58);
  border-radius: var(--radius);
  background: var(--material);
  box-shadow: var(--shadow-sm);
}
.topbar h1 { margin: 0; font-size: 1.08rem; font-weight: 760; letter-spacing: -.025em; }
.topbar h1 a { color: inherit; text-decoration: none; }
.topbar h1 a:hover { color: var(--accent); }
.topbar small { margin-left: 5px; color: var(--sub); font-size: .76rem; font-weight: 580; }
.top-actions { display: flex; align-items: center; gap: 7px; }
.app-switch { padding: 6px 4px; color: var(--sub); font-size: .78rem; font-weight: 680; text-decoration: none; white-space: nowrap; }
.app-switch:hover { color: var(--accent); }
.account-badge, .known-badge { display: inline-flex; align-items: center; min-height: 31px; max-width: 128px; overflow: hidden; padding: 5px 10px; border: 1px solid rgba(0, 122, 255, .18); border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: .79rem; font-weight: 720; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.known-badge { border-color: rgba(52, 199, 89, .22); color: var(--ok); background: var(--ok-soft); }
.theme-toggle { display: inline-flex; align-items: center; gap: 5px; min-height: 31px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--sub); background: rgba(255, 255, 255, .62); cursor: pointer; font-size: .76rem; font-weight: 700; transition: transform 130ms var(--ease-out), color 150ms ease, background-color 150ms ease, border-color 150ms ease; }
.theme-toggle:hover { border-color: rgba(0, 122, 255, .24); color: var(--accent); background: var(--accent-soft); }
.theme-toggle:active { transform: scale(.96); }
.theme-toggle [data-theme-icon] { width: 14px; font-size: 1rem; line-height: 1; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 0 2px 23px; padding: 4px; border: 1px solid rgba(255, 255, 255, .45); border-radius: 16px; background: rgba(118, 118, 128, .11); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; padding: 8px 11px; border: 0; border-radius: 11px; color: var(--sub); background: transparent; cursor: pointer; font-size: .84rem; font-weight: 680; white-space: nowrap; transition: color 160ms ease, background-color 160ms ease, box-shadow 160ms ease, transform 120ms var(--ease-out); }
.tab:hover { color: var(--ink); background: rgba(255, 255, 255, .52); }
.tab.active { color: var(--ink); background: var(--surface-solid); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.tab:active { transform: scale(.97); }

main { min-width: 0; }
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }
.card, .hero-card, .overall-card {
  position: relative;
  margin-bottom: 14px;
  padding: 21px;
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.card h2, .overall-card h2 { margin: 0 0 8px; font-size: 1.14rem; font-weight: 760; letter-spacing: -.025em; line-height: 1.25; }
.card h3 { margin: 18px 0 8px; font-size: .95rem; font-weight: 730; }
.muted, .view-heading p { margin: 0; color: var(--sub); font-size: .9rem; line-height: 1.6; }
.eyebrow { display: inline-flex; margin-bottom: 5px; color: var(--accent); font-size: .68rem; font-weight: 790; letter-spacing: .07em; }
.view-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 2px 1px 16px; }
.view-heading h2 { margin: 0; font-size: clamp(1.38rem, 3vw, 1.7rem); font-weight: 770; letter-spacing: -.035em; line-height: 1.2; }
.view-heading p { max-width: 340px; text-align: right; }

.hero-card { overflow: hidden; padding: clamp(25px, 5vw, 38px); border-color: rgba(0, 122, 255, .18); background: #f3f7ff; box-shadow: var(--shadow-sm); }
.hero-card::after { display: none; }
.hero-card > * { position: relative; z-index: 1; }
.hero-card h2 { max-width: 620px; margin: 0 0 9px; font-size: clamp(1.7rem, 5.3vw, 2.45rem); font-weight: 790; letter-spacing: -.055em; line-height: 1.14; }
.hero-card p { max-width: 600px; margin: 0; color: #4d5870; font-size: .98rem; line-height: 1.6; }
.hero-actions, .button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 19px; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 9px 14px; border: 1px solid transparent; border-radius: 999px; color: #fff; background: var(--accent); box-shadow: 0 1px 2px rgba(0, 76, 173, .18); cursor: pointer; font-size: .88rem; font-weight: 730; letter-spacing: -.01em; transition: transform 130ms var(--ease-out), background-color 160ms ease, box-shadow 160ms ease, border-color 160ms ease; }
.btn:hover { background: var(--accent-strong); box-shadow: 0 5px 14px rgba(0, 103, 209, .24); }
.btn:active, .section-card:active, .choice:active, .known-toggle:active { transform: scale(.97); box-shadow: none; }
.btn.primary { color: #fff; background: var(--accent); }
.btn.secondary { border-color: rgba(0, 122, 255, .2); color: var(--accent); background: var(--accent-soft); box-shadow: none; }
.btn.secondary:hover { background: rgba(0, 122, 255, .18); }
.btn.ghost { border-color: var(--line); color: var(--sub); background: rgba(255, 255, 255, .48); box-shadow: none; }
.btn.ghost:hover { color: var(--ink); background: var(--surface-solid); }
.btn.know { border-color: rgba(52, 199, 89, .25); color: #17643f; background: var(--ok-soft); box-shadow: none; }
.btn.unknown, .btn.danger { border-color: rgba(255, 59, 48, .24); color: var(--bad); background: var(--bad-soft); box-shadow: none; }
.btn.small { min-height: 36px; padding: 7px 11px; }
.danger-card { border-color: rgba(255, 59, 48, .25); }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px; margin-bottom: 14px; }
.summary-card { display: flex; min-height: 128px; flex-direction: column; justify-content: space-between; padding: 17px; border: 1px solid rgba(255, 255, 255, .72); border-radius: 18px; background: var(--surface); }
.summary-card span, .summary-card small { color: var(--sub); font-size: .8rem; }
.summary-card strong { margin: 6px 0; color: var(--accent); font-size: 1.52rem; font-weight: 780; letter-spacing: -.045em; }
.summary-card:nth-child(2) strong { color: var(--violet); }
.summary-card:nth-child(3) strong { color: var(--ok); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.section-heading h2 { margin: 0; }
.text-button { padding: 4px 0; border: 0; color: var(--accent); background: transparent; cursor: pointer; font-size: .88rem; font-weight: 750; }
.section-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.section-card { display: flex; min-width: 0; flex-direction: column; gap: 6px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--surface-solid); cursor: pointer; text-align: left; transition: transform 160ms var(--ease-out), border-color 160ms ease, background-color 160ms ease; }
.section-card:hover { border-color: rgba(0, 122, 255, .28); background: #f7faff; transform: translateY(-1px); }
.section-card strong { overflow: hidden; font-size: .9rem; text-overflow: ellipsis; white-space: nowrap; }
.section-card > span { color: var(--sub); font-size: .79rem; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input, .toolbar select { min-height: 41px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 12px; outline: none; color: var(--ink); background: rgba(255, 255, 255, .8); font-size: .91rem; transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease; }
.toolbar input { flex: 1 1 220px; }
.toolbar select { flex: 1 1 156px; }
.toolbar input:hover, .toolbar select:hover { border-color: var(--line-strong); }
.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); background: var(--surface-solid); box-shadow: 0 0 0 4px rgba(0, 122, 255, .14); }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--sub); font-size: .85rem; white-space: nowrap; }
.check input { accent-color: var(--accent); }

.dictionary-section { overflow: hidden; margin-bottom: 20px; border: 1px solid rgba(255, 255, 255, .7); border-radius: var(--radius); background: var(--surface); }
.dictionary-section h3 { margin: 0; padding: 15px 17px; border-bottom: 1px solid var(--line); color: var(--accent); font-size: .98rem; }
.dictionary-item { display: grid; grid-template-columns: 29px minmax(150px, 1fr) minmax(130px, 1fr) auto; align-items: center; gap: 10px; padding: 12px 17px; }
.dictionary-item + .dictionary-item { border-top: 1px solid var(--line); }
.dictionary-item.known { border-left: 3px solid var(--ok); padding-left: 14px; background: var(--ok-soft); }
@supports (content-visibility: auto) {
  .dictionary-item { content-visibility: auto; contain-intrinsic-size: auto 56px; }
}
.known-toggle { width: 29px; height: 29px; padding: 0; border: 0; border-radius: 9px; color: var(--accent); background: var(--accent-soft); cursor: pointer; font-size: 1.05rem; line-height: 1; transition: transform 130ms var(--ease-out), background-color 150ms ease; }
.known .known-toggle { color: #17643f; background: var(--ok-soft); }
.translation { color: var(--sub); }
.tag { padding: 3px 8px; border-radius: 999px; color: #4c5da7; background: rgba(88, 86, 214, .1); font-size: .71rem; font-weight: 700; white-space: nowrap; }
.empty { margin: 0; padding: 30px 12px; color: var(--sub); text-align: center; }
.empty.success { color: var(--ok); font-weight: 740; }

#flash-area { text-align: center; }
.flash-card { position: relative; display: block; width: min(100%, 620px); min-height: 268px; margin: 0 auto 15px; padding: 0; border: 0; border-radius: 23px; background: transparent; cursor: pointer; perspective: 1000px; }
.flash-face { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 30px; border: 1px solid rgba(255, 255, 255, .8); border-radius: 23px; color: var(--ink); background: var(--surface-solid); box-shadow: var(--shadow-sm); backface-visibility: hidden; transition: transform 220ms var(--ease-out); }
.flash-face strong { max-width: 100%; font-size: clamp(1.24rem, 4vw, 1.7rem); font-weight: 760; line-height: 1.45; letter-spacing: -.02em; }
.flash-face small { color: var(--ok); font-size: .78rem; font-weight: 750; }
.flash-back { color: #fff; border-color: rgba(255, 255, 255, .22); background: #007aff; transform: rotateY(180deg); }
.flash-back .card-label, .flash-back small { color: rgba(255, 255, 255, .76); }
.flash-card.flipped .flash-face:first-child { transform: rotateY(180deg); }
.flash-card.flipped .flash-back { transform: rotateY(0); }
.flash-card.instant-flip .flash-face { transition: none; }
.card-label { color: var(--sub); font-size: .7rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.counter, .hint { color: var(--sub); font-size: .84rem; }
.flash-controls { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.hint { margin: 13px 0 0; }

.quiz-toolbar { margin: 0; }
.quiz-progress { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; color: var(--sub); font-size: .84rem; font-weight: 650; }
.progress-bar { height: 8px; overflow: hidden; border-radius: 999px; background: rgba(118, 118, 128, .18); }
.progress-bar > div { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--violet)); transition: width 180ms var(--ease-out); }
.section-card .progress-bar { height: 5px; margin-top: 2px; }
.quiz-question { margin: 16px 0 12px; padding: 25px; border: 1px solid rgba(0, 122, 255, .17); border-radius: 17px; background: rgba(0, 122, 255, .07); font-size: clamp(1.16rem, 3.5vw, 1.35rem); font-weight: 760; letter-spacing: -.025em; text-align: center; }
.choices { display: grid; gap: 8px; }
.choice { min-height: 49px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 13px; color: var(--ink); background: rgba(255, 255, 255, .64); cursor: pointer; text-align: left; transition: transform 130ms var(--ease-out), border-color 150ms ease, background-color 150ms ease, color 150ms ease; }
.choice:hover:not(:disabled) { border-color: rgba(0, 122, 255, .5); background: var(--accent-soft); }
.choice.correct { border-color: rgba(52, 199, 89, .5); color: #17643f; background: var(--ok-soft); font-weight: 750; }
.choice.wrong { border-color: rgba(255, 59, 48, .45); color: var(--bad); background: var(--bad-soft); }
.choice:disabled { cursor: default; }
.feedback { min-height: 24px; margin: 12px 0; font-weight: 730; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.result-score { margin: 10px 0 19px; color: var(--accent); font-size: clamp(2rem, 6vw, 2.6rem); font-weight: 790; letter-spacing: -.06em; }
.wrong-item { display: flex; flex-direction: column; gap: 2px; padding: 11px 12px; border: 1px solid rgba(255, 59, 48, .22); border-radius: 12px; background: var(--bad-soft); }
.wrong-item + .wrong-item { margin-top: 6px; }
.wrong-item span { color: var(--sub); font-size: .89rem; }

.overall-card { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 16px; }
.overall-card > strong { grid-row: span 2; color: var(--accent); font-size: 2.2rem; font-weight: 790; letter-spacing: -.065em; }
.overall-card > span { color: var(--sub); font-size: .9rem; }
.overall-card .progress-bar { grid-column: 1 / -1; margin-top: 10px; }
.progress-row { margin-top: 14px; }
.progress-row:first-child { margin-top: 0; }
.progress-row > div:first-child { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-size: .89rem; }
.progress-row span, .history-item span { color: var(--sub); font-size: .82rem; }
.history-item { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; }
.history-item + .history-item { border-top: 1px solid var(--line); }
.history-item strong { font-size: .88rem; }
footer { margin-top: 40px; color: #98989d; font-size: .75rem; text-align: center; }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(0, 122, 255, .36); outline-offset: 3px; }

@media (max-width: 640px) {
  body { padding: 0 12px 42px; }
  .topbar { top: 6px; align-items: flex-start; margin-top: 6px; padding: 10px 11px 10px 14px; border-radius: 18px; }
  .topbar h1 { max-width: 146px; line-height: 1.25; }
  .topbar small { display: block; margin: 2px 0 0; }
  .top-actions { align-items: flex-end; flex-direction: column; gap: 4px; }
  .app-switch { padding: 0; }
  .theme-toggle-label { display: none; }
  .known-badge { display: none; }
  .account-badge { max-width: 102px; }
  .tabs { margin-bottom: 17px; border-radius: 14px; }
  .tab { padding: 8px 10px; font-size: .81rem; }
  .card, .hero-card, .overall-card { padding: 18px; border-radius: 18px; }
  .hero-card { padding: 25px 21px; }
  .summary-grid, .section-grid { grid-template-columns: 1fr; }
  .summary-card { min-height: 96px; }
  .view-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
  .view-heading p { text-align: left; }
  .dictionary-item { grid-template-columns: 29px 1fr auto; }
  @supports (content-visibility: auto) {
    .dictionary-item { contain-intrinsic-size: auto 78px; }
  }
  .dictionary-item .translation, .tag { grid-column: 2 / -1; }
  .tag { justify-self: start; }
  .flash-card { min-height: 240px; }
  .flash-face { padding: 24px; border-radius: 19px; }
  .history-item { align-items: flex-start; flex-direction: column; gap: 2px; }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000;
  --surface: #1c1c1e;
  --surface-solid: #1c1c1e;
  --ink: #f5f5f7;
  --sub: #a1a1a6;
  --line: rgba(235, 235, 245, .16);
  --line-strong: rgba(235, 235, 245, .25);
  --accent: #0a84ff;
  --accent-strong: #409cff;
  --accent-soft: rgba(10, 132, 255, .2);
  --violet: #5e5ce6;
  --violet-soft: rgba(94, 92, 230, .2);
  --ok: #30d158;
  --ok-soft: rgba(48, 209, 88, .16);
  --bad: #ff453a;
  --bad-soft: rgba(255, 69, 58, .17);
  --warn: #ff9f0a;
  --warn-soft: rgba(255, 159, 10, .18);
  --material: #1c1c1e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .28);
  --shadow: 0 5px 14px rgba(0, 0, 0, .32);
}
html[data-theme="dark"] body { background: var(--bg); }
html[data-theme="dark"] .topbar, html[data-theme="dark"] .tabs, html[data-theme="dark"] .card, html[data-theme="dark"] .hero-card, html[data-theme="dark"] .overall-card, html[data-theme="dark"] .summary-card, html[data-theme="dark"] .section-card, html[data-theme="dark"] .dictionary-section, html[data-theme="dark"] .flash-face { border-color: rgba(255, 255, 255, .1); }
html[data-theme="dark"] .topbar { border-top-color: rgba(255, 255, 255, .17); }
html[data-theme="dark"] .tabs { background: rgba(118, 118, 128, .24); }
html[data-theme="dark"] .tab:hover { background: rgba(255, 255, 255, .08); }
html[data-theme="dark"] .tab.active { background: #3a3a3c; box-shadow: none; }
html[data-theme="dark"] .account-badge, html[data-theme="dark"] .theme-toggle, html[data-theme="dark"] .toolbar input, html[data-theme="dark"] .toolbar select, html[data-theme="dark"] .section-card, html[data-theme="dark"] .choice, html[data-theme="dark"] .btn.ghost { background: #2c2c2e; }
html[data-theme="dark"] .toolbar input:focus, html[data-theme="dark"] .toolbar select:focus { background: #2c2c2e; }
html[data-theme="dark"] .hero-card { background: #20283a; }
html[data-theme="dark"] .hero-card p { color: #c3cfde; }
html[data-theme="dark"] .dictionary-item.known { background: var(--ok-soft); }
html[data-theme="dark"] .choice.correct { color: #7ef3a0; }
html[data-theme="dark"] .tag { color: #c6c8ff; background: var(--violet-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .topbar, .card, .hero-card, .overall-card, .summary-card, .dictionary-section, .flash-face { background: var(--surface-solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .topbar, .tabs, .card, .hero-card, .overall-card, .summary-card, .section-card, .dictionary-section, .flash-face { border-color: var(--line-strong); }
  .muted, .view-heading p { color: var(--ink); }
}
