:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --paper: #f7f6f2;
  --surface: #fffefa;
  --ink: #261f1d;
  --muted: #68615b;
  --rule: #e2ddd4;
  --accent: #c43722;
  --accent-solid: #d13c25;
  --accent-white: #fff9f2;
  --hero: #f4dfd5;
  --hero-ring: #da9c88;
  --card-back: #f7f2e9;
  --mint: #deeee5;
  --mint-ink: #205a42;
  --lilac: #eae6f8;
  --lilac-ink: #523c88;
  --rose: #f7e1d8;
  --red-wash: #faece6;
  --shadow: 0 12px 34px #332a1810;
  --serif: Georgia, "Times New Roman", serif;
  --ease: cubic-bezier(.22, .8, .22, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1c1a18;
  --surface: #262320;
  --ink: #fbf4eb;
  --muted: #bdb0a5;
  --rule: #464039;
  --accent: #ff947c;
  --accent-solid: #ee7157;
  --accent-white: #251512;
  --hero: #452b25;
  --hero-ring: #995d4d;
  --card-back: #302924;
  --mint: #233c30;
  --mint-ink: #a5e1c2;
  --lilac: #37304b;
  --lilac-ink: #d4c7f7;
  --rose: #4a3028;
  --red-wash: #422923;
  --shadow: 0 12px 34px #0003;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 300px; background: var(--paper); color: var(--ink); }
h1, h2, h3, p { margin: 0; }
button, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
a { color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
#main:focus, #main h1:focus { outline: none; }
.frame {
  margin: 0 auto;
  width: min(100% - 2 * max(20px, env(safe-area-inset-left), env(safe-area-inset-right)), 1064px);
}
.skip-link { position: fixed; z-index: 5; top: 10px; left: 10px; padding: 12px; background: var(--surface); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }
.topbar { min-height: calc(80px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 11px; font-size: 25px; font-weight: 800; letter-spacing: -.055em; text-decoration: none; }
.brand img { border-radius: 11px; }
.brand-dot { color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.offline { display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid var(--rule); color: var(--muted); border-radius: 100px; font-size: .78rem; font-weight: 650; white-space: nowrap; }
.offline::before { content: ""; width: 7px; height: 7px; flex: none; border-radius: 50%; background: currentColor; }
.offline[data-ready="true"] { color: var(--mint-ink); background: var(--mint); border-color: transparent; }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--rule); border-radius: 14px; background: var(--surface); text-decoration: none; font-family: "Segoe UI Symbol", system-ui, sans-serif; font-size: 23px; line-height: 1; }
.icon-button span { transition: transform .45s var(--ease); }
.icon-button:is(:hover, :focus-visible) span { transform: rotate(42deg); }
.icon-button[aria-current] { background: var(--rose); color: var(--accent); }

#main { min-height: min(600px, calc(100svh - 135px)); padding: 10px 0 calc(52px + env(safe-area-inset-bottom)); }
.hero {
  isolation: isolate;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr minmax(205px, .38fr);
  align-items: center;
  gap: 24px;
  min-height: 282px;
  padding: 38px clamp(24px, 5.3vw, 58px);
  border-radius: 30px;
  background: var(--hero);
  animation: enter .53s var(--ease) both;
}
.hero::before, .hero::after { content: ""; position: absolute; z-index: -1; border: 1px solid var(--hero-ring); pointer-events: none; opacity: .55; }
.hero::before {
  width: 370px; height: 370px; right: -55px; bottom: -222px; border-radius: 44%;
  box-shadow: 0 0 0 17px var(--hero), 0 0 0 18px var(--hero-ring), 0 0 0 37px var(--hero), 0 0 0 38px var(--hero-ring);
  animation: drift 13s ease-in-out infinite alternate;
}
.hero::after { width: 16px; height: 16px; right: 31%; top: 18%; border-radius: 50%; background: var(--hero); }
.hero h1 { font: 400 clamp(2.85rem, 6.1vw, 5.05rem)/.98 var(--serif); letter-spacing: -.066em; }
.hero h1 span { color: var(--accent); }
.hero p { color: var(--muted); font-size: clamp(.96rem, 2vw, 1.08rem); margin-top: 17px; line-height: 1.4; }
.hero-score { z-index: 1; justify-self: end; width: min(100%, 242px); padding: 20px 22px; border: 1px solid var(--hero-ring); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.score-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: .84rem; color: var(--muted); font-weight: 650; }
.score-value { display: block; margin: 7px 0 11px; font: 400 2.8rem/.95 var(--serif); letter-spacing: -.075em; font-variant-numeric: tabular-nums; }
progress { display: block; width: 100%; height: 7px; appearance: none; border: 0; overflow: hidden; border-radius: 100px; color: var(--accent-solid); background: var(--rule); }
progress::-webkit-progress-bar { background: var(--rule); border-radius: 100px; }
progress::-webkit-progress-value { background: var(--accent-solid); border-radius: 100px; transition: width .45s var(--ease); }
progress::-moz-progress-bar { background: var(--accent-solid); border-radius: 100px; }

.modules { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; margin-top: 16px; }
.module { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 16px; min-height: 117px; padding: 18px; border: 1px solid var(--rule); border-radius: 22px; background: var(--surface); text-decoration: none; transition: transform .28s var(--ease), box-shadow .28s var(--ease), border-color .28s var(--ease); animation: enter .55s var(--ease) both; }
.module:nth-child(1) { animation-delay: 65ms; }
.module:nth-child(2) { animation-delay: 115ms; }
.module:nth-child(3) { animation-delay: 165ms; }
.module:active { transform: scale(.98); }
.module-mark { display: grid; place-items: center; width: 53px; height: 53px; border-radius: 15px; background: var(--rose); color: var(--accent); font-family: var(--serif); font-size: 26px; transition: transform .4s var(--ease); }
.module[data-deck="words"] .module-mark { background: var(--mint); color: var(--mint-ink); }
.module[data-deck="game"] .module-mark { background: var(--lilac); color: var(--lilac-ink); }
.module-lines, .module-game { position: relative; display: block; width: 20px; height: 20px; }
.module-lines::before { content: ""; position: absolute; top: 2px; left: 0; width: 20px; height: 2px; border-radius: 5px; background: currentColor; box-shadow: 0 7px currentColor; }
.module-lines::after { content: ""; position: absolute; top: 16px; width: 13px; height: 2px; border-radius: 5px; background: currentColor; }
.module-game::before { content: ""; position: absolute; inset: 4px; border-radius: 2px; transform: rotate(45deg); border: 2px solid currentColor; }
.module-game::after { content: ""; position: absolute; width: 4px; height: 4px; top: 8px; left: 8px; border-radius: 1px; transform: rotate(45deg); background: currentColor; }
.module-name { display: block; font-size: clamp(1.19rem, 2.5vw, 1.57rem); font-weight: 780; letter-spacing: -.045em; }
.module-meta { display: block; margin-top: 4px; color: var(--muted); font-size: .84rem; line-height: 1.25; }
@media (hover: hover) {
  .module:hover { transform: translateY(-4px); border-color: var(--hero-ring); box-shadow: var(--shadow); }
  .module:hover .module-mark { transform: rotate(-8deg) scale(1.07); }
}

.review { width: min(100%, 700px); margin: 37px auto 0; animation: enter .54s 125ms var(--ease) both; }
.review-heading { display: flex; justify-content: space-between; align-items: end; gap: 14px; margin-bottom: 14px; }
.review h2 { font: 400 clamp(2rem, 4vw, 2.65rem)/1.05 var(--serif); letter-spacing: -.055em; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 4px; border: 1px solid var(--rule); border-radius: 13px; background: var(--paper); }
.segmented button { min-height: 40px; border: 1px solid transparent; border-radius: 9px; padding: 4px 11px; background: transparent; color: var(--muted); font-size: .86rem; font-weight: 680; text-align: center; transition: background .22s, color .22s; }
.segmented button[aria-pressed="true"] { border-color: var(--rule); background: var(--surface); color: var(--ink); box-shadow: 0 2px 5px #211a1808; }
.segmented button:focus-visible { position: relative; z-index: 1; }
.segmented .tab-count { margin-left: 3px; font-variant-numeric: tabular-nums; color: var(--muted); }
.empty-review { display: flex; align-items: center; gap: 17px; min-height: 109px; padding: 19px 22px; border: 1px dashed var(--rule); border-radius: 21px; }
.empty-review .empty-icon { flex: none; display: grid; place-items: center; width: 48px; height: 48px; border: 1px solid var(--rule); border-radius: 15px; background: var(--surface); color: var(--accent); }
.stack { width: 16px; height: 19px; border: 1.5px solid currentColor; border-radius: 3px; transform: rotate(-10deg); box-shadow: 4px 2px 0 -1px var(--surface), 5px 3px 0 -1px currentColor; }
.empty-review h3 { font-size: 1rem; font-weight: 750; }
.empty-review p, .section-note { margin-top: 5px; color: var(--muted); font-size: .93rem; line-height: 1.5; }
.review-item {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 19px;
  padding: 8px;
  box-shadow: 0 4px 0 -1px var(--paper), 0 5px 0 -1px var(--rule), 0 9px 0 -3px var(--paper), 0 10px 0 -3px var(--rule);
  animation: page-in .35s var(--ease) both;
}
.review-item .flashcard { --card-min: 235px; scroll-margin-top: max(12px, env(safe-area-inset-top)); }
.review-item .face { padding: clamp(15px, 3vw, 26px); }
.review-item .face-front .card-term { font-size: clamp(1.85rem, 7vw, 3.05rem); }
.review-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.review-action { min-height: 46px; padding: 5px; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: .92rem; font-weight: 700; transition: background .2s, transform .27s var(--ease); }
.review-action:only-child { grid-column: 1 / -1; }
.review-action:not(:disabled):active { transform: scale(.98); }
.review-action:disabled { color: var(--muted); opacity: .6; }
@media (hover: hover) { .review-action:not(:disabled):hover { background: var(--paper); } }
.review-paging { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 8px; color: var(--muted); font-size: .86rem; text-align: center; }

.screen { width: min(100%, 664px); margin: 8px auto 0; animation: enter .46s var(--ease) both; }
.crumb { display: inline-flex; min-height: 44px; align-items: center; gap: 8px; color: var(--muted); font-size: .92rem; font-weight: 690; text-decoration: none; }
.crumb::before { content: ""; width: 8px; height: 8px; border: solid currentColor; border-width: 0 0 1.5px 1.5px; transform: rotate(45deg); margin-left: 3px; }
.screen-header { margin: 11px 0 21px; }
.screen-header h1 { font: 400 clamp(3rem, 9vw, 4.75rem)/1 var(--serif); letter-spacing: -.065em; }
.screen-header .section-note { margin-top: 9px; }
.deck-progress { margin-bottom: 17px; }
.deck-progress .score-top { margin-bottom: 8px; }
.flashcard { --card-min: 324px; display: block; width: 100%; padding: 0; border: 0; border-radius: 23px; background: transparent; color: var(--ink); text-align: left; perspective: 1100px; }
.card-inner { display: grid; min-height: var(--card-min); border-radius: inherit; transform-style: preserve-3d; transition: transform .58s cubic-bezier(.23, .8, .23, 1); }
.flashcard.is-flipped .card-inner { transform: rotateY(180deg); }
.face { grid-area: 1 / 1; display: flex; flex-direction: column; justify-content: space-between; gap: 17px; min-width: 0; padding: clamp(20px, 4vw, 34px); border: 1px solid var(--rule); border-radius: inherit; background: var(--surface); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face-front { transform: translateZ(.5px); }
.face-back { transform: rotateY(180deg) translateZ(.5px); background: var(--card-back); }
.card-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .79rem; font-weight: 700; }
.card-label::after { content: ""; width: 12px; height: 12px; border: 1.5px solid var(--accent); border-radius: 3px; transform: rotate(-13deg); }
[data-deck="words"] .card-label::after { border-color: var(--mint-ink); }
.card-term { display: block; overflow-wrap: anywhere; font: 400 clamp(2.05rem, 8vw, 4rem)/1.06 var(--serif); letter-spacing: -.052em; }
.face-back .card-term { color: var(--muted); font-size: clamp(1.6rem, 5.8vw, 2.5rem); line-height: 1.12; letter-spacing: -.038em; }
.card-answer { display: block; margin-top: 16px; max-width: 58ch; overflow-wrap: anywhere; font: 400 clamp(1.4rem, 5.25vw, 2rem)/1.34 var(--serif); }
.card-tap { color: var(--muted); font-size: .81rem; }
.card-tap::before { content: "↻"; color: var(--accent); font-size: 1.15em; margin-right: 6px; }
.primary, .secondary { min-height: 49px; padding: 8px 18px; border-radius: 13px; font-weight: 730; text-align: center; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; transition: background .2s, transform .27s var(--ease); }
.primary { border: 1px solid transparent; background: var(--accent-solid); color: var(--accent-white); }
.secondary { border: 1px solid var(--rule); background: var(--surface); color: var(--ink); }
.primary:not(:disabled):active, .secondary:not(:disabled):active, .option:not(:disabled):active { transform: scale(.98); }
.primary:disabled { color: var(--muted); background: var(--rule); }
.full-button { width: 100%; margin-top: 13px; }
.panel { padding: clamp(18px, 4.3vw, 30px); border: 1px solid var(--rule); border-radius: 23px; background: var(--surface); }
.panel h2 { font: 400 2rem/1.05 var(--serif); letter-spacing: -.045em; }
.panel p { color: var(--muted); line-height: 1.55; margin-top: 9px; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

.game-mode { margin-bottom: 14px; }
.game-mode button { min-width: 100px; }
.question { animation: enter .35s var(--ease) both; }
.panel .question-context { margin: 20px 0 19px; font: 400 clamp(1.52rem, 5.35vw, 2.4rem)/1.26 var(--serif); letter-spacing: -.029em; overflow-wrap: anywhere; }
.blank { display: inline-block; min-width: 2.5em; color: var(--accent); padding: 0 4px 1px; border-radius: 5px; border-bottom: 2px solid var(--accent); background: var(--rose); text-align: center; }
.options { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.option { display: flex; align-items: center; gap: 9px; min-height: 57px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 12px; background: var(--paper); color: var(--ink); text-align: left; font-weight: 655; transition: background .2s, transform .25s var(--ease); }
.option:not(:disabled):hover { border-color: var(--hero-ring); }
.option span:last-child { overflow-wrap: anywhere; }
.option .option-letter { display: grid; flex: none; place-items: center; width: 25px; height: 25px; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); color: var(--muted); font-size: .76rem; }
.option[data-result="correct"] { background: var(--mint); color: var(--mint-ink); border-color: currentColor; animation: answer-pop .4s var(--ease) both; }
.option[data-result="wrong"] { background: var(--red-wash); color: var(--accent); border-color: currentColor; }
.game-answer { margin-top: 15px; padding: 13px 14px; border-radius: 13px; background: var(--paper); color: var(--ink); animation: enter .28s var(--ease) both; overflow-wrap: anywhere; }
.game-answer p { margin-top: 5px; font-size: .93rem; }
.score-big { display: block; margin: 14px 0; color: var(--accent); font: 400 clamp(3rem, 9vw, 5rem)/1 var(--serif); letter-spacing: -.06em; }

.settings-grid { display: grid; gap: 13px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; }
.setting-row + .setting-row { border-top: 1px solid var(--rule); }
.setting-row:first-of-type { margin-top: 7px; }
.setting-row:last-child { padding-bottom: 0; }
.setting-row label { font-weight: 700; }
.setting-row small { display: block; margin-top: 4px; color: var(--muted); font-size: .8rem; }
.setting-row select { max-width: 56%; min-height: 44px; padding: 6px 8px; border: 1px solid var(--rule); border-radius: 10px; color: var(--ink); background: var(--paper); }
.notice { position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; z-index: 5; width: max-content; max-width: calc(100% - 28px); transform: translateX(-50%); padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--paper); box-shadow: var(--shadow); font-size: .92rem; pointer-events: none; }
.notice:not([hidden]) { animation: notice-in .28s var(--ease) both; }

@keyframes enter { from { opacity: 0; translate: 0 13px; } to { opacity: 1; translate: 0 0; } }
@keyframes drift { from { transform: rotate(-10deg) translate(0,0); } to { transform: rotate(15deg) translate(-13px,-15px); } }
@keyframes answer-pop { 0% { scale: .97; } 55% { scale: 1.023; } 100% { scale: 1; } }
@keyframes notice-in { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
@keyframes page-in { from { opacity: 0; transform: translateX(9px) rotateY(-5deg); } to { opacity: 1; transform: none; } }

@media (max-width: 710px) {
  .topbar { min-height: calc(66px + env(safe-area-inset-top)); }
  #main { padding-top: 5px; }
  .hero { grid-template-columns: 1fr; gap: 17px; padding: 22px; min-height: 0; border-radius: 24px; }
  .hero::before { right: -172px; bottom: -245px; }
  .hero::after { right: 15%; top: 19%; }
  .hero p { margin-top: 10px; }
  .hero-score { justify-self: start; width: min(100%, 305px); padding: 10px 13px; display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; align-items: center; border-radius: 13px; }
  .score-value { margin: 0; font-size: 1.37rem; line-height: 1; }
  .hero-score progress { grid-column: 1 / -1; height: 5px; }
  .modules { gap: 8px; margin-top: 12px; }
  .module { display: block; min-height: 104px; padding: 10px; border-radius: 15px; }
  .module-mark { width: 36px; height: 36px; border-radius: 11px; margin-bottom: 5px; font-size: 21px; }
  .module-meta { font-size: .75rem; }
  .review { margin-top: 26px; }
  .review-heading { align-items: start; flex-direction: column; gap: 10px; }
  .empty-review { padding: 13px; gap: 12px; }
  .empty-review .empty-icon { width: 42px; height: 42px; }
  .flashcard { --card-min: 300px; }
  .screen { margin-top: 0; }
}

@media (max-width: 378px) {
  .frame { width: min(100% - 30px, 1064px); }
  .brand { gap: 7px; font-size: 23px; }
  .brand img { width: 34px; height: 34px; }
  .topbar-actions { gap: 6px; }
  .hero { padding: 18px; }
  .hero h1 { font-size: 2.5rem; }
  .options { grid-template-columns: 1fr; }
}

:root[data-motion="reduced"] *, :root[data-motion="reduced"] *::before, :root[data-motion="reduced"] *::after {
  animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important;
}
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) *, :root:not([data-motion="full"]) *::before, :root:not([data-motion="full"]) *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important;
  }
}
