/* kazoekata-quiz の style.css がベース。
   漢字クイズ固有のもの（例文表示・大きな漢字の選択肢・書き順アニメ）を足してある。 */
:root {
  --header-h: 52px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  background: #fdf6ec;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.screen.hidden { display: none; }

/* ---------- 共通トップバー ---------- */
.top-bar {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: #ffffff;
  border-bottom: 1px solid #ece1d0;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: #f7f1e6;
  border-radius: 12px;
  font-size: 20px;
  cursor: pointer;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.icon-btn:active { background: #ece1d0; }
.region-title {
  font-size: 17px;
  font-weight: bold;
  color: #4a3b2b;
}
.timer-display {
  font-size: 12px;
  color: #a3958a;
  font-variant-numeric: tabular-nums;
  width: 44px;
  text-align: right;
  flex: 0 0 auto;
}

/* ---------- ホーム画面 ---------- */
#screen-home {
  background: linear-gradient(180deg, #fdf6ec 0%, #ffffff 100%);
}
.home-title-wrap { flex: 1 1 auto; text-align: center; }
.home-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding: 20px 24px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
}
.mode-btn {
  border: none;
  border-radius: 20px;
  padding: 20px;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #4a3b2b;
}
.mode-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }
.mode-btn:disabled {
  filter: grayscale(0.8);
  opacity: 0.55;
  cursor: default;
  box-shadow: none;
}
.mode-btn:disabled:active { transform: none; }
.mode-btn-icon { font-size: 28px; }
.mode-btn-title { font-size: 20px; font-weight: bold; }
.mode-btn-sub { font-size: 13px; color: #6b5b4a; }
.mode-btn-state { font-size: 12px; color: #8a7869; margin-top: 4px; }
.mode-btn-1 { background: linear-gradient(135deg, #ffe1a8, #ffc978); }
.mode-btn-2 { background: linear-gradient(135deg, #bdf0d1, #8fe0b0); }
.home-scope {
  text-align: center;
  font-size: 13px;
  color: #8a7869;
  line-height: 1.6;
}
.home-scope-empty {
  color: #b3541e;
  background: #fff2e0;
  border-radius: 12px;
  padding: 10px 12px;
}

/* ---------- クイズ画面 ---------- */
.quiz-progress-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
.quiz-progress { font-size: 16px; font-weight: bold; color: #4a3b2b; }
.quiz-score { font-size: 12px; color: #6b5b4a; }

.quiz-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 20px;
  padding: 24px 16px;
  overflow-y: auto;
}
.quiz-question {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 110px;
}
.quiz-question-sub {
  font-size: 15px;
  color: #6b5b4a;
  text-align: center;
}
.quiz-answer-area {
  width: 100%;
  max-width: 440px;
}

/* ---------- 例文 ---------- */
.sentence {
  font-size: 26px;
  font-weight: bold;
  color: #4a3b2b;
  text-align: center;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.sentence-focus { color: #4a3b2b; }
.sentence-focus-strong {
  color: #d2691e;
  background: #fff2e0;
  border-radius: 8px;
  padding: 0 6px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.sentence-focus-blank { color: #c0a68c; }

/* ---------- 選択肢 ---------- */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.choice-btn {
  border: 2px solid #ece1d0;
  background: #ffffff;
  border-radius: 16px;
  cursor: pointer;
  min-height: 64px;
  font-weight: bold;
  color: #4a3b2b;
  font-family: inherit;
}
.choice-btn:active { background: #fbf4ea; }
.choice-btn-kanji {
  padding: 10px;
  font-size: 40px;
  line-height: 1.2;
  /* 漢字は字形そのものを見せたいので、丸ゴシックより明朝/標準ゴシックが読みやすい */
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
}
.choice-btn-reading { padding: 14px 10px; font-size: 24px; }

/* ---------- 手書き入力 ---------- */
.handwriting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.handwriting-hint {
  font-size: 14px;
  color: #8a7869;
  background: #f7f1e6;
  border-radius: 999px;
  padding: 4px 14px;
}
.handwriting-canvas-wrap { line-height: 0; }
.handwriting-canvas {
  border: 2px solid #ece1d0;
  border-radius: 12px;
  background: #fffdfa;
  /* 田の字のガイド。KanjiCanvas が clearRect するので背景側に描く */
  background-image:
    linear-gradient(#f0e6d6 1px, transparent 1px),
    linear-gradient(90deg, #f0e6d6 1px, transparent 1px);
  background-position: center center;
  background-size: 50% 50%;
  /* スクロールやピンチに取られると線が引けないので、タッチはすべてこちらで受ける */
  touch-action: none;
}
.handwriting-message {
  font-size: 14px;
  min-height: 20px;
  color: #8a7869;
}
.handwriting-message-warn { color: #b3541e; font-weight: bold; }
.handwriting-tools {
  display: flex;
  gap: 10px;
}
.handwriting-tool {
  border: 2px solid #ece1d0;
  background: #ffffff;
  color: #4a3b2b;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  min-height: 44px;
  cursor: pointer;
  font-family: inherit;
}
.handwriting-tool:active { background: #fbf4ea; }
.handwriting-submit { width: 100%; max-width: 300px; }

/* ---------- 50音パネル ---------- */
.kana-pad {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.kana-display {
  min-height: 56px;
  min-width: 60%;
  border: 2px dashed #ece1d0;
  border-radius: 12px;
  background: #fffdfa;
  font-size: 32px;
  font-weight: bold;
  color: #4a3b2b;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 16px;
  letter-spacing: 0.1em;
}
.kana-display-empty::after {
  content: "よみを いれてね";
  font-size: 14px;
  font-weight: normal;
  color: #c0a68c;
  letter-spacing: 0;
}
.kana-grid {
  display: grid;
  /* あ行〜わ行の10列 × あ〜おの5段。列ごとに縦に並べる */
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(5, 1fr);
  grid-auto-flow: column;
  gap: 4px;
  width: 100%;
}
.kana-key {
  border: 2px solid #ece1d0;
  background: #ffffff;
  color: #4a3b2b;
  border-radius: 8px;
  font-size: 19px;
  font-weight: bold;
  min-height: 42px;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}
.kana-key:active { background: #fff2e0; border-color: #e08a3c; }
.kana-key-empty { border: none; background: none; }
.kana-mods {
  display: flex;
  gap: 8px;
  width: 100%;
}
.kana-mod {
  flex: 1 1 0;
  border: 2px solid #ece1d0;
  background: #f7f1e6;
  color: #4a3b2b;
  border-radius: 10px;
  font-size: 18px;
  font-weight: bold;
  min-height: 48px;
  cursor: pointer;
  font-family: inherit;
}
.kana-mod:active { background: #ece1d0; }
.kana-mod-delete { flex: 1.4 1 0; font-size: 15px; }
.kana-message {
  font-size: 14px;
  min-height: 20px;
  color: #b3541e;
}
.kana-pad .completion-btn { width: 100%; }

/* ---------- 正解画面: 自分が書いた答え ---------- */
.answer-written {
  background: #faf6f0;
  border-radius: 12px;
  padding: 10px;
}
.answer-written-label { font-size: 12px; color: #8a7869; margin-bottom: 6px; }
.answer-written-image {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border: 1px solid #ece1d0;
  border-radius: 8px;
  background: #ffffff;
}
.answer-written-reading { font-size: 26px; font-weight: bold; color: #4a3b2b; }
.answer-written-wrong { color: #b3541e; text-decoration: line-through; }

.notice {
  background: #fff6df;
  border: 1px solid #f2dfa0;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.7;
  color: #6b5116;
}

/* ---------- 正解画面（答えあわせカード） ---------- */
.answer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}
.answer-overlay.hidden { display: none; }
.answer-card {
  background: #ffffff;
  border-radius: 22px;
  padding: 24px;
  width: min(360px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  animation: pop-in 0.25s ease-out;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@keyframes pop-in {
  0%   { transform: scale(0.92); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}
.answer-badge {
  font-size: 20px;
  font-weight: bold;
  border-radius: 999px;
  padding: 6px 0;
}
.answer-badge-correct { color: #227a4e; background: #eafaf1; }
.answer-badge-wrong { color: #b3541e; background: #fff2ea; }

.answer-kanji-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 150px;
}
.answer-kanji {
  font-size: 110px;
  line-height: 1;
  color: #4a3b2b;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
}
.answer-stroke-order {
  width: 150px;
  height: 150px;
  border: 2px solid #ece1d0;
  border-radius: 12px;
  background: #fffdfa;
}
.stroke-order-stroke {
  fill: none;
  stroke: #4a3b2b;
  stroke-width: 5.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.stroke-order-guide {
  stroke: #f0e6d6;
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.answer-reading { font-size: 20px; font-weight: bold; color: #4a3b2b; }
.answer-sentence { font-size: 15px; }
.answer-sentence .sentence { font-size: 18px; }
.answer-meaning { font-size: 14px; color: #6b5b4a; }
.answer-trivia {
  text-align: left;
  font-size: 13.5px;
  line-height: 1.5;
  color: #6b5116;
  background: #fff6df;
  border: 1px solid #f2dfa0;
  border-radius: 12px;
  padding: 10px 12px;
}

/* ---------- 結果画面 ---------- */
.completion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}
.completion-overlay.hidden { display: none; }
.completion-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 28px;
  text-align: center;
  width: min(360px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  animation: pop-in 0.3s ease-out;
}
.completion-title { font-size: 24px; font-weight: bold; color: #4a3b2b; margin-bottom: 8px; }
.completion-sub { font-size: 16px; color: #6b5b4a; margin-bottom: 16px; }
.result-wrong-heading { font-size: 13px; color: #a3958a; margin-bottom: 8px; text-align: left; }
.result-wrong-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.result-wrong-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: #4a3b2b;
}
.result-wrong-kanji {
  font-size: 30px;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
}
.result-wrong-reading { font-size: 11px; color: #8a7869; }
.completion-buttons { display: flex; flex-direction: column; gap: 10px; }
.completion-btn {
  border: none;
  border-radius: 14px;
  padding: 14px;
  font-size: 16px;
  font-weight: bold;
  color: #ffffff;
  background: #e08a3c;
  cursor: pointer;
  font-family: inherit;
}
.completion-btn-secondary { background: #f7f1e6; color: #4a3b2b; }
.completion-btn-wrong { background: #ff9f5a; }

/* ---------- せってい画面 ---------- */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 20, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2100;
}
.settings-overlay.hidden { display: none; }
.settings-card {
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -6px 24px rgba(0,0,0,0.25);
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #ece1d0;
  flex: 0 0 auto;
}
.settings-title { font-size: 18px; font-weight: bold; color: #4a3b2b; }
.settings-body { overflow-y: auto; padding: 8px 16px 24px; }
.settings-group { padding: 14px 0; border-bottom: 1px solid #f7f1e6; }
.settings-group-label { font-size: 14px; color: #6b5b4a; margin-bottom: 8px; }
.settings-row { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-option {
  border: 2px solid #ece1d0;
  background: #ffffff;
  color: #4a3b2b;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
  font-family: inherit;
}
.settings-option.active {
  border-color: #e08a3c;
  background: #fff2e0;
  color: #b3541e;
  font-weight: bold;
}
.settings-footer {
  flex: 0 0 auto;
  padding: 12px 16px 20px;
  border-top: 1px solid #f7f1e6;
}
.settings-danger-btn {
  width: 100%;
  border: 2px solid #f2dcc8;
  background: #fff8f2;
  color: #a05a2c;
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.settings-danger-btn:active { background: #fbeee1; }
