:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --paper-deep: #ece9df;
  --ink: #182236;
  --ink-soft: #596173;
  --line: #d8d5cc;
  --white: #fffefa;
  --red: #bd3a33;
  --red-dark: #922a26;
  --red-soft: #f5e5e2;
  --blue: #294f78;
  --blue-soft: #e8eff6;
  --green: #27745b;
  --green-soft: #e4f3ed;
  --amber: #9a6414;
  --shadow: 0 18px 50px rgba(24, 34, 54, 0.09);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;
  --max: 1180px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible { outline: 3px solid rgba(41, 79, 120, .36); outline-offset: 3px; }
.skip-link { position: fixed; z-index: 99; left: 1rem; top: -5rem; background: var(--ink); color: white; padding: .8rem 1rem; border-radius: 0 0 10px 10px; }
.skip-link:focus { top: 0; }
.topbar { height: 78px; max-width: var(--max); margin: 0 auto; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 11px; border: 0; background: transparent; font-weight: 760; font-size: 1.1rem; cursor: pointer; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: white; background: var(--red); font-family: "Noto Serif JP", "Yu Mincho", serif; font-size: 1.32rem; box-shadow: 0 5px 12px rgba(189, 58, 51, .22); }
.top-actions { display: flex; align-items: center; gap: 6px; }
.nav-button, .icon-button, .text-button { border: 0; background: transparent; cursor: pointer; }
.nav-button { padding: .6rem .8rem; border-radius: 9px; color: var(--ink-soft); font-weight: 630; }
.nav-button:hover, .nav-button[aria-current="page"] { color: var(--ink); background: rgba(24,34,54,.06); }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--ink-soft); font-size: 1.18rem; }
.icon-button:hover { background: rgba(24,34,54,.07); color: var(--ink); }
.page { max-width: var(--max); margin: 0 auto; padding: 35px 24px 64px; }
.page-head { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 24px; margin: 0 0 30px; }
.eyebrow { margin: 0 0 8px; color: var(--red); font-size: .78rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(2rem, 4vw, 3.45rem); line-height: 1.04; letter-spacing: -.045em; max-width: 700px; }
h2 { margin-bottom: 8px; font-size: clamp(1.45rem, 2.5vw, 2rem); line-height: 1.14; letter-spacing: -.025em; }
h3 { margin-bottom: 7px; font-size: 1.18rem; }
.lead { color: var(--ink-soft); font-size: 1.05rem; line-height: 1.6; max-width: 630px; margin-bottom: 0; }
.daily-summary { min-width: 230px; display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: rgba(255,254,250,.65); }
.summary-ring { --value: 0deg; width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--red) var(--value), var(--paper-deep) 0); position: relative; font-weight: 800; font-size: .82rem; }
.summary-ring::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--white); }
.summary-ring span { position: relative; }
.daily-summary strong, .daily-summary small { display: block; }
.daily-summary small { color: var(--ink-soft); margin-top: 3px; }
.goal-panel { display: grid; grid-template-columns: minmax(210px, .85fr) 2fr; gap: 24px; align-items: center; margin: 0 0 22px; padding: 22px 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: rgba(255,254,250,.7); }
.goal-copy .eyebrow { margin-bottom: 6px; }
.goal-copy h2 { margin-bottom: 5px; font-size: 1.35rem; }
.goal-copy p:last-child { margin: 0; color: var(--ink-soft); font-size: .9rem; line-height: 1.5; }
.goal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.goal-item { min-height: 102px; display: flex; flex-direction: column; justify-content: center; padding: 15px; border-radius: 13px; background: var(--paper); }
.goal-item strong, .goal-item span { display: block; }
.goal-item strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.goal-item span { margin-top: 2px; color: var(--ink-soft); font-size: .78rem; }
.goal-item small { margin-top: 7px; color: var(--ink-soft); font-size: .67rem; line-height: 1.3; }
.goal-track { height: 6px; margin-top: 11px; overflow: hidden; border-radius: 99px; background: var(--paper-deep); }
.goal-track span { height: 100%; margin: 0; border-radius: inherit; background: var(--red); }
.deck-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.deck-card { min-height: 330px; position: relative; overflow: hidden; display: flex; flex-direction: column; padding: 30px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--white); box-shadow: var(--shadow); }
.deck-card::after { content: attr(data-kanji); position: absolute; right: 16px; bottom: -60px; color: rgba(24,34,54,.035); font: 260px/1 "Yu Mincho", "Noto Serif JP", serif; pointer-events: none; }
.deck-card > * { position: relative; z-index: 1; }
.deck-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.deck-icon { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 14px; background: var(--red-soft); color: var(--red); font-family: "Yu Mincho", serif; font-size: 1.4rem; font-weight: 700; }
.general-card .deck-icon { background: var(--blue-soft); color: var(--blue); }
.tag { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 10px; background: var(--paper-deep); color: var(--ink-soft); font-size: .73rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.deck-card h2 { margin-top: 26px; }
.deck-card p { color: var(--ink-soft); line-height: 1.55; max-width: 480px; }
.deck-meta { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 6px; color: var(--ink-soft); font-size: .87rem; }
.deck-meta strong { color: var(--ink); }
.deck-actions { margin-top: auto; display: flex; flex-wrap: wrap; gap: 10px; padding-top: 26px; }
.button { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 18px; border: 1px solid transparent; border-radius: 12px; font-weight: 760; cursor: pointer; text-decoration: none; transition: transform .16s ease, box-shadow .16s ease, background .16s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: var(--red); box-shadow: 0 8px 18px rgba(189,58,51,.2); }
.button.primary:hover { background: var(--red-dark); }
.button.secondary { background: transparent; border-color: var(--line); }
.button.secondary:hover { background: var(--paper); }
.button.blue { background: var(--blue); box-shadow: 0 8px 18px rgba(41,79,120,.19); }
.button.full { width: 100%; }
.text-button { color: var(--blue); font-weight: 750; padding: 5px; }
.text-button:hover { text-decoration: underline; }

/* Study */
.study-page { max-width: 1020px; padding-top: 18px; }
.study-toolbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 18px; margin-bottom: 28px; }
.back-button { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--white); border-radius: 12px; cursor: pointer; font-size: 1.2rem; }
.session-title strong, .session-title span { display: block; }
.session-title span { margin-top: 3px; color: var(--ink-soft); font-size: .84rem; }
.progress-track { height: 8px; border-radius: 99px; background: var(--paper-deep); overflow: hidden; margin-top: 10px; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--red); transition: width .3s ease; }
.session-count { font-weight: 780; font-variant-numeric: tabular-nums; white-space: nowrap; }
.study-layout { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 20px; align-items: start; }
.flashcard { min-height: 530px; display: flex; flex-direction: column; align-items: stretch; padding: 30px clamp(24px, 5vw, 54px); border: 1px solid var(--line); border-radius: 28px; background: var(--white); box-shadow: var(--shadow); position: relative; }
.flashcard::before { content: ""; position: absolute; top: 0; bottom: 0; left: 24px; width: 1px; background: rgba(189,58,51,.24); }
.stage-label { align-self: flex-start; display: inline-flex; gap: 7px; align-items: center; color: var(--ink-soft); font-size: .82rem; font-weight: 760; }
.stage-dot { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--red); font-size: .7rem; }
.prompt-zone { flex: 1; min-height: 230px; display: grid; place-items: center; text-align: center; padding: 24px 0 12px; }
.japanese-term { font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif; font-size: clamp(4.4rem, 13vw, 8.8rem); line-height: 1; letter-spacing: .02em; font-weight: 600; }
.reading-reveal { display: block; max-width: 680px; margin: 18px auto 0; color: var(--red); font-family: "Yu Gothic", "Noto Sans JP", sans-serif; font-size: clamp(1.15rem, 2.5vw, 1.75rem); font-weight: 700; line-height: 1.45; overflow-wrap: anywhere; }
.meaning-reveal { display: block; max-width: 680px; margin: 18px auto 0; color: var(--blue); font-size: clamp(1.1rem, 2.2vw, 1.55rem); font-weight: 760; line-height: 1.45; overflow-wrap: anywhere; }
.answer-area { width: 100%; max-width: 540px; margin: 0 auto; }
.answer-area label { display: block; margin-bottom: 8px; color: var(--ink-soft); font-size: .9rem; font-weight: 660; }
.answer-input { width: 100%; min-height: 52px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); padding: 0 15px; font-size: 1rem; }
.answer-input:focus { border-color: var(--blue); }
.answer-hint { min-height: 20px; margin: 7px 0 0; color: var(--ink-soft); font-size: .79rem; text-align: center; }
.card-actions { width: 100%; max-width: 540px; margin: 18px auto 0; }
.reveal-button { width: 100%; }
.grade-prompt { text-align: center; color: var(--ink-soft); font-size: .88rem; margin: 0 0 10px; }
.grade-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.button.wrong { color: var(--red-dark); background: var(--red-soft); border-color: rgba(189,58,51,.18); }
.button.hard { color: var(--amber); background: #f8edd8; border-color: rgba(154,100,20,.2); }
.button.right { color: var(--green); background: var(--green-soft); border-color: rgba(39,116,91,.18); }
.session-aside { display: grid; gap: 12px; }
.aside-card { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: rgba(255,254,250,.62); }
.aside-card small { display: block; color: var(--ink-soft); margin-bottom: 8px; }
.aside-card strong { font-size: 1.5rem; }
.aside-card p { color: var(--ink-soft); font-size: .83rem; line-height: 1.45; margin: 5px 0 0; }
.keyboard-help { color: var(--ink-soft); font-size: .76rem; line-height: 1.65; padding: 10px 4px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--white); padding: 1px 5px; color: var(--ink); font: inherit; }
.completion { max-width: 720px; margin: 30px auto; text-align: center; padding: 46px; border-radius: 28px; background: var(--white); border: 1px solid var(--line); box-shadow: var(--shadow); }
.completion-mark { width: 74px; height: 74px; margin: 0 auto 22px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--green); font-size: 2rem; }
.result-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin: 28px 0; }
.result-grid div { padding: 18px 10px; border-radius: 12px; background: var(--paper); }
.result-grid strong, .result-grid span { display: block; }
.result-grid strong { font-size: 1.45rem; }
.result-grid span { color: var(--ink-soft); font-size: .8rem; margin-top: 4px; }
.mastery-note { margin: -12px 0 22px; color: var(--green); }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat-card { padding: 22px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--white); }
.stat-card span { display: block; color: var(--ink-soft); font-size: .86rem; }
.stat-card strong { display: block; margin-top: 9px; font-size: 1.8rem; }
.panel { padding: 26px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--white); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.deck-progress-list { display: grid; gap: 12px; }
.deck-progress-row { display: grid; grid-template-columns: 1.1fr 2fr auto; align-items: center; gap: 18px; padding: 16px; border-radius: 13px; background: var(--paper); }
.deck-progress-row small { color: var(--ink-soft); }
.accuracy-bar { height: 9px; border-radius: 99px; background: var(--paper-deep); overflow: hidden; }
.accuracy-bar span { display: block; height: 100%; background: var(--blue); border-radius: inherit; }
.empty-state { text-align: center; color: var(--ink-soft); padding: 42px 18px; }

/* Dialog */
.dialog { width: min(720px, calc(100% - 28px)); max-height: min(850px, calc(100vh - 28px)); padding: 0; border: 0; border-radius: 24px; background: var(--white); box-shadow: 0 28px 80px rgba(24,34,54,.26); }
.dialog::backdrop { background: rgba(20,27,42,.54); backdrop-filter: blur(4px); }
.dialog-shell { padding: 28px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.dialog-header h2 { margin: 0; }
.dropzone { min-height: 210px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 2px dashed #c8c4ba; border-radius: 18px; background: var(--paper); cursor: pointer; text-align: center; padding: 24px; }
.dropzone:hover, .dropzone.dragging { border-color: var(--red); background: var(--red-soft); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone span:last-of-type { color: var(--ink-soft); font-size: .9rem; }
.drop-icon { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: var(--white); color: var(--red); font-size: 1.5rem; }
.example-format { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 16px; padding: 16px; border-radius: 13px; background: var(--blue-soft); }
.example-format p { margin: 4px 0 0; color: var(--ink-soft); font-size: .83rem; }
.file-summary { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px; border-radius: 12px; background: var(--paper); }
.file-summary strong, .file-summary span { display: block; }
.file-summary span { color: var(--ink-soft); font-size: .8rem; margin-top: 3px; }
.file-badge { display: grid !important; place-items: center; width: 46px; height: 46px; border-radius: 10px; color: white !important; background: var(--green); font-weight: 800; font-size: .7rem !important; }
.section-lead { margin: 22px 0 12px; font-weight: 720; }
.mapping-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mapping-grid label { color: var(--ink-soft); font-size: .82rem; font-weight: 700; }
.mapping-grid select { width: 100%; height: 44px; margin-top: 7px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--ink); }
.preview-table-wrap { margin-top: 20px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.preview-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.preview-table caption { text-align: left; padding: 12px 14px; color: var(--ink-soft); font-weight: 700; }
.preview-table th, .preview-table td { padding: 10px 14px; border-top: 1px solid var(--line); text-align: left; }
.preview-table th { background: var(--paper); color: var(--ink-soft); font-size: .77rem; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.compact-dialog { max-width: 560px; }
.help-list { list-style: none; display: grid; gap: 18px; padding: 0; margin: 0 0 26px; }
.help-list li { display: grid; grid-template-columns: 38px 1fr; gap: 13px; }
.help-list li > span { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; color: var(--red); background: var(--red-soft); font-weight: 800; }
.help-list p { margin: 4px 0 0; color: var(--ink-soft); line-height: 1.45; font-size: .88rem; }
.toast-region { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: grid; gap: 8px; }
.toast { padding: 13px 16px; border-radius: 12px; color: white; background: var(--ink); box-shadow: var(--shadow); animation: toast-in .25s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 820px) {
  .page { padding-top: 22px; }
  .page-head { grid-template-columns: 1fr; }
  .daily-summary { width: 100%; }
  .goal-panel { grid-template-columns: 1fr; }
  .deck-grid, .study-layout { grid-template-columns: 1fr; }
  .session-aside { grid-template-columns: repeat(2, 1fr); }
  .keyboard-help { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .deck-progress-row { grid-template-columns: 1fr; gap: 9px; }
}
@media (max-width: 560px) {
  .topbar { height: 68px; padding: 0 16px; }
  .nav-button { display: none; }
  .page { padding: 22px 16px 42px; }
  h1 { font-size: 2.2rem; }
  .deck-card { min-height: 310px; padding: 23px; }
  .goal-panel { padding: 20px; }
  .goal-grid { grid-template-columns: 1fr; }
  .goal-item { min-height: 82px; }
  .study-toolbar { grid-template-columns: auto 1fr; gap: 12px; }
  .session-count { grid-column: 2; }
  .flashcard { min-height: 510px; padding: 24px 22px 26px 35px; }
  .flashcard::before { left: 17px; }
  .japanese-term { font-size: clamp(4.2rem, 24vw, 7rem); }
  .grade-actions { grid-template-columns: 1fr; }
  .session-aside { grid-template-columns: 1fr 1fr; }
  .result-grid { grid-template-columns: 1fr; }
  .completion { padding: 30px 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card { padding: 17px; }
  .mapping-grid { grid-template-columns: 1fr; }
  .example-format { align-items: flex-start; flex-direction: column; }
  .dialog-shell { padding: 22px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
