:root {
  color-scheme: light;
  --ink: #17231d;
  --muted: #5f6e66;
  --paper: #f5f3eb;
  --panel: #fffefa;
  --panel-soft: #eef3ed;
  --line: #d4dbd3;
  --line-strong: #bdc8bf;
  --accent: #19766f;
  --accent-strong: #075851;
  --accent-soft: #e3f0ec;
  --danger: #b93f45;
  --warn: #a9690d;
  --good: #207746;
  --radius-control: 11px;
  --radius-panel: 22px;
  --shadow: 0 24px 64px rgba(36, 50, 42, 0.16), 0 4px 14px rgba(36, 50, 42, 0.08);
  --shadow-soft: 0 14px 38px rgba(36, 50, 42, 0.09);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  overscroll-behavior: none;
}

[hidden] {
  display: none !important;
}

body {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  overscroll-behavior: none;
  touch-action: pan-y;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(25, 118, 111, 0.13), transparent 28rem),
    radial-gradient(circle at 88% 92%, rgba(169, 105, 13, 0.1), transparent 30rem),
    linear-gradient(rgba(23, 35, 29, 0.018) 1px, transparent 1px),
    var(--paper);
  background-size: auto, auto, 100% 32px, auto;
}

button {
  font: inherit;
}

button,
input,
select,
textarea {
  accent-color: var(--accent);
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: rgba(25, 118, 111, 0.14);
}

::selection {
  color: var(--ink);
  background: #bfe2d8;
}

* {
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}

.app-shell {
  width: min(1180px, calc(100vw - 40px));
  max-width: 100%;
  margin: 0 auto;
  padding: max(32px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-mark {
  width: clamp(68px, 7vw, 82px);
  height: clamp(68px, 7vw, 82px);
  flex: 0 0 auto;
  border-radius: 24px;
  object-fit: cover;
  box-shadow: 0 14px 30px rgba(36, 50, 42, 0.14);
}

.brand-copy {
  display: grid;
  justify-items: start;
  min-width: 0;
  text-align: left;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
}

.brand-copy h1 {
  justify-self: start;
  max-width: min(56vw, 390px);
  color: var(--ink);
  font-size: clamp(1.65rem, 3.1vw, 2.35rem);
  font-weight: 900;
  letter-spacing: -0.035em;
  line-height: 1.02;
  white-space: nowrap;
}

.brand-subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

h2 {
  font-size: 1rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(74px, 1fr));
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--muted);
  background: rgba(255, 254, 250, 0.72);
  box-shadow: 0 10px 28px rgba(36, 50, 42, 0.06);
}

.stats span {
  min-width: 0;
  padding: 11px 13px;
  text-align: center;
}

.stats span + span {
  border-left: 1px solid var(--line);
}

.stats strong {
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
}

.view-bar {
  position: relative;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(0, 96px));
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 254, 250, 0.7);
  box-shadow: 0 8px 24px rgba(36, 50, 42, 0.05);
}

.settings-control {
  position: relative;
  flex: 0 0 auto;
}

.settings-button {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--muted);
  background: rgba(255, 254, 250, 0.8);
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, transform 160ms ease, background 160ms ease;
}

.settings-button svg,
.icon-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.settings-button:hover,
.settings-button[aria-expanded="true"] {
  border-color: rgba(27, 127, 121, 0.42);
  color: var(--accent-strong);
  background: var(--panel);
  transform: translateY(-1px);
}

.settings-button:focus-visible {
  outline: 3px solid rgba(27, 127, 121, 0.28);
  outline-offset: 3px;
}

.settings-panel {
  position: absolute;
  z-index: 30;
  top: 56px;
  right: 0;
  width: 210px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 14px 32px rgba(23, 33, 27, 0.16);
}

.settings-field {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

.settings-field select {
  width: 100%;
  min-height: 38px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  font: inherit;
}

.settings-field select:focus-visible {
  outline: 3px solid rgba(27, 127, 121, 0.28);
  outline-offset: 3px;
}

.view-tab {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 800;
  transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.view-tab:hover:not([aria-selected="true"]) {
  color: var(--ink);
  background: rgba(25, 118, 111, 0.06);
}

.view-tab[aria-selected="true"] {
  color: var(--accent-strong);
  background: var(--panel);
  box-shadow: 0 4px 14px rgba(33, 42, 36, 0.1);
}

.study-layout {
  display: grid;
  grid-template-columns: 294px minmax(0, 1fr);
  gap: 28px;
  align-items: stretch;
}

.study-layout.is-task-mode {
  grid-template-columns: 1fr;
}

.study-layout.is-task-mode .deck-panel {
  display: none;
}

.deck-view-tab {
  display: none;
}

.deck-panel {
  min-height: 520px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: rgba(255, 254, 250, 0.74);
  box-shadow: var(--shadow-soft);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-head h2 {
  font-size: 1.08rem;
  letter-spacing: -0.02em;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, transform 180ms ease;
}

.icon-button:hover {
  border-color: rgba(25, 118, 111, 0.45);
  color: var(--accent-strong);
  transform: rotate(-12deg);
}

.mode-tabs,
.importance-tabs {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.mode-tabs {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.importance-tabs {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mode-tab,
.importance-tab {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--muted);
  background: var(--panel);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 800;
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease, transform 150ms ease;
}

.mode-tab:hover,
.importance-tab:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  transform: translateY(-1px);
}

.mode-tab[aria-selected="true"],
.importance-tab[aria-selected="true"] {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.chapter-tabs {
  display: grid;
  gap: 8px;
  max-height: 356px;
  overflow: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.chapter-tab {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.chapter-tab:hover {
  border-color: var(--line-strong);
  background: #fff;
  transform: translateX(2px);
}

.chapter-tab[aria-selected="true"] {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
  box-shadow: inset 1px 0 0 var(--accent);
}

.progress-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.progress-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe5de;
}

#progressFill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #48a493);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.card-stage {
  display: grid;
  align-content: center;
  gap: 18px;
  min-height: 520px;
  perspective: 1200px;
}

.study-tools {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.undo-button,
.audio-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(23, 33, 27, 0.16);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 254, 250, 0.84);
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(23, 33, 27, 0.08);
  transition: border-color 160ms ease, color 160ms ease, transform 160ms ease, background 160ms ease;
}

.undo-button svg,
.audio-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.audio-button {
  color: var(--accent-strong);
}

.audio-button.is-playing {
  border-color: rgba(27, 127, 121, 0.5);
  background: rgba(27, 127, 121, 0.12);
}

.undo-button:not(:disabled):hover,
.audio-button:not(:disabled):hover {
  border-color: rgba(27, 127, 121, 0.42);
  color: var(--accent-strong);
  transform: translateY(-1px);
}

.undo-button:disabled,
.audio-button:disabled {
  cursor: default;
  opacity: 0.42;
  box-shadow: none;
}

.flashcard {
  --flip-angle: 0deg;
  --swipe-x: 0px;
  --swipe-y: 0px;
  --swipe-rotation: 0deg;
  --swipe-again-progress: 0;
  --swipe-good-progress: 0;
  position: relative;
  display: block;
  width: min(100%, 560px);
  aspect-ratio: 5 / 3.35;
  justify-self: center;
  border: 0;
  border-radius: 26px;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y pinch-zoom;
  user-select: none;
  -webkit-user-select: none;
  transform-style: preserve-3d;
  transform:
    translate3d(var(--swipe-x), var(--swipe-y), 0)
    rotateZ(var(--swipe-rotation))
    rotateY(var(--flip-angle));
  transition: transform 420ms cubic-bezier(0.2, 0.75, 0.2, 1);
  will-change: transform;
}

.flashcard.is-flipped {
  --flip-angle: 180deg;
}

.flashcard.is-dragging {
  transition: none;
  cursor: grabbing;
}

.flashcard.is-committing {
  pointer-events: none;
  transition-duration: 260ms;
  transition-timing-function: cubic-bezier(0.3, 0, 0.7, 0.2);
}

.swipe-feedback {
  position: absolute;
  z-index: 4;
  top: 22px;
  display: grid;
  width: 54px;
  aspect-ratio: 1;
  place-items: center;
  border: 3px solid currentColor;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
}

.swipe-feedback-again {
  right: 22px;
  color: var(--danger);
  opacity: var(--swipe-again-progress);
  transform: rotate(10deg);
}

.swipe-feedback-good {
  left: 22px;
  color: var(--good);
  opacity: var(--swipe-good-progress);
  transform: rotate(-10deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 38px;
  border: 1px solid rgba(23, 33, 27, 0.12);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 254, 250, 0.98), rgba(253, 251, 243, 0.94)),
    repeating-linear-gradient(0deg, transparent 0 38px, rgba(25, 118, 111, 0.08) 39px 40px);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
}

.card-face::before {
  content: "";
  position: absolute;
  top: 13px;
  left: 50%;
  width: 74px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 2px 5px rgba(7, 88, 81, 0.18);
  opacity: 0.74;
  transform: translateX(-50%);
}

.card-back {
  transform: rotateY(180deg);
}

.flashcard.is-empty {
  cursor: default;
}

.flashcard.is-empty .card-chapter,
.flashcard.is-empty .importance-badge,
.flashcard.is-empty .schedule-badge,
.flashcard.is-empty .kana-text,
.flashcard.is-empty .card-back {
  display: none;
}

.flashcard.is-empty .card-face {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.9)),
    repeating-linear-gradient(0deg, transparent 0 38px, rgba(27, 127, 121, 0.05) 39px 40px);
}

.card-chapter,
.answer-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.card-chapter,
.importance-badge {
  margin-bottom: 10px;
}

.importance-badge,
.schedule-badge {
  display: inline-grid;
  min-width: 58px;
  min-height: 28px;
  place-items: center;
  border: 1px solid rgba(27, 127, 121, 0.28);
  border-radius: 999px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 0.82rem;
  font-weight: 800;
}

.schedule-badge {
  margin-bottom: 12px;
  border-color: rgba(104, 115, 108, 0.28);
  color: var(--muted);
  background: rgba(104, 115, 108, 0.08);
}

.answer-label {
  margin-bottom: 18px;
}

.jp-text {
  max-width: 100%;
  color: var(--ink);
  overflow-wrap: anywhere;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: clamp(3rem, 7vw, 5.65rem);
  line-height: 1.05;
  white-space: pre-line;
}

.jp-text.is-phrase {
  font-size: clamp(2.15rem, 6.2vw, 4.2rem);
  line-height: 1.18;
}

.flashcard.is-empty .jp-text {
  display: grid;
  gap: 12px;
  justify-items: center;
  color: var(--accent-strong);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", sans-serif;
  font-size: clamp(2.6rem, 8vw, 5.2rem);
  font-weight: 900;
  line-height: 1;
}

.empty-hint {
  color: var(--muted);
  font-size: clamp(1rem, 2.6vw, 1.25rem);
  font-weight: 800;
}

.kanji-mask,
.word-mask {
  display: inline-grid;
  min-width: 0.72em;
  min-height: 1em;
  place-items: center;
  border-radius: 6px;
  color: transparent;
  background:
    repeating-linear-gradient(135deg, rgba(23, 33, 27, 0.18) 0 5px, rgba(23, 33, 27, 0.08) 5px 10px),
    rgba(27, 127, 121, 0.12);
  box-shadow: inset 0 -0.06em 0 rgba(9, 95, 91, 0.35);
  cursor: pointer;
  user-select: none;
}

.word-mask {
  min-width: min(7.5em, 100%);
  padding: 0 0.14em;
  white-space: pre-line;
}

.inline-mask {
  min-width: 2.6em;
  margin-left: 0.05em;
  padding: 0 0.12em;
  vertical-align: baseline;
}

.jp-text.is-phrase .word-mask {
  min-width: min(8.4em, 100%);
  padding: 0.08em 0.22em 0.14em;
}

.kanji-mask.is-revealed,
.word-mask.is-revealed {
  color: inherit;
  background: rgba(27, 127, 121, 0.08);
  box-shadow: inset 0 -0.06em 0 rgba(27, 127, 121, 0.4);
}

.kana-text {
  margin-top: 18px;
  color: var(--muted);
  font-size: clamp(1.15rem, 3vw, 1.65rem);
}

.zh-text {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--accent-strong);
  font-size: clamp(2rem, 5vw, 3.75rem);
  font-weight: 800;
  line-height: 1.15;
}

.pos-text {
  margin-top: 14px;
  color: var(--muted);
  font-size: 1rem;
}

.extra-text {
  display: none;
  max-width: 92%;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(186, 122, 24, 0.28);
  border-radius: 8px;
  color: #72510d;
  background: rgba(186, 122, 24, 0.09);
  font-size: clamp(0.95rem, 2.4vw, 1.15rem);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.extra-text.has-extra {
  display: inline-block;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 150px));
  gap: 10px;
  justify-content: center;
}

.actions.is-hidden {
  display: none;
}

.encouragement-dock {
  position: relative;
  z-index: 5;
  justify-self: center;
  width: 112px;
  height: 112px;
  margin-top: 48px;
  overflow: visible;
}

.mascot-off .encouragement-dock {
  display: none;
}

.encouragement-button {
  position: relative;
  display: grid;
  width: 112px;
  height: 112px;
  justify-items: center;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--ink);
  touch-action: none;
}

.encouragement-button:focus-visible {
  outline: 3px solid rgba(27, 127, 121, 0.28);
  outline-offset: 8px;
  border-radius: 8px;
}

.encouragement-bubble {
  position: absolute;
  z-index: 4;
  bottom: 120px;
  left: 50%;
  max-width: min(260px, calc(100vw - 44px));
  width: max-content;
  padding: 9px 12px;
  border: 1px solid rgba(27, 127, 121, 0.24);
  border-radius: 8px;
  color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 24px rgba(23, 33, 27, 0.1);
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.25;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 6px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.encouragement-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 12px;
  border-right: 1px solid rgba(27, 127, 121, 0.24);
  border-bottom: 1px solid rgba(27, 127, 121, 0.24);
  background: rgba(255, 255, 255, 0.94);
  transform: translateX(-50%) rotate(45deg);
}

.encouragement-button:hover .encouragement-bubble,
.encouragement-button:focus-visible .encouragement-bubble,
.encouragement-button.is-cheering .encouragement-bubble {
  opacity: 1;
  transform: translate(-50%, 0);
}

.mascot-stage {
  position: absolute;
  bottom: 0;
  width: 112px;
  aspect-ratio: 1;
  animation: mascot-rest 6s ease-in-out infinite;
  transform-origin: 50% 82%;
}

.mascot-stage.is-animating {
  animation: none;
}

.mascot-image {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 9px 8px rgba(23, 33, 27, 0.13));
  transform-origin: 50% 82%;
  transition:
    opacity 180ms ease,
    filter 180ms ease,
    transform 180ms ease;
  user-select: none;
  -webkit-user-drag: none;
}

.mascot-image-animated {
  opacity: 0;
}

.mascot-stage.is-animating .mascot-image-static {
  opacity: 0;
}

.mascot-stage.is-animating .mascot-image-animated {
  opacity: 1;
}

body[data-mascot="usagi"] .encouragement-dock,
body[data-mascot="usagi"] .encouragement-button {
  width: min(260px, calc(100vw - 44px));
  height: 170px;
}

body[data-mascot="usagi"] .mascot-stage {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  animation: none;
}

body[data-mascot="usagi"] .mascot-image {
  object-fit: contain;
}

body[data-mascot="usagi"] .encouragement-bubble {
  bottom: 178px;
}

.encouragement-button:hover .mascot-image {
  filter: drop-shadow(0 12px 9px rgba(23, 33, 27, 0.16));
  transform: translateY(-3px) scale(1.025);
}

.encouragement-button.is-cheering .mascot-image {
  animation: mascot-cheer 680ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes mascot-cheer {
  0%,
  100% {
    transform: translateY(0) rotate(0deg) scale(1);
  }

  28% {
    transform: translateY(-14px) rotate(-7deg) scale(1.04, 0.96);
  }

  58% {
    transform: translateY(-7px) rotate(7deg) scale(0.98, 1.03);
  }

  78% {
    transform: translateY(-2px) rotate(-2deg) scale(1.015, 0.985);
  }
}

@keyframes mascot-rest {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-1.5px) scale(1.005);
  }
}

@media (max-width: 780px) {
  .encouragement-dock {
    width: 96px;
    height: 96px;
    margin-top: 52px;
  }

  .encouragement-button {
    width: 96px;
    height: 96px;
  }

  .encouragement-bubble {
    bottom: 104px;
  }

  .mascot-stage {
    bottom: 0;
    width: 96px;
  }

  body[data-mascot="usagi"] .encouragement-dock,
  body[data-mascot="usagi"] .encouragement-button {
    width: min(230px, calc(100vw - 40px));
    height: 160px;
  }

  body[data-mascot="usagi"] .mascot-stage {
    width: 100%;
    height: 100%;
  }

  body[data-mascot="usagi"] .encouragement-bubble {
    bottom: 168px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mascot-stage {
    animation: none;
  }

  .mascot-image {
    transition: none;
  }

  .encouragement-button.is-cheering .mascot-image {
    animation: none;
  }
}

.spelling-view {
  min-height: 520px;
  display: grid;
  place-items: center;
}

.spelling-view[hidden] {
  display: none;
}

.spelling-scope-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.spelling-scope-tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 254, 250, 0.74);
}

.spelling-scope-tabs button {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 800;
}

.spelling-scope-tabs button[aria-selected="true"] {
  color: #fff;
  background: var(--accent);
}

.spelling-chapter-picker {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.spelling-chapter-picker[hidden] {
  display: none;
}

.spelling-chapter-picker select {
  min-height: 42px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

.spelling-quiz,
.spelling-empty {
  width: min(100%, 620px);
  padding: clamp(28px, 6vw, 54px);
  border: 1px solid rgba(23, 33, 27, 0.1);
  border-radius: var(--radius-panel);
  background: rgba(255, 254, 250, 0.92);
  box-shadow: var(--shadow);
  text-align: center;
}

.spelling-empty {
  display: grid;
  gap: 12px;
  color: var(--muted);
}

.spelling-empty strong {
  color: var(--accent-strong);
  font-size: 1.5rem;
}

.spelling-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.spelling-meta-right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.spelling-audio-button {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}

.spelling-audio-button svg {
  width: 18px;
  height: 18px;
}

.spelling-label {
  margin: 32px 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.spelling-prompt {
  margin: 0;
  color: var(--accent-strong);
  font-size: clamp(2.2rem, 7vw, 4.5rem);
  font-weight: 900;
  line-height: 1.15;
}

.spelling-pos {
  min-height: 1.5em;
  margin: 12px 0 24px;
  color: var(--muted);
}

.spelling-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.spelling-form input {
  min-width: 0;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-size: 1.2rem;
}

.spelling-form input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(27, 127, 121, 0.13);
}

.spelling-feedback {
  display: grid;
  gap: 7px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid;
  border-radius: 8px;
}

.spelling-feedback[hidden] {
  display: none;
}

.spelling-feedback.is-correct {
  border-color: rgba(35, 132, 74, 0.35);
  color: var(--good);
  background: rgba(35, 132, 74, 0.08);
}

.spelling-feedback.is-wrong {
  border-color: rgba(200, 75, 75, 0.35);
  color: var(--danger);
  background: rgba(200, 75, 75, 0.08);
}

.spelling-feedback span {
  color: var(--ink);
}

.next-spelling-button {
  min-height: 44px;
  margin-top: 12px;
  padding: 0 24px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.rate-button {
  min-height: 50px;
  border: 1px solid currentColor;
  border-radius: 14px;
  background: rgba(255, 254, 250, 0.88);
  cursor: pointer;
  font-weight: 800;
  box-shadow: 0 7px 16px rgba(36, 50, 42, 0.05);
  transition: color 150ms ease, background 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.rate-button:hover:not(:disabled) {
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 12px 22px rgba(36, 50, 42, 0.1);
}

.rate-button.danger:hover:not(:disabled) {
  background: var(--danger);
}

.rate-button.warn:hover:not(:disabled) {
  background: var(--warn);
}

.rate-button.good:hover:not(:disabled) {
  background: var(--good);
}

.rate-button:active:not(:disabled) {
  transform: translateY(0);
}

.rate-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.rate-button.danger {
  color: var(--danger);
}

.rate-button.warn {
  color: var(--warn);
}

.rate-button.good {
  color: var(--good);
}

.review-view {
  min-height: 520px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: rgba(255, 254, 250, 0.78);
  box-shadow: var(--shadow-soft);
}

.review-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.review-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.export-panel {
  display: grid;
  grid-template-columns: max-content max-content;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid rgba(27, 127, 121, 0.28);
  border-radius: 8px;
  background: rgba(27, 127, 121, 0.07);
}

.export-panel[hidden] {
  display: none;
}

.download-link {
  display: inline-grid;
  width: max-content;
  max-width: 100%;
  min-height: 38px;
  place-items: center;
  padding: 0 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

#exportPreview {
  grid-column: 1 / -1;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  background: var(--panel);
  font: 0.85rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

@media (max-width: 780px) {
  .export-panel {
    grid-template-columns: 1fr;
  }

  #exportPreview {
    grid-column: auto;
  }
}

.search-input,
.edit-form input,
.edit-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--ink);
  background: var(--panel);
  font: inherit;
}

.search-input {
  min-height: 42px;
  padding: 0 12px;
}

.check-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
}

.review-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 14px;
  align-items: start;
}

.word-list {
  display: grid;
  gap: 8px;
  max-height: 620px;
  overflow: auto;
  padding-right: 4px;
}

.word-row {
  display: grid;
  grid-template-columns: minmax(76px, 0.8fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  text-align: left;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.word-row:hover {
  border-color: var(--line-strong);
  background: #fff;
  transform: translateX(2px);
}

.word-row[aria-selected="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 1px 0 0 var(--accent);
}

.word-row strong,
.word-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.word-row strong {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 1.15rem;
}

.word-row span {
  color: var(--muted);
}

.word-row em {
  display: inline-grid;
  min-width: 30px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(186, 122, 24, 0.28);
  border-radius: 999px;
  color: #72510d;
  background: rgba(186, 122, 24, 0.09);
  font-style: normal;
  font-size: 0.75rem;
  font-weight: 800;
}

.edit-form {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.edit-meta {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.edit-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.edit-form input,
.edit-form textarea {
  padding: 10px 12px;
  resize: vertical;
}

.edit-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.primary-button,
.secondary-button {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: var(--radius-control);
  cursor: pointer;
  font-weight: 800;
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease, transform 150ms ease;
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button:hover {
  border-color: var(--line-strong);
  color: var(--accent-strong);
}

:where(button, a, input, select, textarea):focus-visible {
  outline: 3px solid rgba(25, 118, 111, 0.3);
  outline-offset: 3px;
}

.primary-button {
  border: 1px solid var(--accent);
  color: #fff;
  background: var(--accent);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--panel);
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.save-status {
  min-height: 20px;
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.88rem;
  font-weight: 700;
}

.empty-state {
  color: var(--muted);
  font-size: 1.2rem;
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100vw - 24px, 560px);
    padding: max(18px, env(safe-area-inset-top)) 0 max(18px, env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: start;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 22px;
  }

  .brand-lockup {
    width: 100%;
  }

  .brand-copy {
    flex: 1 1 auto;
  }

  .brand-copy h1 {
    max-width: none;
    font-size: clamp(1.55rem, 7vw, 2rem);
    white-space: normal;
  }

  .brand-subtitle {
    margin-top: 5px;
    font-size: 0.8rem;
  }

  .stats {
    width: 100%;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    border-radius: 14px;
  }

  .stats span {
    grid-column: span 2;
    padding: 9px 5px;
    font-size: 0.76rem;
  }

  .stats span:nth-child(4),
  .stats span:nth-child(5) {
    grid-column: span 3;
    border-top: 1px solid var(--line);
  }

  .stats span:nth-child(4) {
    border-left: 0;
  }

  .stats strong {
    font-size: 1rem;
  }

  .view-tabs {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding: 4px;
    border-radius: 14px;
  }

  .view-bar {
    width: 100%;
  }

  .deck-view-tab {
    display: block;
  }

  .view-tab {
    padding-inline: 5px;
    font-size: 0.76rem;
    line-height: 1.15;
  }

  .brand-lockup {
    gap: 12px;
  }

  .brand-mark {
    width: 62px;
    height: 62px;
    border-radius: 18px;
  }

  .study-layout,
  .study-layout.is-task-mode {
    grid-template-columns: 1fr;
  }

  .study-layout .deck-panel {
    display: none;
  }

  .study-layout.is-deck-mode .deck-panel {
    display: block;
  }

  .study-layout.is-deck-mode .card-stage,
  .study-layout.is-deck-mode .spelling-view,
  .study-layout.is-deck-mode .review-view {
    display: none;
  }

  .deck-panel,
  .card-stage {
    min-height: auto;
  }

  .card-stage {
    gap: 12px;
  }

  .deck-panel {
    padding: 16px;
  }

  .chapter-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 184px;
  }

  .chapter-tab {
    align-items: center;
    min-height: 48px;
  }

  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .card-face {
    padding: 28px 20px 24px;
    border-radius: 21px;
  }

  .flashcard {
    border-radius: 21px;
  }

  .jp-text {
    font-size: clamp(2.55rem, 12vw, 4rem);
  }

  .jp-text.is-phrase {
    font-size: clamp(1.9rem, 8vw, 3rem);
  }

  .kana-text {
    margin-top: 12px;
  }

  .rate-button {
    min-height: 48px;
    border-radius: 12px;
  }

  .encouragement-dock,
  .encouragement-button {
    width: 76px;
    height: 76px;
  }

  .encouragement-dock {
    margin-top: 4px;
  }

  .mascot-stage {
    width: 76px;
  }

  .encouragement-bubble {
    bottom: 84px;
  }

  body[data-mascot="usagi"] .encouragement-dock,
  body[data-mascot="usagi"] .encouragement-button {
    width: min(160px, calc(100vw - 40px));
    height: 96px;
  }

  body[data-mascot="usagi"] .encouragement-bubble {
    bottom: 104px;
  }

  .spelling-view {
    min-height: auto;
  }

  .spelling-scope-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .spelling-scope-tabs {
    width: 100%;
  }

  .spelling-chapter-picker {
    justify-content: space-between;
  }

  .spelling-chapter-picker select {
    flex: 1;
  }

  .spelling-quiz,
  .spelling-empty {
    padding: 26px 18px;
  }

  .spelling-form {
    grid-template-columns: 1fr;
  }

  .review-toolbar,
  .review-tools,
  .review-grid {
    grid-template-columns: 1fr;
  }

  .word-list {
    max-height: 360px;
  }

  .word-row {
    grid-template-columns: minmax(70px, 0.8fr) minmax(0, 1fr) auto;
  }
}

@media (min-width: 781px) and (max-width: 1020px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .stats {
    width: 100%;
  }

  .study-layout {
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 20px;
  }
}

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