:root {
  --ink: #17251f;
  --forest: #254938;
  --moss: #638160;
  --paper: #f7f3e9;
  --paper-deep: #ebe3d1;
  --line: #cfc4ae;
  --tomato: #d8523c;
  --sun: #f3b73f;
  --cream: #fffdf7;
  --shadow: 0 18px 50px rgb(33 50 38 / 12%);
  --display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --body: "Trebuchet MS", "Avenir Next", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 12%, rgb(243 183 63 / 22%), transparent 19rem),
    radial-gradient(circle at 92% 24%, rgb(99 129 96 / 15%), transparent 25rem),
    var(--paper);
  font-family: var(--body);
}

button, input, select { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgb(216 82 60 / 55%);
  outline-offset: 3px;
}

.grain {
  position: fixed;
  z-index: -1;
  inset: 0;
  opacity: .3;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.055'/%3E%3C/svg%3E");
}

.app-shell { width: min(1120px, calc(100% - 40px)); margin: 0 auto; padding: 26px 0 76px; }

.site-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 38px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; width: 38px; height: 38px; place-items: center; color: var(--cream); background: var(--forest); border-radius: 50% 45% 50% 42%; font-family: var(--display); font-size: 1.35rem; transform: rotate(-8deg); }
.brand strong, .brand small { display: block; line-height: .9; letter-spacing: .13em; }
.brand strong { font-size: .92rem; }
.brand small { margin-top: 4px; color: var(--moss); font-size: .58rem; font-weight: 700; }
.header-note { display: flex; align-items: center; gap: 8px; margin: 0; color: #496051; font-size: .78rem; font-weight: 700; }
.pulse-dot { width: 8px; height: 8px; background: var(--tomato); border-radius: 50%; box-shadow: 0 0 0 4px rgb(216 82 60 / 13%); }

.hero { position: relative; overflow: hidden; padding: clamp(42px, 7vw, 80px); border-radius: 4px 68px 4px 4px; color: var(--cream); background: var(--forest); box-shadow: var(--shadow); }
.hero::after { position: absolute; right: -5%; bottom: -47%; width: 430px; height: 430px; border: 1px solid rgb(255 253 247 / 22%); border-radius: 50%; content: ""; box-shadow: 0 0 0 50px rgb(255 253 247 / 4%), 0 0 0 100px rgb(255 253 247 / 4%); }
.eyebrow { margin: 0 0 12px; color: var(--tomato); font-size: .69rem; font-weight: 800; letter-spacing: .16em; }
.hero .eyebrow { color: var(--sun); }
h1, h2, p { margin-top: 0; }
h1, h2 { font-family: var(--display); font-weight: 500; }
h1 { position: relative; z-index: 1; max-width: 700px; margin-bottom: 20px; font-size: clamp(2.6rem, 6vw, 5.4rem); line-height: .96; letter-spacing: -.06em; }
h1 em { color: var(--sun); font-style: italic; }
.hero-copy { position: relative; z-index: 1; max-width: 470px; margin-bottom: 34px; color: #dae6d7; font-size: 1.02rem; line-height: 1.65; }
.hero-stats { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 26px; }
.hero-stats div, .hero-saved-words { min-width: 90px; min-height: 44px; padding-left: 14px; border-left: 1px solid rgb(255 253 247 / 30%); }
.hero-saved-words { color: var(--cream); border-top: 0; border-right: 0; border-bottom: 0; background: transparent; text-align: left; transition: color .18s ease; }
.hero-saved-words:hover, .hero-saved-words:hover span { color: var(--sun); }
.hero-stats strong, .hero-stats span { display: block; }
.hero-stats strong { font-family: var(--display); font-size: 2rem; font-weight: 500; }
.hero-stats span { color: #c5d5c2; font-size: .72rem; font-weight: 700; }

.content-section { margin-top: 72px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 25px; }
.section-heading.compact { margin-bottom: 20px; }
.section-heading .eyebrow { margin-bottom: 8px; }
h2 { margin-bottom: 0; font-size: clamp(2rem, 4vw, 3.25rem); line-height: 1; letter-spacing: -.045em; }
.text-button, .hint-button { padding: 6px 0; border: 0; color: var(--forest); background: transparent; font-size: .84rem; font-weight: 800; }
.text-button span, .primary-button span, .next-button span { display: inline-block; margin-left: 5px; font-size: 1.15em; transition: transform .18s ease; }
.text-button:hover span, .primary-button:hover span, .next-button:hover span { transform: translateX(4px); }

.study-scope-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 15px 17px; border: 1px solid #aac1a6; border-radius: 4px 26px 4px 4px; background: linear-gradient(100deg, rgb(225 235 217 / 86%), rgb(255 253 247 / 72%)); }
.study-scope-summary { min-width: 0; }
.study-scope-label { margin: 0 0 5px; color: var(--moss); font-size: .64rem; font-weight: 900; letter-spacing: .14em; }
.study-scope-summary strong { display: block; color: var(--forest); font-family: var(--display); font-size: 1.38rem; font-weight: 500; line-height: 1; }
.study-scope-summary > p:last-child { margin: 6px 0 0; color: var(--moss); font-size: .74rem; font-weight: 700; line-height: 1.4; }
.study-scope-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 9px; }
.shuffle-option { display: inline-flex; align-items: center; gap: 7px; min-height: 42px; padding: 8px 10px; color: var(--forest); border: 1px solid rgb(99 129 96 / 45%); border-radius: 3px; background: rgb(255 253 247 / 60%); cursor: pointer; font-size: .72rem; font-weight: 900; white-space: nowrap; }
.shuffle-option input { width: 16px; height: 16px; margin: 0; accent-color: var(--forest); }
.scope-select-button { min-height: 42px; padding: 8px 11px; color: var(--cream); border: 1px solid var(--forest); border-radius: 3px; background: var(--forest); font-size: .72rem; font-weight: 900; transition: transform .18s ease, background .18s ease; }
.scope-select-button:hover { transform: translateY(-2px); background: #173426; }
.scope-select-button.is-selecting { color: var(--forest); background: var(--sun); }
.study-scope-instruction { margin: 10px 0; padding: 11px 14px; color: #3c5f47; border-left: 3px solid var(--tomato); background: #fff4e9; font-size: .78rem; font-weight: 800; line-height: 1.45; }
.lesson-filter-bar { display: flex; align-items: center; gap: 16px 24px; flex-wrap: wrap; margin: 18px 0 14px; }
.lesson-filter-bar label { display: flex; align-items: center; gap: 10px; max-width: 100%; color: var(--forest); font-size: .8rem; font-weight: 800; }
.lesson-filter-bar select { min-width: 0; max-width: 300px; min-height: 44px; padding: 9px 12px; color: var(--forest); border: 1px solid var(--line); border-radius: 3px; background: var(--cream); }
.lesson-filter-bar p { flex: 1 1 220px; margin: 0; color: var(--moss); font-size: .76rem; line-height: 1.5; }

.lesson-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.lesson-grid.is-empty { display: block; border: 1px solid var(--line); }
.loading { grid-column: 1 / -1; padding: 24px; color: var(--moss); }
.lesson-card { position: relative; min-height: 156px; padding: 17px; overflow: hidden; text-align: left; color: var(--ink); border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: rgb(255 253 247 / 42%); transition: background .2s ease, transform .2s ease; }
.lesson-card:hover, .lesson-card.selected { background: var(--cream); }
.lesson-card:hover { z-index: 1; transform: translateY(-4px); box-shadow: 0 8px 20px rgb(37 73 56 / 12%); }
.lesson-card.selected::before { position: absolute; top: 0; left: 0; width: 100%; height: 4px; content: ""; background: var(--tomato); }
.lesson-card.selected:not(.selection-mode)::after { position: absolute; top: 12px; right: 12px; padding: 4px 6px; color: #fff7e9; border-radius: 999px; background: var(--forest); content: "ĐÃ CHỌN"; font-size: .56rem; font-weight: 900; letter-spacing: .08em; line-height: 1; }
.lesson-card.selection-mode::after { position: absolute; top: 12px; right: 12px; display: grid; width: 24px; height: 24px; place-items: center; color: var(--moss); border: 1px solid var(--line); border-radius: 50%; background: var(--cream); content: "+"; font-size: 1rem; font-weight: 900; line-height: 1; }
.lesson-card.selection-mode.selected::after { color: var(--cream); border-color: var(--forest); background: var(--forest); content: "✓"; }
.lesson-number { display: block; margin-bottom: 7px; color: var(--tomato); font-family: var(--display); font-size: 1.1rem; font-style: italic; }
.lesson-type { display: block; max-width: 100%; margin-bottom: 8px; overflow: hidden; color: var(--moss); font-size: .63rem; font-weight: 800; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.lesson-meta strong, .lesson-meta small { display: block; }
.lesson-meta strong { margin-bottom: 3px; font-size: .88rem; }
.lesson-meta small { color: var(--moss); font-size: .7rem; font-weight: 700; }
.lesson-progress { position: absolute; right: 17px; bottom: 18px; left: 17px; height: 4px; overflow: hidden; background: var(--paper-deep); }
.lesson-progress i { display: block; height: 100%; background: var(--forest); }
.lesson-heading-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 10px 18px; }
.lesson-card.imported-lesson { background: #eef1e3; }
.lesson-card.imported-lesson.selected { background: #e0e9d6; }
.lesson-card.imported-lesson .lesson-number { padding-right: 30px; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
.import-csv-status { color: var(--forest); font-size: .85rem; line-height: 1.5; }
.import-csv-status:empty, .import-csv-error:empty, #import-csv-file-status:empty { display: none; }
.import-csv-dialog { width: min(780px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: 0; overflow: auto; overscroll-behavior: contain; color: var(--ink); border: 1px solid var(--line); border-radius: 5px 36px 5px 5px; background: var(--cream); box-shadow: var(--shadow); }
.import-csv-dialog::backdrop { background: rgb(18 35 27 / 65%); backdrop-filter: blur(3px); }
.import-csv-topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 22px 26px; border-bottom: 1px solid var(--line); }
.import-csv-topbar .eyebrow { margin-bottom: 7px; }
.import-csv-topbar h2 { font-size: clamp(1.5rem, 5vw, 2rem); }
.import-csv-topbar .close-button { flex-shrink: 0; }
.import-csv-form { display: grid; gap: 17px; padding: 24px 26px; }
.import-csv-help { margin: 0; color: var(--moss); font-size: .8rem; line-height: 1.6; overflow-wrap: anywhere; }
.import-csv-example { max-width: 100%; margin: 0; padding: 13px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--forest); border-left: 3px solid var(--tomato); background: var(--paper); font-size: .78rem; line-height: 1.6; }
.import-csv-field { display: grid; min-width: 0; gap: 8px; color: var(--forest); font-size: .84rem; font-weight: 800; }
.import-csv-field[hidden] { display: none; }
.import-csv-field input, .import-csv-field select { width: 100%; min-width: 0; min-height: 46px; padding: 10px 12px; color: var(--ink); border: 1px solid var(--line); border-radius: 3px; background: var(--paper); }
.import-csv-field input[type="file"] { font-size: .8rem; }
.import-csv-field input::file-selector-button { margin-right: 10px; padding: 7px 10px; color: var(--cream); border: 0; border-radius: 3px; background: var(--forest); cursor: pointer; }
.import-csv-count { margin: 0 0 10px; color: var(--forest); font-size: .8rem; font-weight: 800; }
#import-csv-preview { min-width: 0; }
.import-csv-table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); }
.import-csv-table { width: 100%; min-width: 510px; border-collapse: collapse; font-size: .76rem; text-align: left; }
.import-csv-table th, .import-csv-table td { max-width: 220px; padding: 10px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; vertical-align: top; }
.import-csv-table th { color: var(--forest); background: var(--paper-deep); }
.import-csv-table tr:last-child td { border-bottom: 0; }
.import-csv-error { margin: 0; padding: 12px; color: #913523; border-left: 3px solid var(--tomato); background: #f7dfd5; font-size: .84rem; line-height: 1.5; }
.import-csv-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 12px; }
#open-csv-import:disabled, #import-csv-submit:disabled { cursor: not-allowed; opacity: .48; transform: none; }

.flashcard-bar { display: flex; align-items: center; justify-content: space-between; gap: 30px; margin-top: 20px; padding: 25px 27px; border: 1px solid #aac1a6; border-radius: 4px 34px 4px 4px; background: linear-gradient(110deg, #e1ebd9, #f4efde); }
.flashcard-intro { display: flex; align-items: center; gap: 16px; }
.flashcard-stamp { display: grid; flex: 0 0 52px; width: 52px; height: 52px; place-items: center; color: var(--cream); background: var(--forest); border-radius: 50% 50% 44% 50%; font-family: var(--display); font-size: 1.55rem; transform: rotate(-7deg); }
.flashcard-intro .eyebrow { margin-bottom: 5px; }
.flashcard-intro h2 { font-size: 1.65rem; }
.flashcard-intro h2 span { color: var(--tomato); font-style: italic; }
.flashcard-intro p:last-child { max-width: 550px; margin: 8px 0 0; color: var(--moss); font-size: .8rem; font-weight: 700; line-height: 1.45; }
.flashcard-start { flex: 0 0 auto; min-height: 50px; padding: 12px 17px; color: var(--cream); border: 0; border-radius: 3px; background: var(--forest); box-shadow: 0 4px 0 #173426; font-weight: 800; transition: transform .18s ease, box-shadow .18s ease; }
.flashcard-start:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #173426; }
.flashcard-start span { display: inline-block; margin-left: 5px; transition: transform .18s ease; }
.flashcard-start:hover span { transform: translateX(4px); }

.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; }
.mode-card { display: flex; align-items: center; gap: 13px; padding: 19px; text-align: left; color: var(--ink); border: 1px solid var(--line); border-radius: 4px; background: rgb(255 253 247 / 46%); transition: border .2s ease, background .2s ease, transform .2s ease; }
.mode-card:hover { transform: translateY(-2px); border-color: var(--moss); }
.mode-card.active { color: var(--cream); border-color: var(--forest); background: var(--forest); }
.mode-icon { display: grid; flex: 0 0 47px; width: 47px; height: 47px; place-items: center; font-family: var(--display); font-size: 1.7rem; border-radius: 50%; background: var(--paper-deep); }
.mode-card.active .mode-icon { color: var(--forest); background: var(--sun); }
.mode-icon.hanviet { font-family: var(--body); font-size: .83rem; font-weight: 900; }
.mode-content { min-width: 0; }
.mode-content strong, .mode-content small { display: block; }
.mode-content strong { margin-bottom: 4px; font-size: .92rem; }
.mode-content small { color: var(--moss); font-size: .69rem; font-weight: 700; line-height: 1.35; }
.mode-card.active .mode-content small { color: #c5d5c2; }
.mode-arrow { margin-left: auto; color: var(--tomato); font-size: 1.1rem; }
.mode-card.active .mode-arrow { color: var(--sun); }

.hanviet-granularity { min-width: 0; margin: 13px 0 0; padding: 14px 16px 16px; border: 1px solid #aac1a6; border-radius: 4px 24px 4px 4px; background: linear-gradient(100deg, rgb(225 235 217 / 78%), rgb(255 253 247 / 58%)); }
.hanviet-granularity legend { padding: 0 6px; color: var(--forest); font-size: .65rem; font-weight: 900; letter-spacing: .14em; }
.hanviet-granularity > p { margin: 0 0 12px; color: var(--moss); font-size: .78rem; font-weight: 700; line-height: 1.45; }
.hanviet-granularity-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.hanviet-granularity-option { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 10px 12px; color: var(--forest); border: 1px solid rgb(99 129 96 / 45%); border-radius: 3px; background: rgb(255 253 247 / 62%); cursor: pointer; transition: border-color .18s ease, background .18s ease, transform .18s ease; }
.hanviet-granularity-option:hover { border-color: var(--forest); transform: translateY(-1px); }
.hanviet-granularity-option.active { border-color: var(--forest); background: var(--forest); color: var(--cream); }
.hanviet-granularity-option input { flex: 0 0 auto; width: 17px; height: 17px; margin: 0; accent-color: var(--sun); }
.hanviet-granularity-option span { min-width: 0; }
.hanviet-granularity-option strong, .hanviet-granularity-option small { display: block; }
.hanviet-granularity-option strong { font-size: .78rem; }
.hanviet-granularity-option small { margin-top: 3px; color: var(--moss); font-size: .66rem; font-weight: 800; }
.hanviet-granularity-option.active small { color: #c5d5c2; }
.hanviet-granularity-option:has(input:disabled) { cursor: not-allowed; opacity: .52; transform: none; }

.practice-bar { display: flex; align-items: center; justify-content: space-between; gap: 22px; margin-top: 13px; padding: 18px 21px; border-radius: 3px; background: var(--paper-deep); }
.practice-bar p { margin: 0; font-size: .83rem; font-weight: 700; line-height: 1.5; }
.muted { color: var(--moss); }
.practice-actions { display: flex; align-items: center; gap: 16px; }
.question-count { display: flex; align-items: center; gap: 6px; color: var(--moss); font-size: .69rem; font-weight: 800; text-transform: uppercase; }
.question-count select { padding: 6px 19px 6px 7px; color: var(--ink); border: 0; border-bottom: 1px solid var(--moss); background: transparent; font-size: .78rem; font-weight: 700; }
.primary-button, .secondary-button, .next-button { border: 0; border-radius: 3px; font-weight: 800; }
.primary-button { padding: 12px 17px; color: var(--cream); background: var(--tomato); box-shadow: 0 4px 0 #af3626; transition: transform .18s ease, box-shadow .18s ease; }
.primary-button:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #af3626; }
.primary-button:active { transform: translateY(2px); box-shadow: 0 2px 0 #af3626; }

.practice-dialog { width: min(860px, calc(100% - 28px)); min-height: min(640px, calc(100dvh - 28px)); padding: 0; overflow: hidden; color: var(--ink); border: 0; border-radius: 5px 52px 5px 5px; background: var(--cream); box-shadow: 0 28px 100px rgb(11 26 18 / 45%); }
.practice-dialog::backdrop { background: rgb(18 35 27 / 65%); backdrop-filter: blur(3px); }
.dialog-topbar { display: grid; grid-template-columns: 80px 1fr 80px; align-items: center; min-height: 75px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.close-button { width: 35px; height: 35px; color: var(--forest); border: 1px solid var(--line); border-radius: 50%; background: transparent; font-size: 1.5rem; line-height: 1; }
.progress-group { text-align: center; }
.progress-group > span { color: var(--moss); font-size: .72rem; font-weight: 800; }
.progress-track { width: min(300px, 100%); height: 5px; margin: 7px auto 0; overflow: hidden; background: var(--paper-deep); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--tomato); transition: width .28s ease; }
.score-chip { justify-self: end; color: var(--forest); font-size: .72rem; font-weight: 800; }
.score-chip #score-value { font-family: var(--display); font-size: 1.35rem; }
.quiz-panel, .result-panel { padding: clamp(34px, 8vw, 76px); text-align: center; }
.quiz-mode { margin-bottom: 31px; color: var(--tomato); font-size: .69rem; font-weight: 900; letter-spacing: .16em; }
.prompt-label { margin-bottom: 12px; color: var(--moss); font-size: .69rem; font-weight: 800; letter-spacing: .13em; }
.question-display { max-width: 620px; min-height: 60px; margin: 0 auto; font-size: clamp(2.5rem, 7vw, 5.4rem); line-height: 1.05; letter-spacing: -.055em; }
.question-support { min-height: 24px; margin: 13px auto 30px; color: var(--moss); font-size: .9rem; }
#answer-form { display: flex; max-width: 560px; margin: 0 auto; gap: 10px; }
#answer-input { min-width: 0; flex: 1; padding: 14px 15px; color: var(--ink); border: 1px solid var(--line); border-radius: 3px; background: #fffefa; font-size: 1.1rem; }
#answer-input::placeholder { color: #9c9a90; }
.kanji-builder { max-width: 560px; margin: 0 auto; }
.kanji-answer { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 7px; min-height: 66px; padding: 11px; border: 1px dashed var(--moss); border-radius: 4px; background: #fffefa; }
.kanji-answer:empty::before { color: #9c9a90; content: "Chạm chữ bên dưới để ghép đáp án"; font-size: .83rem; font-weight: 700; }
.kanji-answer-token, .kanji-choice { display: grid; min-width: 45px; min-height: 45px; place-items: center; padding: 5px 9px; border-radius: 3px; font-family: var(--display); font-size: 1.46rem; line-height: 1; }
.kanji-answer-token { color: var(--forest); border: 1px solid #aac1a6; background: #e1ebd9; }
.kanji-builder-help { margin: 13px 0 10px; color: var(--moss); font-size: .75rem; font-weight: 700; }
.kanji-choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(48px, 1fr)); gap: 9px; }
.kanji-choice { color: var(--ink); border: 1px solid var(--line); background: var(--paper-deep); transition: transform .15s ease, background .15s ease; }
.kanji-choice:hover { border-color: var(--forest); transform: translateY(-2px); }
.kanji-choice:disabled { opacity: .28; transform: none; cursor: default; }
.kanji-builder-actions { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }
.kanji-builder-actions .secondary-button { min-height: 46px; }
.kanji-builder-actions .primary-button:disabled { cursor: not-allowed; opacity: .48; transform: none; box-shadow: 0 2px 0 #af3626; }
.hint-button { margin-top: 20px; color: var(--moss); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 4px; }
.quiz-utilities { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 20px; }
.quiz-utilities .hint-button { margin-top: 0; }
.flag-toggle-button { min-height: 42px; padding: 8px 12px; color: var(--forest); border: 1px dashed var(--moss); border-radius: 3px; background: transparent; font-size: .75rem; font-weight: 900; transition: color .18s ease, border-color .18s ease, background .18s ease; }
.flag-toggle-button:hover { border-color: var(--tomato); background: #fff4eb; }
.flag-toggle-button.is-flagged { color: #913523; border-color: #d68e77; border-style: solid; background: #f7dfd5; }
.flag-toggle-button:disabled { cursor: not-allowed; opacity: .45; }
.feedback { max-width: 560px; margin: 20px auto 0; padding: 16px; border-radius: 3px; background: var(--paper-deep); }
.feedback.correct { background: #dfead9; }
.feedback.incorrect { background: #f8ded5; }
.feedback-title { margin-bottom: 5px; font-size: .88rem; font-weight: 900; }
.feedback.correct .feedback-title { color: #2f6a3d; }
.feedback.incorrect .feedback-title { color: #9b3d2c; }
.feedback p { margin-bottom: 13px; font-size: .85rem; }
.next-button { padding: 9px 12px; color: var(--cream); background: var(--forest); }
.result-panel { padding-top: clamp(52px, 11vw, 104px); }
.result-number { margin-bottom: 8px; color: var(--tomato); font-family: var(--display); font-size: clamp(4rem, 13vw, 7rem); line-height: .9; }
.result-number span + span { color: var(--moss); }
.result-panel h2 { margin-bottom: 12px; }
.result-panel > p:not(.eyebrow):not(.result-number) { max-width: 460px; margin: 0 auto 24px; color: var(--moss); line-height: 1.55; }
.review-list { display: grid; max-width: 530px; margin: 10px auto 28px; text-align: left; }
.review-item { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .82rem; }
.review-item strong { color: var(--tomato); }
.result-actions { display: flex; justify-content: center; gap: 12px; }
.secondary-button { padding: 12px 15px; color: var(--forest); border: 1px solid var(--moss); background: transparent; }

.flashcard-dialog { width: min(720px, calc(100% - 28px)); min-height: min(700px, calc(100dvh - 28px)); padding: 0; overflow: hidden; color: var(--ink); border: 0; border-radius: 5px 52px 5px 5px; background: var(--cream); box-shadow: 0 28px 100px rgb(11 26 18 / 45%); }
.flashcard-dialog::backdrop { background: rgb(18 35 27 / 65%); backdrop-filter: blur(3px); }
.flashcard-topbar { display: grid; grid-template-columns: 80px 1fr 80px; align-items: center; min-height: 75px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.shuffle-button { justify-self: end; min-height: 38px; padding: 7px 8px; color: var(--forest); border: 1px solid var(--line); border-radius: 3px; background: transparent; font-size: .73rem; font-weight: 800; }
.shuffle-button:hover { border-color: var(--moss); background: var(--paper-deep); }
.flashcard-panel, .flashcard-result { padding: clamp(31px, 6vw, 52px); text-align: center; }
.flashcard-panel .quiz-mode { margin-bottom: 20px; }
.flashcard-scene { display: block; width: min(510px, 100%); min-height: clamp(290px, 45dvh, 410px); padding: 0; margin: 0 auto; perspective: 1200px; touch-action: pan-y; text-align: left; border: 0; background: transparent; }
.flashcard-card { position: relative; display: block; width: 100%; height: 100%; min-height: inherit; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2, .75, .25, 1); }
.flashcard-card.is-flipped { transform: rotateY(180deg); }
.flashcard-face { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 42px; overflow: hidden; border-radius: 5px 42px 5px 5px; backface-visibility: hidden; box-shadow: 0 16px 35px rgb(20 38 28 / 16%); }
.flashcard-front { color: var(--cream); background: linear-gradient(145deg, #315b45, #1e392c); }
.flashcard-front::after { position: absolute; right: -50px; bottom: -75px; width: 210px; height: 210px; border: 1px solid rgb(255 253 247 / 16%); border-radius: 50%; content: ""; box-shadow: 0 0 0 35px rgb(255 253 247 / 4%); }
.flashcard-back { background: var(--paper-deep); transform: rotateY(180deg); }
.card-corner { position: absolute; top: 20px; left: 22px; color: var(--sun); font-size: .63rem; font-weight: 900; letter-spacing: .14em; }
.flashcard-back .card-corner { color: var(--tomato); }
.flashcard-primary, .flashcard-meaning { position: relative; z-index: 1; max-width: 100%; overflow-wrap: anywhere; font-family: var(--display); font-size: clamp(4rem, 12vw, 7rem); font-weight: 500; line-height: .95; letter-spacing: -.055em; text-align: center; }
.flashcard-meaning { font-size: clamp(2.25rem, 7vw, 4rem); }
.flashcard-reading { position: relative; z-index: 1; margin-top: 17px; color: #d2e1d0; font-size: 1.1rem; font-weight: 700; }
.flashcard-prompt { position: absolute; bottom: 23px; color: #bcd0ba; font-size: .72rem; font-weight: 800; }
.flashcard-detail { max-width: 100%; margin-top: 18px; color: var(--moss); font-size: .94rem; font-weight: 700; text-align: center; overflow-wrap: anywhere; }
.hanviet-badge { margin-top: 13px; padding: 7px 10px; color: #884130; border: 1px solid #dcac91; border-radius: 999px; background: #f7dfcf; font-size: .7rem; font-weight: 900; letter-spacing: .04em; }
.flashcard-help { margin: 17px 0; color: var(--moss); font-size: .72rem; font-weight: 700; }
.flashcard-actions { display: grid; grid-template-columns: 58px 1fr 1fr; width: min(510px, 100%); margin: 0 auto; gap: 9px; }
.flashcard-actions button { min-height: 52px; border-radius: 3px; font-weight: 900; }
.flashcard-flag { display: block; width: min(510px, 100%); min-height: 44px; margin: 10px auto 0; }
.flashcard-previous { color: var(--forest); border: 1px solid var(--line); background: var(--cream); font-size: 1.2rem; }
.flashcard-previous:disabled { opacity: .38; cursor: not-allowed; }
.flashcard-review { color: #913523; border: 1px solid #e6b09e; background: #f7dfd5; }
.flashcard-known { color: var(--cream); border: 1px solid var(--forest); background: var(--forest); }
.flashcard-result { padding-top: clamp(76px, 13vw, 112px); }
.flashcard-result-number { margin-bottom: 7px; color: var(--forest); font-family: var(--display); font-size: clamp(4rem, 12vw, 6.2rem); line-height: .9; }
.flashcard-result-number span + span { color: var(--moss); }
.flashcard-result h2 { margin-bottom: 13px; }
.flashcard-result > p:not(.eyebrow):not(.flashcard-result-number) { max-width: 430px; margin: 0 auto 27px; color: var(--moss); line-height: 1.55; }
.flashcard-result-actions { display: flex; justify-content: center; gap: 12px; }

.flagged-words-dialog { width: min(700px, calc(100% - 28px)); min-height: min(560px, calc(100dvh - 28px)); max-height: calc(100dvh - 28px); padding: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; color: var(--ink); border: 0; border-radius: 5px 52px 5px 5px; background: var(--cream); box-shadow: 0 28px 100px rgb(11 26 18 / 45%); }
.flagged-words-dialog::backdrop { background: rgb(18 35 27 / 65%); backdrop-filter: blur(3px); }
.flagged-words-topbar { position: sticky; z-index: 2; top: 0; display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; align-items: center; gap: 14px; min-height: 92px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--cream); }
.flagged-words-topbar .eyebrow { margin-bottom: 5px; }
.flagged-words-topbar h2 { font-size: 1.7rem; }
.flagged-words-total { justify-self: end; padding: 7px 9px; color: #884130; border: 1px solid #dcac91; border-radius: 999px; background: #f7dfcf; font-size: .7rem; font-weight: 900; white-space: nowrap; }
.flagged-words-panel { padding: clamp(25px, 5vw, 42px); }
.flagged-words-copy { margin-bottom: 18px; color: var(--moss); font-size: .86rem; font-weight: 700; line-height: 1.5; }
.flagged-words-list { max-height: min(390px, calc(100dvh - 340px)); overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; }
.flagged-words-empty { margin: 0; padding: 24px 18px; color: var(--moss); border: 1px dashed var(--line); border-radius: 3px; text-align: center; font-size: .84rem; font-weight: 700; line-height: 1.5; }
.flagged-word-items { display: grid; gap: 8px; padding: 0; margin: 0; list-style: none; }
.flagged-word-item { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 3px; background: #fffefa; }
.flagged-word-content { min-width: 0; }
.flagged-word-japanese, .flagged-word-reading, .flagged-word-meaning { display: block; overflow-wrap: anywhere; }
.flagged-word-japanese { color: var(--forest); font-family: var(--display); font-size: 1.4rem; line-height: 1; }
.flagged-word-reading { margin-top: 4px; color: var(--moss); font-size: .76rem; font-weight: 800; }
.flagged-word-meaning { margin-top: 5px; font-size: .78rem; font-weight: 700; }
.flagged-word-actions { display: grid; justify-items: end; gap: 8px; flex: 0 0 auto; }
.flagged-word-lesson { color: var(--moss); font-size: .67rem; font-weight: 900; text-transform: uppercase; }
.flagged-word-remove { min-height: 34px; padding: 6px 9px; color: #913523; border: 1px solid #e6b09e; border-radius: 3px; background: #f7dfd5; font-size: .7rem; font-weight: 900; }
#start-flagged-flashcards { display: block; margin: 24px auto 0; }
#start-flagged-flashcards:disabled { cursor: not-allowed; opacity: .48; transform: none; box-shadow: 0 2px 0 #af3626; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (hover: none) {
  .lesson-card:hover, .mode-card:hover, .primary-button:hover, .flashcard-start:hover { transform: none; }
  .lesson-card:hover { box-shadow: none; }
}

@media (max-width: 760px) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .app-shell { width: min(100% - 28px, 1120px); padding: max(16px, env(safe-area-inset-top)) 0 calc(88px + env(safe-area-inset-bottom)); }
  .site-header { padding-bottom: 28px; }
  .header-note { max-width: 170px; text-align: right; line-height: 1.35; }
  .brand, .text-button { min-height: 44px; }
  .hero { padding: 42px 28px; border-radius: 3px 42px 3px 3px; }
  .hero-copy { margin-bottom: 29px; }
  .hero-stats { gap: 15px; }
  .hero-stats div, .hero-saved-words { min-width: 82px; padding-left: 10px; }
  .content-section { margin-top: 52px; }
  .section-heading { align-items: flex-start; }
  .section-heading .text-button { padding-top: 7px; white-space: nowrap; }
  .lesson-section > .section-heading { flex-wrap: wrap; gap: 18px; }
  .lesson-heading-actions { justify-content: flex-start; }
  .import-csv-topbar { padding: 20px 16px; }
  .import-csv-form { padding: 20px 16px; }
  .import-csv-actions .primary-button { flex: 1; }
  .study-scope-toolbar { display: block; padding: 16px; }
  .study-scope-actions { justify-content: flex-start; margin-top: 14px; }
  .shuffle-option, .scope-select-button { min-height: 44px; }
  .study-scope-instruction { margin: 8px 0; }
  .lesson-filter-bar { display: block; }
  .lesson-filter-bar label { display: grid; grid-template-columns: auto minmax(0, 1fr); }
  .lesson-filter-bar select { width: 100%; max-width: none; }
  .lesson-filter-bar p { margin-top: 9px; }
  .lesson-grid {
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-template-rows: repeat(2, 142px);
    grid-auto-columns: minmax(118px, 29vw);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 8px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }
  .lesson-card { min-height: 142px; padding: 14px; scroll-snap-align: start; }
  .lesson-card.selection-mode::after { top: 9px; right: 9px; }
  .lesson-number { margin-bottom: 6px; }
  .lesson-type { margin-bottom: 6px; }
  .lesson-progress { right: 14px; bottom: 14px; left: 14px; }
  .flashcard-bar { display: block; margin-top: 15px; padding: 20px; }
  .flashcard-intro { align-items: flex-start; }
  .flashcard-start { width: 100%; margin-top: 16px; }
  .mode-grid { grid-template-columns: 1fr; gap: 9px; }
  .mode-card { min-height: 76px; padding: 14px 16px; }
  .mode-icon { flex-basis: 46px; width: 46px; height: 46px; }
  .hanviet-granularity { padding: 14px; }
  .hanviet-granularity-option { min-height: 62px; }
  .practice-bar { padding: 18px; border: 1px solid rgb(99 129 96 / 23%); }
  .practice-actions { display: grid; grid-template-columns: minmax(96px, .72fr) 1.28fr; align-items: stretch; gap: 10px; margin-top: 16px; }
  .question-count { justify-content: space-between; min-height: 50px; padding: 0 10px; border: 1px solid var(--line); background: rgb(255 253 247 / 56%); }
  .question-count select { min-height: 36px; padding-right: 2px; border-bottom: 0; }
  .primary-button, .secondary-button, .next-button { min-height: 50px; }
  .practice-actions .primary-button { width: 100%; }
  .practice-dialog { max-height: calc(100dvh - 18px); overflow-y: auto; overscroll-behavior: contain; }
  .dialog-topbar { position: sticky; z-index: 2; top: 0; grid-template-columns: 52px 1fr 58px; min-height: 68px; padding: 0 14px; background: var(--cream); }
  .close-button { width: 44px; height: 44px; }
  .score-chip { font-size: .68rem; }
  .quiz-panel, .result-panel { padding: 42px 24px; }
  .quiz-mode { margin-bottom: 26px; }
  .question-display { min-height: 0; font-size: clamp(2.35rem, 12vw, 4.1rem); overflow-wrap: anywhere; }
  .question-support { margin-bottom: 28px; line-height: 1.5; }
  #answer-form { display: block; }
  #answer-input, #check-button { width: 100%; }
  #answer-input { min-height: 54px; font-size: 16px; }
  #check-button { margin-top: 12px; }
  .kanji-answer { min-height: 64px; }
  .kanji-answer-token, .kanji-choice { min-width: 48px; min-height: 48px; font-size: 1.48rem; }
  .kanji-builder-actions { display: grid; grid-template-columns: .72fr 1.28fr; }
  .kanji-builder-actions .secondary-button, .kanji-builder-actions .primary-button { width: 100%; }
  .hint-button { min-height: 44px; margin-top: 14px; }
  .quiz-utilities { gap: 14px; margin-top: 14px; }
  .quiz-utilities .hint-button { margin-top: 0; }
  .flag-toggle-button { min-height: 44px; }
  .feedback { margin-top: 16px; padding: 16px; }
  .next-button { width: 100%; margin-top: 2px; }
  .result-actions { display: grid; width: 100%; }
  .result-actions .secondary-button, .result-actions .primary-button { width: 100%; }
  .flashcard-dialog { max-height: calc(100dvh - 18px); overflow-y: auto; overscroll-behavior: contain; }
  .flashcard-topbar { position: sticky; z-index: 2; top: 0; grid-template-columns: 52px 1fr 66px; min-height: 68px; padding: 0 14px; background: var(--cream); }
  .shuffle-button { min-width: 52px; min-height: 44px; }
  .shuffle-button span { display: none; }
  .flashcard-panel, .flashcard-result { padding: 34px 24px; }
  .flashcard-scene { min-height: min(390px, 49dvh); }
  .flashcard-face { padding: 34px 22px; }
  .flashcard-actions button { min-height: 54px; }
  .flashcard-result-actions { display: grid; width: 100%; }
  .flashcard-result-actions .secondary-button, .flashcard-result-actions .primary-button { width: 100%; }
  .flagged-words-dialog { max-height: calc(100dvh - 18px); overflow-y: auto; overscroll-behavior: contain; }
  .flagged-words-topbar { position: sticky; z-index: 2; top: 0; grid-template-columns: 44px minmax(0, 1fr) auto; min-height: 76px; padding: 12px 14px; background: var(--cream); }
  .flagged-words-panel { padding: 28px 24px; }
  .flagged-words-list { max-height: min(400px, calc(100dvh - 255px)); }
  #start-flagged-flashcards { width: 100%; }
}

@media (max-width: 600px) {
  .practice-dialog { width: 100%; min-height: 100dvh; height: 100dvh; max-height: 100dvh; margin: 0; overflow-y: auto; overscroll-behavior: contain; border-radius: 0; }
  .dialog-topbar { min-height: calc(68px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
  .quiz-panel, .result-panel { min-height: calc(100dvh - 68px - env(safe-area-inset-top)); padding-bottom: calc(36px + env(safe-area-inset-bottom)); }
  .flashcard-dialog { width: 100%; min-height: 100dvh; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .flashcard-topbar { min-height: calc(68px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
  .flashcard-panel, .flashcard-result { min-height: calc(100dvh - 68px - env(safe-area-inset-top)); padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .flagged-words-dialog { width: 100%; min-height: 100dvh; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .flagged-words-topbar { min-height: calc(76px + env(safe-area-inset-top)); padding-top: calc(12px + env(safe-area-inset-top)); }
  .flagged-words-panel { min-height: calc(100dvh - 76px - env(safe-area-inset-top)); padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
  .flagged-words-list { max-height: calc(100dvh - 260px - env(safe-area-inset-top)); }
}

@media (max-width: 430px) {
  .header-note { display: none; }
  .hero { padding: 36px 23px; }
  .hero-stats { gap: 11px; }
  .hero-stats strong { font-size: 1.72rem; }
  .hero-stats span { font-size: .65rem; }
  .lesson-grid { grid-auto-columns: minmax(108px, 39vw); grid-template-rows: repeat(2, 142px); }
  .lesson-card { min-height: 142px; }
  .practice-bar { margin-inline: -2px; padding: 15px; }
  .flashcard-bar { margin-inline: -2px; padding: 17px; }
  .flashcard-stamp { flex-basis: 44px; width: 44px; height: 44px; }
  .flashcard-intro h2 { font-size: 1.45rem; }
  .flashcard-intro p:last-child { font-size: .74rem; }
  .hanviet-granularity-options { grid-template-columns: 1fr; }
  .practice-actions { grid-template-columns: 1fr; }
  .study-scope-actions { display: grid; grid-template-columns: 1fr; }
  .shuffle-option, .scope-select-button { justify-content: center; width: 100%; }
  .question-count { min-height: 46px; }
  .question-count select { flex: 1; text-align: right; }
  .quiz-utilities { display: grid; gap: 8px; }
  .quiz-utilities .flag-toggle-button, .quiz-utilities .hint-button { width: 100%; }
  .kanji-choice-grid { gap: 7px; }
  .kanji-answer-token, .kanji-choice { min-width: 45px; min-height: 45px; }
  .quiz-panel, .result-panel { padding-right: 19px; padding-left: 19px; }
  .review-item { align-items: flex-start; font-size: .78rem; }
  .review-item strong { max-width: 48%; text-align: right; overflow-wrap: anywhere; }
  .flashcard-panel, .flashcard-result { padding-right: 18px; padding-left: 18px; }
  .flashcard-scene { min-height: min(355px, 47dvh); }
  .flashcard-primary { font-size: clamp(3.6rem, 20vw, 5.2rem); }
  .flashcard-help { margin: 13px 0; }
  .flagged-word-item { align-items: flex-start; gap: 12px; }
  .flagged-word-actions { gap: 7px; }
}

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