:root {
  color-scheme: light;
  --bg: #fefefb;
  --surface: #ffffff;
  --text: #3e2f23;
  --heading: #4a3728;
  --muted: #6f6258;
  --green: #257836;
  --green-dark: #1d5e2a;
  --green-soft: #f1f7ed;
  --terracotta: #9c5230;
  --border: #efe7d9;
  --line: #cdbda9;
  --soft-yellow: #f7e3a8;
  --soft-sky: #cfe4ef;
  /* 不正解と取り消し操作の意味色。教材上の意味を持つためブランド色へは寄せない */
  --warn: #a8412f;
  --warn-border: rgba(168, 65, 47, 0.32);
  --warn-bg: rgba(168, 65, 47, 0.06);
  /* もじよみ（統制）の黒文字と、4色共通の輪郭 */
  --ink-black: #2b2622;
  --outline: rgba(43, 38, 34, 0.28);
  --shadow: 0 5px 18px rgba(62, 47, 35, 0.06);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 0;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

/* 訓練中の長押しメニュー・選択を抑える（入力欄はないアプリ） */
.app,
.app button,
.app label,
.app .stimulus,
.app .answer-swatch {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

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

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

/* iPad Safariでは word-break: auto-phrase が効かないため、共通テーマの見出し設定を上書きする */
body.linest-themed .app h1,
body.linest-themed .app h2,
body.linest-themed .app h3,
body.linest-themed .app legend,
body.linest-themed .app .option span,
body.linest-themed .app .eyebrow {
  line-break: strict;
  overflow-wrap: normal;
  word-break: keep-all;
  hyphens: none;
}

.screen {
  display: grid;
  gap: 18px;
}

.screen-head {
  display: grid;
  gap: 6px;
}

.eyebrow {
  margin: 0;
  color: var(--terracotta);
  font-size: 0.86rem;
  font-weight: 700;
}

.app-title,
.screen-title {
  margin: 0;
  color: var(--heading);
  font-size: clamp(1.5rem, 3.4vw, 2.05rem);
  line-height: 1.45;
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.97rem;
  line-height: 1.8;
}

.lead strong {
  color: var(--heading);
}

.panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* ---------- 設定 ---------- */

.settings-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px 20px;
  padding: 18px 20px 20px;
}

.field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field legend {
  padding: 0 0 7px;
  color: var(--green-dark);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.option-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option {
  position: relative;
  display: inline-flex;
}

.option input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.option span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  min-height: 46px;
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.option input:checked + span {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green-dark);
  box-shadow: inset 0 0 0 1px var(--green);
}

.option input:focus-visible + span {
  outline: 3px solid rgba(47, 158, 68, 0.48);
  outline-offset: 3px;
}

.field-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.7;
}

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

.actions--quiet {
  justify-content: flex-end;
}

.app .primary,
.app .secondary,
.app .danger-button {
  min-height: 48px;
  padding: 10px 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.app .primary {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

.app .secondary {
  border-color: var(--terracotta);
  background: var(--terracotta);
  color: #ffffff;
}

.app .danger-button {
  border-color: var(--warn);
  background: #ffffff;
  color: var(--warn);
}

.notice {
  margin: 0;
  color: var(--terracotta);
  font-size: 0.9rem;
  line-height: 1.7;
}

.notice:empty {
  display: none;
}

.safety-note {
  margin: 0;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(207, 228, 239, 0.28);
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.8;
}

.safety-note strong {
  color: var(--heading);
}

/* ---------- 説明 ---------- */

.block-badge {
  display: inline-flex;
  align-items: center;
  align-self: start;
  min-height: 32px;
  margin: 0;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--soft-yellow);
  color: var(--heading);
  font-size: 0.84rem;
  font-weight: 700;
}

.instruction-text {
  margin: 0;
  font-size: 1.06rem;
  line-height: 1.9;
}

.instruction-text strong {
  color: var(--green-dark);
}

.instruction-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.8;
}

.sample-frame {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 18px 16px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sample-label,
.sample-answer {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

/* ---------- 試行 ---------- */

.trial-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.trial-phase {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 3px 13px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 0.84rem;
  font-weight: 700;
}

.trial-progress {
  color: var(--muted);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.trial-question {
  margin: 0;
  color: var(--heading);
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  text-align: center;
}

.stimulus-frame {
  display: grid;
  place-items: center;
  min-height: 210px;
  padding: 20px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stimulus {
  display: grid;
  place-items: center;
  min-height: 150px;
}

/* 計時開始まで刺激を見せない。レイアウトは確定させたいので display ではなく visibility */
.stimulus.is-pending,
.trial-question.is-pending,
.cue-badge-slot.is-pending {
  visibility: hidden;
}

/* 質問キューのバッジ。丸（いろ）／角（いみ）で形でも見分けられるようにする。
   刺激の位置がずれないよう、スロットの外寸は形にかかわらず固定する */
.cue-badge-slot {
  display: grid;
  place-items: center;
  width: 100%;
  height: 76px;
}

.cue-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border: 3px solid var(--heading);
  background: var(--surface);
  color: var(--heading);
  font-family: "Zen Maru Gothic", "Hiragino Kaku Gothic ProN", "Hiragino Sans", sans-serif;
  /* 「いろ」2文字と「ことば」3文字が同じ外寸に収まる大きさ */
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.cue-badge[data-question="ink"] {
  border-radius: 50%;
  background: var(--soft-sky);
}

.cue-badge[data-question="word"] {
  border-radius: 10px;
  background: var(--soft-yellow);
}

/* 色パッチ・文字とも同じ濃さの輪郭を付け、黄色だけが薄く見えないようにする */
.stimulus-patch,
.sample-stimulus .stimulus-patch {
  width: clamp(116px, 30vw, 168px);
  height: clamp(116px, 30vw, 168px);
  border: 5px solid var(--outline);
  border-radius: 50%;
}

/* 文字の下に同じ濃さの輪郭を敷く。文字色そのものは変えないので4色を同条件で比べられる */
.stimulus-word,
.sample-stimulus .stimulus-word {
  font-family: "Zen Maru Gothic", "Hiragino Kaku Gothic ProN", "Hiragino Sans", sans-serif;
  font-size: clamp(3.1rem, 12vw, 5.2rem);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.04em;
  text-shadow:
    -2px 0 0 var(--outline),
    2px 0 0 var(--outline),
    0 -2px 0 var(--outline),
    0 2px 0 var(--outline),
    -2px -2px 0 var(--outline),
    2px -2px 0 var(--outline),
    -2px 2px 0 var(--outline),
    2px 2px 0 var(--outline);
}

.sample-stimulus {
  display: grid;
  place-items: center;
  min-height: 120px;
}

.sample-stimulus .stimulus-patch {
  width: 84px;
  height: 84px;
  border-width: 4px;
}

.sample-stimulus .stimulus-word {
  font-size: 2.6rem;
  text-shadow:
    -1px 0 0 var(--outline),
    1px 0 0 var(--outline),
    0 -1px 0 var(--outline),
    0 1px 0 var(--outline),
    -1px -1px 0 var(--outline),
    1px -1px 0 var(--outline),
    -1px 1px 0 var(--outline),
    1px 1px 0 var(--outline);
}

.feedback {
  min-height: 34px;
  margin: 0;
  font-size: 1.06rem;
  font-weight: 700;
  text-align: center;
}

.feedback[data-tone="correct"] {
  color: var(--green-dark);
}

.feedback[data-tone="wrong"] {
  color: var(--warn);
}

.feedback[data-tone="timeout"],
.feedback[data-tone="invalid"] {
  color: var(--terracotta);
}

.answer-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 12px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.answer-swatch {
  min-width: 96px;
  min-height: 96px;
  padding: 0;
  border: 5px solid var(--outline);
  border-radius: 16px;
  cursor: pointer;
  touch-action: manipulation;
}

.answer-row.is-locked .answer-swatch {
  pointer-events: none;
}

.oral-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

.oral-button {
  min-height: 62px;
  padding: 10px 18px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.06rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.oral-button--correct {
  border-color: var(--green);
  color: var(--green-dark);
}

.oral-button--wrong {
  border-color: var(--warn);
  color: var(--warn);
}

.oral-row.is-locked .oral-button {
  pointer-events: none;
}

/* ---------- 結果 ---------- */

.result-summary {
  margin: 0;
  font-size: 1rem;
  line-height: 1.8;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.result-card {
  padding: 16px 18px 18px;
}

.result-card__title {
  margin: 0 0 10px;
  color: var(--heading);
  font-size: 1.05rem;
}

.result-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
}

.result-list dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.result-list dd {
  margin: 0;
  color: var(--heading);
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
}

.interference-card {
  display: grid;
  gap: 6px;
  padding: 16px 18px 18px;
}

.interference-label {
  margin: 0;
  color: var(--green-dark);
  font-size: 0.9rem;
  font-weight: 700;
}

.interference-value {
  margin: 0;
  color: var(--heading);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.interference-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.75;
}

/* ---------- 履歴 ---------- */

.history-caution {
  margin: 0;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(247, 227, 168, 0.32);
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.8;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-item {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.history-item__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.history-item__date {
  color: var(--muted);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.history-tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 2px 11px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 0.8rem;
  font-weight: 700;
}

.history-tag--oral {
  background: rgba(207, 228, 239, 0.55);
  color: var(--heading);
}

.history-tag--practice {
  background: var(--soft-yellow);
  color: var(--heading);
}

.history-tag--drill {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.history-item__lines {
  display: grid;
  gap: 3px;
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.7;
}

.history-item__lines p {
  margin: 0;
}

.history-item__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.history-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.confirm-row {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--warn-border);
  border-radius: 10px;
  background: var(--warn-bg);
}

.confirm-text {
  color: var(--warn);
  font-size: 0.88rem;
  font-weight: 700;
}

.app .confirm-row .danger-button,
.app .confirm-row .secondary {
  min-height: 40px;
  padding: 6px 14px;
  font-size: 0.9rem;
}

/* ---------- 画面幅 ---------- */

@media (max-width: 680px) {
  .app {
    width: min(1024px, calc(100% - 20px));
    padding: 18px 0 32px;
  }

  .settings-panel {
    grid-template-columns: 1fr;
    padding: 16px 15px 18px;
  }

  .actions .primary,
  .actions .secondary,
  .actions .danger-button {
    flex: 1 1 46%;
  }

  .stimulus-frame {
    min-height: 180px;
  }
}

@media (max-width: 390px) {
  .option span {
    min-width: 66px;
    padding: 8px 11px;
    font-size: 0.9rem;
  }

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

  .answer-swatch {
    min-width: 0;
    min-height: 84px;
  }

  .oral-row {
    grid-template-columns: 1fr;
  }

  .result-list {
    grid-template-columns: 1fr auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app *,
  .app *::before,
  .app *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

@media print {
  .actions,
  .answer-row,
  .oral-row,
  .confirm-row {
    display: none !important;
  }

  .app {
    width: 100%;
  }

  .panel,
  .stimulus-frame,
  .sample-frame,
  .history-item {
    box-shadow: none;
  }
}
