:root {
  --ink: #1c1c1c;
  --paper: #faf6ee;
  --paper-card: #fffdf8;
  --accent: #a8321e;
  --accent-soft: #d98c4a;
  --line: #e0d6c2;
  --muted: #8a8272;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Zen Kurenaido", "Hiragino Sans", sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  text-align: center;
  padding: 24px 16px 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 0.15em;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 0 16px 16px;
  flex-wrap: wrap;
}

.tab-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 8px 20px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

main {
  flex: 1;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 0 16px 40px;
}

.panel { display: none; }
.panel.active { display: block; }

.row-select {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 20px;
}

.row-btn {
  border: 1px solid var(--line);
  background: var(--paper-card);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
}

.row-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  color: #fff;
}

.card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 20px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.05);
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card-face { width: 100%; }

.sosho-char {
  font-family: "Yuji Boku", serif;
  font-size: 8rem;
  line-height: 1;
  color: var(--ink);
}

#quizCard .sosho-char { font-size: 7rem; margin-bottom: 8px; }

.kaisho-char {
  margin-top: 10px;
  font-size: 1.3rem;
  color: var(--muted);
}

.hiragana-char {
  margin-top: 16px;
  font-size: 2rem;
  color: var(--accent);
}

.reading {
  margin-top: 10px;
  font-size: 0.95rem;
  color: var(--muted);
}

.progress-bar-wrap {
  margin-top: 20px;
  height: 6px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s;
}

.progress-label {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 6px 0 0;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
  flex-wrap: wrap;
}

button {
  border: 1px solid var(--line);
  background: var(--paper-card);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button:hover { filter: brightness(0.96); }

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.quiz-score { color: var(--muted); font-size: 0.9rem; }

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

.option-btn {
  padding: 18px 10px;
  font-size: 1.6rem;
  border-radius: 12px;
}

.option-btn.correct {
  background: #3f7d4c;
  border-color: #3f7d4c;
  color: #fff;
}

.option-btn.wrong {
  background: #b0453c;
  border-color: #b0453c;
  color: #fff;
}

.quiz-feedback {
  text-align: center;
  margin-top: 14px;
  min-height: 1.4em;
  font-size: 1rem;
}

#quizNextBtn {
  display: block;
  margin: 12px auto 0;
}

.about-content h2 { margin-top: 4px; }

.style-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin: 16px 0;
}

.style-flow .highlight {
  color: var(--accent);
  font-weight: bold;
}

.note {
  font-size: 0.85rem;
  color: var(--muted);
}

#resetBtn {
  margin-top: 12px;
}

footer {
  text-align: center;
  padding: 16px;
  color: var(--muted);
  font-size: 0.8rem;
}

@media (max-width: 420px) {
  .sosho-char { font-size: 6rem; }
  .option-btn { font-size: 1.3rem; }
}

/* ---------- なぞり書き ---------- */
.trace-target-label {
  text-align: center;
  margin-bottom: 12px;
}

#traceKanji {
  font-family: "Yuji Boku", serif;
  font-size: 2.2rem;
  color: var(--accent);
  margin-right: 10px;
}

.trace-sub {
  color: var(--muted);
  font-size: 0.9rem;
}

.trace-stage {
  position: relative;
  width: min(90vw, 520px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background: #fffefb;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  overflow: hidden;
  touch-action: none;
}

.trace-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#guideCanvas { z-index: 1; }
#traceCanvas { z-index: 2; }

.trace-demo-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28,28,28,0.75);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  pointer-events: none;
  z-index: 4;
  transition: opacity 0.3s;
  white-space: nowrap;
}

.trace-demo-hint.hidden { opacity: 0; }

.trace-controls { margin-top: 18px; }
.trace-nav { margin-top: 10px; }

.trace-result {
  margin-top: 20px;
  text-align: center;
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}

.trace-score {
  font-size: 2.6rem;
  font-weight: bold;
  color: var(--accent);
}

.trace-score-label {
  margin-top: 4px;
  color: var(--muted);
}

.trace-stroke-feedback {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.stroke-chip {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  border: 1px solid var(--line);
  background: #fff;
}

.stroke-chip.good { background: #e4f2e7; border-color: #3f7d4c; color: #2c5a37; }
.stroke-chip.mid { background: #fbead2; border-color: #d98c4a; color: #8a5620; }
.stroke-chip.bad { background: #f7e1de; border-color: #b0453c; color: #7a2c22; }
