:root {
  color-scheme: light;
  --bg: #eef5ee;
  --surface: #fffefa;
  --surface-2: #eaf2eb;
  --surface-warm: #fbf3e4;
  --line: #d4ded3;
  --text: #25312c;
  --muted: #66766d;
  --green: #2f7756;
  --blue: #345f95;
  --amber: #a06d2d;
  --ink: #26364a;
  --red: #b8463b;
  --shadow: 0 18px 45px rgba(38, 54, 46, 0.09);
  --shadow-soft: 0 10px 28px rgba(38, 54, 46, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Yu Gothic UI", "Meiryo", "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(47, 119, 86, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(52, 95, 149, 0.026) 1px, transparent 1px),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.2) 0 2px, transparent 2px 18px),
    linear-gradient(180deg, #edf6ed 0%, #f8f1e4 46%, #edf5ef 100%);
  background-size: 64px 64px, 64px 64px, auto, auto;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  max-width: 1420px;
  margin: 0 auto 16px;
  padding: 14px;
  background: rgba(255, 254, 250, 0.78);
  border: 1px solid rgba(212, 222, 211, 0.86);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  color: var(--ink);
}

h2 {
  font-size: 14px;
  line-height: 1.3;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.top-gallery {
  flex: 1;
  max-width: 420px;
  display: grid;
  grid-template-columns: repeat(5, 54px);
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

.top-gallery-item {
  width: 54px;
  height: 54px;
  border: 3px solid var(--surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 18px rgba(41, 54, 74, 0.14);
  transform: rotate(-2deg);
}

.top-gallery-item:nth-child(even) {
  transform: rotate(2deg) translateY(4px);
}

.top-gallery-item img,
.shelf-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.icon-button,
.primary-button,
.segment,
.choice-card {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.icon-button {
  min-width: 68px;
  height: 40px;
  border-radius: 8px;
  font-weight: 700;
  box-shadow: var(--shadow-soft);
}

.primary-button {
  height: 40px;
  padding: 0 18px;
  border-radius: 8px;
  background: #2f7d58;
  border-color: #2f7d58;
  color: white;
  font-weight: 800;
  box-shadow: var(--shadow-soft);
}

.icon-button:hover,
.primary-button:hover,
.segment:hover,
.choice-card:hover {
  transform: translateY(-1px);
}

.layout {
  max-width: 1420px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 260px;
  gap: 16px;
  align-items: start;
}

.sidebar,
.inspector {
  display: grid;
  gap: 12px;
}

.panel {
  background: rgba(255, 254, 250, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin-bottom: 12px;
}

.panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-header-row h2 {
  margin-bottom: 0;
}

.link-button {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: inherit;
}

.link-button:hover {
  background: var(--surface-2);
  transform: none;
}

.link-button.is-active {
  color: var(--red);
}

.link-button:disabled {
  color: var(--muted);
  cursor: default;
}

.link-button:disabled:hover {
  background: none;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 4px;
}

.segment {
  height: 34px;
  border-radius: 6px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segment.is-active {
  background: var(--surface-warm);
  color: var(--green);
  border-color: var(--line);
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}

.metric-row,
.source-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.metric-row:first-of-type,
.source-list div:first-child {
  border-top: 0;
}

.metric-row span,
dt {
  color: var(--muted);
}

.metric-row strong,
dd {
  margin: 0;
  text-align: right;
  font-weight: 800;
}

.trainer {
  min-height: calc(100vh - 110px);
}

.word-surface {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 254, 250, 0.97), rgba(248, 242, 228, 0.95)),
    repeating-linear-gradient(0deg, rgba(160, 109, 45, 0.04) 0 1px, transparent 1px 34px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
  min-height: 190px;
  display: grid;
  align-content: center;
}

.word-surface::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: #315d9b;
}

.word-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.word-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e7efe9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.word-main {
  font-size: 58px;
  line-height: 1.08;
  font-weight: 800;
}

.reading {
  min-height: 28px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 20px;
}

.answer-line {
  min-height: 28px;
  margin-top: 14px;
  color: var(--green);
  font-weight: 800;
}

.answer-line.is-wrong {
  color: var(--red);
}

.sentence-line {
  margin-top: 14px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--muted);
}

.sentence-line .sentence-ja {
  color: var(--ink);
  font-size: 16px;
}

.choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.choices.is-audio {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

.choice-card {
  display: grid;
  grid-template-rows: minmax(180px, 26vh) auto;
  min-height: 0;
  border-radius: 8px;
  overflow: hidden;
  padding: 0;
  box-shadow: var(--shadow);
  text-align: left;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease;
}

.choice-card:focus-visible {
  outline: 3px solid rgba(47, 125, 88, 0.32);
  outline-offset: 2px;
}

.choice-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #dbe2dd;
}

.choice-caption {
  min-height: 58px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.choice-caption strong {
  font-size: 16px;
}

.choice-caption span {
  color: var(--muted);
  font-size: 13px;
}

.choice-card.is-correct {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 125, 88, 0.18), 0 20px 45px rgba(47, 125, 88, 0.12);
}

.choice-card.is-wrong {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(184, 70, 59, 0.16), 0 20px 45px rgba(184, 70, 59, 0.1);
}

.choice-card.is-muted {
  opacity: 0.52;
}

.word-choice {
  grid-template-rows: none;
  min-height: 230px;
  padding: 22px;
  align-content: start;
  gap: 12px;
}

.option-label {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--green);
  font-weight: 900;
}

.option-word {
  margin-top: 8px;
  font-size: 42px;
  line-height: 1.15;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.option-reading {
  min-height: 26px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
}

.option-meaning {
  min-height: 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.source-list {
  margin: 0;
}

.source-link {
  display: inline-flex;
  margin-top: 10px;
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.source-link-secondary {
  display: block;
  color: var(--text);
}

.site-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
  color: var(--muted);
  font-size: 13px;
}

.site-footer a,
.license-page a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.license-page {
  position: relative;
  z-index: 1;
  max-width: 920px;
  margin: 0 auto;
  padding: 28px 18px 42px;
  color: var(--text);
}

.license-page header {
  margin-bottom: 22px;
}

.license-page h1 {
  margin: 8px 0 10px;
  font-size: clamp(34px, 5vw, 56px);
}

.license-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.src-lang-select {
  margin-top: 8px;
  padding: 6px 10px;
  width: 120px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

.license-section p code {
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 3px;
}

.license-section {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 34px rgba(73, 90, 76, 0.1);
  overflow: hidden;
}

.license-section h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

.license-section p,
.license-section li {
  line-height: 1.72;
}

.license-section ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.license-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 14px;
}

.license-table th,
.license-table td {
  padding: 7px 10px;
  text-align: left;
  border: 1px solid var(--line);
  vertical-align: top;
}

.license-table th {
  background: var(--surface-2);
  font-weight: 700;
  white-space: nowrap;
}

.license-table code {
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 3px;
}

.intro-body {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(255, 249, 238, 0.94), rgba(239, 248, 239, 0.92)),
    var(--bg);
}

.intro-boot {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-content: center;
  gap: 18px;
  text-align: center;
  color: var(--text);
  background: #fff8ea;
  animation: bootExit 1.5s ease 0.85s forwards;
  pointer-events: none;
}

.boot-mark {
  font-size: clamp(48px, 10vw, 118px);
  font-weight: 900;
}

.boot-line {
  width: min(320px, 58vw);
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(144, 167, 147, 0.32);
}

.boot-line::before {
  content: "";
  display: block;
  width: 46%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  animation: bootLoad 1.3s ease-in-out infinite;
}

.boot-caption {
  color: var(--muted);
  font-weight: 800;
}

.intro-shell {
  max-width: 1180px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 20px 44px;
}

.intro-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.brand-link,
.intro-nav a {
  color: var(--text);
  font-weight: 900;
  text-decoration: none;
}

.intro-nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-cta {
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--text);
  color: #fffdf8 !important;
}

.intro-hero {
  display: grid;
  grid-template-columns: minmax(360px, 0.82fr) minmax(520px, 1.18fr);
  align-items: center;
  gap: 42px;
  min-height: calc(100vh - 140px);
}

.intro-copy {
  animation: introRise 0.9s ease both;
}

.intro-copy h1 {
  max-width: 760px;
  margin: 10px 0 16px;
  font-size: clamp(32px, 3vw, 44px);
  line-height: 1.18;
  text-wrap: balance;
}

.intro-lede {
  max-width: 620px;
  color: var(--muted);
  font-size: clamp(16px, 1.55vw, 19px);
  line-height: 1.78;
}

.intro-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
}

.intro-primary,
.intro-secondary {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 900;
  text-decoration: none;
}

.intro-lang-select {
  width: auto;
  min-width: 118px;
  min-height: 46px;
  border-radius: 999px;
  padding: 0 14px;
  border: 1px solid rgba(112, 134, 117, 0.35);
  background: rgba(255, 253, 248, 0.82);
  color: var(--text);
  font-weight: 900;
  box-shadow: var(--shadow-soft);
}

.intro-primary {
  background: var(--green);
  color: #fffdf8;
  box-shadow: 0 16px 36px rgba(73, 123, 89, 0.24);
}

.intro-secondary {
  border: 1px solid rgba(112, 134, 117, 0.35);
  background: rgba(255, 253, 248, 0.72);
  color: var(--text);
}

.intro-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-width: 500px;
  margin: 0;
}

.intro-stats div {
  padding: 12px 14px;
  border: 1px solid rgba(216, 223, 218, 0.92);
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.8);
}

.intro-stats dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.intro-stats dd {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 22px;
  font-weight: 900;
}

#introLevelCount {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  font-size: 13px;
}

.intro-level-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.01em;
}

.intro-visual {
  position: relative;
  min-height: 590px;
  animation: introFade 1.1s ease both;
}

.sound-ring {
  position: absolute;
  inset: 12% 9%;
  border: 1px solid rgba(87, 117, 95, 0.18);
  border-radius: 50%;
}

.sound-ring-two {
  inset: 22% 19%;
  border-color: rgba(171, 126, 68, 0.18);
}

.floating-word {
  position: absolute;
  z-index: 2;
  padding: 8px 12px;
  border: 1px solid rgba(216, 223, 218, 0.92);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.82);
  color: var(--text);
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(73, 90, 76, 0.12);
}

.word-one {
  top: 12%;
  left: 18%;
}

.word-two {
  right: 10%;
  top: 34%;
}

.word-three {
  left: 12%;
  bottom: 18%;
}

.intro-image-orbit {
  position: absolute;
  inset: 0;
}

.intro-image-tile {
  --tile-size: clamp(76px, 10vw, 118px);
  position: absolute;
  width: var(--tile-size);
  aspect-ratio: 1;
  cursor: grab;
  touch-action: none;
  user-select: none;
  will-change: transform;
}

.intro-image-card {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 1px solid rgba(216, 223, 218, 0.95);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 18px 38px rgba(73, 90, 76, 0.16);
  transform: translate3d(0, 0, 0);
  animation: tileFloat 5.2s ease-in-out var(--tile-delay) infinite;
  transition:
    box-shadow 0.18s ease,
    filter 0.18s ease,
    transform 0.18s ease;
}

.intro-image-tile:hover:not(.is-dragging) .intro-image-card {
  box-shadow: 0 22px 44px rgba(73, 90, 76, 0.2);
  filter: saturate(1.05);
}

.intro-image-tile.is-dragging {
  cursor: grabbing;
}

.intro-image-tile.is-dragging .intro-image-card {
  animation: none;
  box-shadow: 0 28px 58px rgba(73, 90, 76, 0.28);
  transform: scale(1.05) rotate(1deg);
}

.intro-image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.intro-image-card span {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  overflow: hidden;
  padding: 4px 6px;
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.86);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.intro-image-tile:nth-child(1) {
  left: 42%;
  top: 4%;
  --tile-size: 128px;
}

.intro-image-tile:nth-child(2) {
  right: 8%;
  top: 12%;
}

.intro-image-tile:nth-child(3) {
  left: 12%;
  top: 24%;
  --tile-size: 112px;
}

.intro-image-tile:nth-child(4) {
  right: 20%;
  top: 42%;
  --tile-size: 142px;
}

.intro-image-tile:nth-child(5) {
  left: 34%;
  top: 46%;
}

.intro-image-tile:nth-child(6) {
  left: 6%;
  bottom: 8%;
  --tile-size: 126px;
}

.intro-image-tile:nth-child(7) {
  right: 9%;
  bottom: 12%;
}

.intro-image-tile:nth-child(8) {
  left: 48%;
  bottom: 2%;
  --tile-size: 108px;
}

.intro-image-tile:nth-child(9) {
  left: 24%;
  top: 5%;
  --tile-size: 92px;
}

.intro-image-tile:nth-child(10) {
  right: 34%;
  bottom: 26%;
  --tile-size: 96px;
}

.intro-image-orbit.is-empty::before {
  content: "JLPT";
  position: absolute;
  inset: 30% 20%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(216, 223, 218, 0.92);
  border-radius: 12px;
  background: rgba(255, 252, 246, 0.8);
  color: var(--muted);
  font-size: 64px;
  font-weight: 900;
}

.intro-band,
.intro-license-strip {
  margin-top: 24px;
}

.intro-section-heading h2,
.intro-license-strip h2 {
  margin: 6px 0 10px;
  font-size: clamp(28px, 4vw, 44px);
}

.intro-feature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.intro-feature-grid article {
  padding: 18px;
  border: 1px solid rgba(216, 223, 218, 0.92);
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.82);
}

.intro-feature-grid span {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: rgba(88, 129, 87, 0.16);
  color: var(--green);
  font-weight: 900;
}

.intro-feature-grid h3 {
  margin: 14px 0 8px;
}

.intro-feature-grid p,
.intro-license-strip p {
  color: var(--muted);
  line-height: 1.72;
}

.intro-license-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 22px;
  border: 1px solid rgba(216, 223, 218, 0.92);
  border-radius: 8px;
  background: rgba(247, 252, 244, 0.84);
}

@keyframes bootLoad {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(230%);
  }
}

@keyframes bootExit {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

@keyframes introRise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes introFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes tileFloat {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-14px) rotate(1.8deg);
  }
}

.image-shelf-panel {
  background: rgba(251, 247, 239, 0.9);
}

.image-shelf {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.shelf-thumb {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(216, 223, 218, 0.9);
  background: var(--surface);
  box-shadow: 0 8px 18px rgba(41, 54, 74, 0.1);
}

.history-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.history-list li {
  padding-left: 2px;
}

.history-list strong {
  color: var(--text);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .top-gallery {
    max-width: 300px;
    grid-template-columns: repeat(5, 44px);
  }

  .top-gallery-item {
    width: 44px;
    height: 44px;
  }

  .inspector {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
  }

  .intro-hero {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .intro-visual {
    min-height: 470px;
  }
}

@media (max-width: 820px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    padding: 10px;
  }

  .topbar,
  .layout {
    width: 100%;
    max-width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .topbar {
    padding: 12px;
    margin-bottom: 12px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .topbar .eyebrow {
    font-size: 11px;
  }

  .top-gallery {
    max-width: none;
    grid-template-columns: repeat(5, 44px);
    justify-content: center;
    gap: 7px;
  }

  .top-gallery-item {
    width: 44px;
    height: 44px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: normal;
    gap: 8px;
    width: 100%;
  }

  .top-actions > * {
    min-width: 0;
    width: 100%;
  }

  .lang-select,
  .voice-select,
  .icon-button,
  .primary-button {
    min-width: 0;
    height: 42px;
    padding-left: 8px;
    padding-right: 8px;
    font-size: 15px;
  }

  .primary-button {
    white-space: normal;
    line-height: 1.15;
  }

  .layout {
    align-items: stretch;
  }

  .trainer {
    order: 1;
    min-height: auto;
  }

  .sidebar {
    order: 2;
  }

  .inspector {
    order: 3;
  }

  .panel {
    padding: 12px;
  }

  .word-surface {
    min-height: 150px;
    padding: 18px;
  }

  .reading {
    font-size: 17px;
  }

  .sentence-line {
    font-size: 14px;
  }

  .choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
  }

  .choices.is-audio {
    grid-template-columns: 1fr 1fr;
  }

  .image-choice {
    grid-template-rows: clamp(128px, 34vw, 220px) auto;
  }

  .image-choice img {
    object-fit: contain;
    background: linear-gradient(135deg, #f8f3ea, #dfece5);
  }

  .word-choice {
    min-height: 150px;
    grid-template-rows: none;
    padding: 16px;
  }

  .option-word {
    font-size: clamp(24px, 8vw, 34px);
  }

  .word-main {
    font-size: clamp(34px, 12vw, 48px);
    overflow-wrap: anywhere;
  }

  .inspector {
    grid-template-columns: 1fr;
  }

  .source-list div {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
  }

  dd {
    text-align: left;
    overflow-wrap: anywhere;
  }

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

  .write-input {
    width: 100%;
    min-width: 0;
    font-size: 20px;
  }

  .kbd-hint {
    display: none;
  }

  .site-footer {
    flex-wrap: wrap;
    text-align: center;
  }

  .intro-shell {
    padding: 16px 14px 34px;
  }

  .intro-nav {
    align-items: flex-start;
  }

  .intro-nav-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .intro-copy h1 {
    font-size: 34px;
    line-height: 1.16;
  }

  .intro-stats,
  .intro-feature-grid,
  .intro-license-strip {
    grid-template-columns: 1fr;
  }

  .intro-visual {
    min-height: 390px;
  }

  .intro-image-tile {
    --tile-size: 88px;
  }

  .intro-image-tile:nth-child(n + 7) {
    display: none;
  }

  .floating-word {
    font-size: 14px;
  }
}

@media (max-width: 520px) {
  .topbar h1 {
    font-size: 20px;
  }

  .top-gallery {
    display: none;
  }

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

  .primary-button {
    grid-column: span 2;
  }

  .segmented {
    grid-template-columns: 1fr 1fr;
  }

  .segment {
    min-height: 42px;
    height: auto;
    padding: 6px 4px;
    font-size: 14px;
  }

  .choices.is-audio {
    grid-template-columns: 1fr;
  }

  .image-choice {
    grid-template-rows: clamp(112px, 32vw, 150px) auto;
  }

  .word-choice {
    min-height: 132px;
  }

  .choice-caption {
    min-height: 42px;
    padding: 8px 10px;
  }

  .summary-card {
    width: calc(100% - 20px);
    padding: 20px 16px;
  }
}

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

  .intro-boot {
    display: none;
  }
}

/* === Dark mode === */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #18231e;
  --surface: #1f2d26;
  --surface-2: #253029;
  --surface-warm: #272620;
  --line: #344038;
  --text: #d4e4d0;
  --muted: #8ca48a;
  --green: #5dbf82;
  --blue: #6da3d4;
  --amber: #c49040;
  --ink: #c4d8c0;
  --red: #d46b62;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.5);
  --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] body::before {
  background:
    linear-gradient(90deg, rgba(47, 119, 86, 0.07) 1px, transparent 1px),
    linear-gradient(0deg, rgba(52, 95, 149, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, #18231e 0%, #1e2318 46%, #18231e 100%);
  background-size: 64px 64px, 64px 64px, auto;
}

[data-theme="dark"] .topbar {
  background: rgba(31, 45, 38, 0.88);
  border-color: rgba(52, 64, 56, 0.86);
}

[data-theme="dark"] .panel {
  background: rgba(31, 45, 38, 0.92);
}

[data-theme="dark"] .image-shelf-panel {
  background: rgba(39, 38, 32, 0.92);
}

[data-theme="dark"] .word-surface {
  background:
    linear-gradient(135deg, rgba(31, 45, 38, 0.97), rgba(39, 38, 32, 0.95)),
    repeating-linear-gradient(0deg, rgba(196, 144, 64, 0.05) 0 1px, transparent 1px 34px);
}

[data-theme="dark"] select {
  background: var(--surface-2);
}

[data-theme="dark"] .intro-body {
  background:
    linear-gradient(135deg, rgba(24, 35, 30, 0.96), rgba(30, 35, 24, 0.94)),
    var(--bg);
}

[data-theme="dark"] .intro-boot {
  background: #18231e;
}

[data-theme="dark"] .nav-cta {
  background: var(--text);
  color: #18231e !important;
}

[data-theme="dark"] .intro-secondary {
  background: rgba(31, 45, 38, 0.72);
  border-color: rgba(52, 64, 56, 0.5);
}

[data-theme="dark"] .intro-feature-grid article,
[data-theme="dark"] .intro-stats div,
[data-theme="dark"] .floating-word,
[data-theme="dark"] .intro-image-card {
  background: rgba(31, 45, 38, 0.88);
  border-color: rgba(52, 64, 56, 0.86);
}

[data-theme="dark"] .intro-image-card span {
  background: rgba(31, 45, 38, 0.88);
}

[data-theme="dark"] .intro-license-strip {
  background: rgba(24, 40, 30, 0.84);
  border-color: rgba(52, 64, 56, 0.86);
}

[data-theme="dark"] .license-section {
  background: rgba(31, 45, 38, 0.88);
  border-color: rgba(52, 64, 56, 0.86);
}

/* === Write form (听音写词 mode) === */
.write-form {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.write-input {
  flex: 1;
  height: 54px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.write-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 125, 88, 0.15);
}

.write-input:disabled {
  opacity: 0.6;
  cursor: default;
}

[data-theme="dark"] .write-input {
  background: var(--surface-2);
}

/* === Auto-advance progress bar === */
.auto-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  display: none;
  overflow: hidden;
}

.auto-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--green);
}

/* === Keyboard hints === */
.kbd-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  user-select: none;
}

.kbd {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  font-family: inherit;
  font-size: 10px;
  font-weight: 800;
}

/* === History color coding === */
.history-item-correct strong {
  color: var(--green);
}

.history-item-wrong strong {
  color: var(--red);
}

/* === Wrong words panel === */
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  min-width: 22px;
  height: 20px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  vertical-align: middle;
  transition: background 0.2s, color 0.2s;
}

.count-badge.has-items {
  background: var(--red);
  color: white;
}

.panel-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* === Summary overlay === */
.summary-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.42);
  display: grid;
  place-items: center;
  backdrop-filter: blur(3px);
}

.summary-overlay[hidden] {
  display: none;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 28px 22px;
  max-width: 480px;
  width: calc(100% - 40px);
  box-shadow: var(--shadow);
}

.summary-card h2 {
  margin-bottom: 0;
  font-size: 20px;
}

.summary-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0;
}

.summary-metric {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.summary-metric dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-metric dd {
  margin: 2px 0 0;
  font-size: 28px;
  font-weight: 900;
  color: var(--text);
}

.summary-wrong-title {
  font-weight: 800;
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 6px;
}

.summary-wrong-list {
  margin: 0;
  padding: 0 0 0 18px;
  max-height: 150px;
  overflow-y: auto;
  color: var(--muted);
  font-size: 13px;
}

.summary-wrong-list li {
  margin-bottom: 4px;
}

.summary-wrong-list strong {
  color: var(--red);
}

.summary-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  justify-content: flex-end;
}

/* === Top selects === */
.lang-select,
.voice-select {
  height: 40px;
  width: auto;
  min-width: 84px;
  padding: 0 10px;
  border-radius: 8px;
  font-weight: 700;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}

.voice-select {
  min-width: 118px;
}

/* === Auto-advance & dark mode toggle button states === */
#autoAdvanceButton.is-active {
  background: var(--green);
  border-color: var(--green);
  color: white;
}
