:root {
  color-scheme: light;
  --paper: #f7f1e8;
  --surface: #fffaf2;
  --ink: #23201d;
  --muted: #746b61;
  --line: #ddd2c4;
  --teal: #127b72;
  --teal-dark: #0c5953;
  --coral: #d95f43;
  --gold: #e1a93b;
  --mint: #dceee7;
  --rose: #f7d6ca;
  --shadow: 0 12px 32px rgba(35, 32, 29, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

button,
select,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(88px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 18px;
}

.eyebrow,
.metric-label,
.lesson-chip,
.score-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 2px 0 0;
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  margin: 8px 0;
  font-size: 36px;
  line-height: 1.15;
}

.topbar .icon-button {
  flex: 0 0 auto;
}

.study-overview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.study-overview div {
  min-height: 74px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.study-overview strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
  line-height: 1;
}

.controls-band {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.select-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.mode-panel {
  animation: rise 180ms ease-out;
}

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

.word-card,
.prompt-block,
.score-panel,
.import-box,
.library-head,
.shadow-script,
.shadow-tools {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.word-card {
  position: relative;
  min-height: 430px;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 28px 18px;
  text-align: center;
}

.card-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  font-weight: 800;
}

.icon-button:active,
.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.tabbar button:active,
.self-score button:active,
.option-button:active {
  transform: translateY(1px);
}

.lesson-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--mint);
  color: var(--teal-dark);
}

.kana {
  margin: 0;
  color: var(--teal-dark);
  font-size: 22px;
  font-weight: 800;
}

.romaji,
.hint-text {
  margin: 8px 0 18px;
  color: var(--muted);
}

.answer-area {
  width: 100%;
  max-width: 440px;
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.meaning {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 800;
}

.example,
.example-cn {
  margin: 6px 0;
  color: var(--muted);
  line-height: 1.55;
}

.decision-row,
.import-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.primary-button,
.secondary-button,
.ghost-button,
.option-button,
.self-score button {
  min-height: 48px;
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 800;
}

.primary-button {
  background: var(--teal);
  color: white;
}

.secondary-button {
  background: var(--rose);
  color: #74301f;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
}

.prompt-block {
  position: relative;
  min-height: 220px;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 24px 18px;
  text-align: center;
}

.prompt-block .icon-button {
  position: absolute;
  top: 12px;
  right: 12px;
}

.option-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.option-button {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  text-align: left;
}

.option-button.correct {
  border-color: var(--teal);
  background: var(--mint);
}

.option-button.wrong {
  border-color: var(--coral);
  background: var(--rose);
}

.feedback {
  min-height: 28px;
  margin: 12px 2px 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
}

.type-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 12px;
}

.shadow-layout {
  display: grid;
  gap: 12px;
}

.shadow-script,
.shadow-tools,
.score-panel,
.library-head,
.import-box {
  padding: 16px;
}

.shadow-script h2 {
  font-size: 30px;
}

.shadow-tools {
  display: grid;
  gap: 10px;
}

.shadow-tools .select-label {
  color: var(--muted);
}

.meter {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 8px;
  background: #efe2d2;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--gold);
  transition: width 80ms linear;
}

.score-panel {
  margin-top: 12px;
}

.score-panel strong {
  display: block;
  margin: 4px 0;
  font-size: 32px;
}

.self-score {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.self-score button {
  background: #fffdf8;
  border: 1px solid var(--line);
}

.full-width {
  width: 100%;
  margin-top: 12px;
}

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

.library-head h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.library-head p {
  margin: 0;
  color: var(--muted);
}

.import-box label {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
}

.word-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.word-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 66px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.word-row strong {
  display: block;
  margin-bottom: 2px;
}

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

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: min(100%, 760px);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: rgba(247, 241, 232, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.tabbar button {
  min-width: 0;
  height: 46px;
  border-radius: 8px;
  background: #fffdf8;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 900;
}

.tabbar button.active {
  background: var(--teal);
  color: white;
  border-color: var(--teal);
}

[hidden] {
  display: none !important;
}

@media (min-width: 680px) {
  .shadow-layout {
    grid-template-columns: 1.4fr 0.8fr;
  }

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

@media (max-width: 420px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 32px;
  }

  .study-overview {
    gap: 6px;
  }

  .study-overview div {
    min-height: 68px;
    padding: 10px 8px;
  }

  .metric-label {
    font-size: 11px;
  }

  .type-form,
  .decision-row,
  .import-actions {
    grid-template-columns: 1fr;
  }
}
