:root {
  color-scheme: light;
  --bg: #f3f7ef;
  --panel: #fffefa;
  --text: #24332b;
  --muted: #647066;
  --line: #d8e1d2;
  --primary: #1f7a62;
  --primary-dark: #155842;
  --accent: #c75f35;
  --accent-soft: #ffe1cf;
  --yellow: #f4c95d;
  --good: #24764b;
  --bad: #b94335;
  --shadow: 0 14px 28px rgba(40, 68, 52, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    sans-serif;
}

button,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 34px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.eyebrow,
.lead,
h1,
h2,
p {
  margin-top: 0;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--primary-dark);
  font-size: 0.95rem;
  font-weight: 800;
}

h1 {
  margin-bottom: 8px;
  font-size: 2.4rem;
  line-height: 1.12;
  letter-spacing: 0;
}

.lead {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
}

.score-box {
  min-width: 116px;
  padding: 12px 14px;
  border: 2px solid rgba(31, 122, 98, 0.2);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 18px rgba(40, 68, 52, 0.08);
  text-align: center;
}

.score-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.score-box strong {
  display: block;
  margin-top: 2px;
  color: var(--primary-dark);
  font-size: 1.32rem;
  line-height: 1.2;
}

.control-band {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.9);
  box-shadow: 0 8px 18px rgba(40, 68, 52, 0.07);
}

.grade-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  color: var(--primary-dark);
  font-weight: 900;
}

.grade-control select {
  min-height: 46px;
  min-width: 144px;
  padding: 0 36px 0 12px;
  border: 2px solid rgba(31, 122, 98, 0.24);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(5, minmax(96px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef5ea;
}

.mode-button,
.tool-button,
.primary-button,
.answer-button {
  border-radius: 6px;
  cursor: pointer;
  font-weight: 900;
}

.mode-button {
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--primary-dark);
}

.mode-button.is-active {
  background: var(--primary);
  color: #fff;
}

.tool-button {
  min-height: 48px;
  padding: 0 16px;
  border: 2px solid rgba(31, 122, 98, 0.18);
  background: #fff;
  color: var(--primary-dark);
}

.practice-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  align-items: start;
}

.main-panel,
.side-panel,
.feedback,
.hint-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.main-panel {
  min-height: 560px;
  padding: 18px;
}

.level-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.92rem;
  font-weight: 900;
}

.pill.secondary {
  background: var(--accent-soft);
  color: #84401f;
}

.question-block {
  display: grid;
  gap: 12px;
  min-height: 282px;
  align-content: center;
  padding: 18px;
  border: 2px solid rgba(31, 122, 98, 0.12);
  border-radius: 8px;
  background: #f8fbf4;
}

.mode-label {
  margin-bottom: 0;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 900;
}

.question-text {
  margin-bottom: 0;
  color: var(--text);
  font-size: 1.28rem;
  font-weight: 900;
  line-height: 1.5;
}

.word-card {
  display: grid;
  gap: 10px;
  place-items: center;
  min-height: 140px;
  padding: 14px;
  border: 3px solid rgba(31, 122, 98, 0.18);
  border-radius: 8px;
  background: #fff;
}

.word {
  color: var(--text);
  font-size: 4.4rem;
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0;
}

.reading {
  color: var(--primary-dark);
  font-size: 2rem;
  line-height: 1.2;
  font-weight: 900;
}

.context-sentence {
  margin-bottom: 0;
  padding: 14px;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 1.45rem;
  line-height: 1.8;
  font-weight: 800;
}

.context-sentence mark {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--yellow);
  color: #2d2514;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
  min-height: 116px;
}

.answer-button {
  min-height: 76px;
  padding: 10px 12px;
  border: 2px solid rgba(31, 122, 98, 0.22);
  background: #fff;
  color: var(--text);
  font-size: 1.32rem;
  line-height: 1.25;
  box-shadow: 0 8px 16px rgba(40, 68, 52, 0.08);
}

.answer-button:hover,
.answer-button:focus-visible,
.kanji-tile:hover,
.kanji-tile:focus-visible,
.tool-button:hover,
.tool-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible {
  outline: 3px solid rgba(244, 201, 93, 0.55);
  outline-offset: 2px;
}

.answer-button.is-correct {
  border-color: var(--good);
  background: #e8f7ed;
  color: #174b2d;
}

.answer-button.is-wrong {
  border-color: var(--bad);
  background: #ffe8e0;
  color: #783025;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.primary-button {
  min-height: 54px;
  min-width: 128px;
  padding: 0 18px;
  border: 0;
  background: var(--primary);
  color: #fff;
}

.primary-button.success {
  background: var(--good);
}

.primary-button.quiet {
  border: 2px solid rgba(31, 122, 98, 0.24);
  background: #fff;
  color: var(--primary-dark);
}

.side-panel {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.feedback,
.hint-panel {
  padding: 14px;
}

.feedback {
  min-height: 84px;
  border-color: rgba(199, 95, 53, 0.28);
  background: #fff8f2;
  color: #6f371d;
  font-size: 1.04rem;
  font-weight: 800;
  line-height: 1.6;
}

.feedback.good {
  border-color: rgba(36, 118, 75, 0.3);
  background: #edf8ef;
  color: #174b2d;
}

.feedback.bad {
  border-color: rgba(185, 67, 53, 0.3);
  background: #fff0ea;
  color: #783025;
}

.hint-panel h2 {
  margin-bottom: 8px;
  color: var(--primary-dark);
  font-size: 1.08rem;
  line-height: 1.35;
}

.hint-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
}

.kanji-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.answer-grid.kanji-grid-all {
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  max-height: 360px;
  min-height: 220px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.kanji-tile {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 2px solid rgba(31, 122, 98, 0.18);
  border-radius: 6px;
  background: #f8fbf4;
  color: var(--text);
  font-size: 1.45rem;
  line-height: 1;
  font-weight: 900;
}

.kanji-tile.is-selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.word-card.is-kanji-mode .word {
  font-size: 5.2rem;
}

.word-card.is-kanji-mode .reading {
  font-size: 1.2rem;
}

.grade-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.grade-summary-row strong {
  color: var(--primary-dark);
  font-size: 1.05rem;
}

.kanji-chip {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 46px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.kanji-char {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: #eef5ea;
  color: var(--primary-dark);
  font-size: 1.7rem;
  font-weight: 900;
}

.kanji-reading {
  color: var(--text);
  font-size: 1rem;
  font-weight: 900;
}

.reading-compare-row {
  display: grid;
  grid-template-columns: 72px minmax(64px, 1fr) minmax(80px, auto);
  gap: 8px;
  align-items: center;
  min-height: 50px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.reading-compare-row strong {
  font-size: 1.15rem;
}

.reading-type-badge {
  display: inline-grid;
  place-items: center;
  min-height: 30px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 900;
}

.reading-type-badge.is-on {
  background: #dff1eb;
  color: var(--primary-dark);
}

.reading-type-badge.is-kun {
  background: var(--accent-soft);
  color: #84401f;
}

.grade-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #84401f;
  font-size: 0.78rem;
  font-weight: 900;
}

.is-hidden {
  display: none !important;
}

@media (max-width: 920px) {
  .practice-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 16px;
  }

  .topbar {
    display: grid;
  }

  .score-box {
    justify-self: start;
  }

  h1 {
    font-size: 2rem;
  }

  .segmented,
  .answer-grid,
  .side-panel {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .answer-grid.kanji-grid-all {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  }

  .grade-control,
  .grade-control select,
  .tool-button,
  .mode-button,
  .primary-button {
    width: 100%;
  }

  .word {
    font-size: 3.1rem;
  }

  .reading {
    font-size: 1.55rem;
  }

  .question-text,
  .context-sentence {
    font-size: 1.16rem;
  }
}

/* LiNest v3: 学習状態色と漢字一覧の密度を保ち、外枠を統一する。 */
body.linest-themed {
  --bg: var(--linest-bg);
  --panel: var(--linest-surface);
  --text: var(--linest-text);
  --muted: var(--linest-muted);
  --line: var(--linest-border);
  --primary: var(--linest-green);
  --primary-dark: var(--linest-green-dark);
  --accent: var(--linest-terracotta);
  --accent-soft: #f7e9df;
  --shadow: var(--linest-shadow);
}

body.linest-themed .topbar {
  padding: 16px 18px;
  border: 1px solid var(--linest-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed :where(.control-band, .main-panel, .feedback, .hint-panel, .score-box) {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed :where(.segmented, .tool-button, .grade-control select, .answer-button, .kanji-tile, .kanji-chip, .grade-summary-row) {
  border-color: var(--linest-border);
  background-color: #ffffff;
  color: var(--linest-text);
}

body.linest-themed .mode-button.is-active {
  background: var(--linest-green);
  color: #ffffff;
}

body.linest-themed .primary-button.quiet {
  border: 2px solid var(--linest-border) !important;
  background: #ffffff !important;
  color: var(--linest-green-dark) !important;
  box-shadow: none;
}

@media (max-width: 720px) {
  body.linest-themed :where(.grade-control, .mode-button, .tool-button, .primary-button) {
    min-width: 0;
    white-space: normal;
    word-break: keep-all;
  }
}
