:root {
  --font-kyokasho: "YuKyokasho", "YuKyokasho Yoko",
    "UD デジタル 教科書体 N-R", "UD Digi Kyokasho N-R", "UD Digi Kyokasho NK-R",
    "Klee One", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --bg: #faf7f0;
  --card: #ffffff;
  --ink: #33302a;
  --sub: #8a8478;
  --line: #e4ddd0;
  --primary: #3b6ea5;
  --primary-dark: #2f5885;
  --accent: #c9662a;
  --correct: #2e9e5b;
  --wrong: #d43d3d;
  --answer-red: rgba(200, 30, 30, 0.62);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

h1 { font-size: 1.5rem; text-align: center; margin: 12px 0 20px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }

.app-title { letter-spacing: 0.08em; }


.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-head h2 { margin: 0; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 1rem;
  min-height: 44px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }
.btn.big { width: 100%; font-size: 1.1rem; padding: 14px; }
.btn.primary { background: var(--primary); border-color: var(--primary-dark); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: #fff; border-color: var(--wrong); color: var(--wrong); }
.btn:disabled { opacity: 0.45; cursor: default; }

.setup-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 4px 10px;
}


.level-actions { display: flex; gap: 8px; }

.level-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.level-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.level-item:has(input:checked) {
  border-color: var(--primary);
  background: #eef4fb;
}
.level-item input { width: 18px; height: 18px; accent-color: var(--primary); }
.level-item .lv-name { font-weight: 600; }
.level-item .lv-sub { font-size: 0.72rem; color: var(--sub); display: block; }
.level-item.empty { opacity: 0.45; }

.count-options { display: flex; gap: 8px; }
.count-option {
  flex: 1;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 0;
  cursor: pointer;
  user-select: none;
}
.count-option:has(input:checked) {
  border-color: var(--primary);
  background: #eef4fb;
  font-weight: 600;
}
.count-option input { position: absolute; opacity: 0; }


.practice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.progress { font-size: 0.95rem; color: var(--sub); font-variant-numeric: tabular-nums; }

.sentence {
  font-family: var(--font-kyokasho);
  font-size: clamp(1.4rem, 5.5vw, 2.1rem);
  line-height: 1.9;
  text-align: center;
  min-height: 3.2em;
  padding: 10px 8px 4px;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.sentence .target {
  display: inline-block;
  position: relative;
  vertical-align: -0.12em;
}

.sentence .target .rt {
  position: absolute;
  bottom: calc(100% + 0.18em);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.45em;
  line-height: 1;
  white-space: nowrap;
  color: var(--accent);
  font-weight: 600;
}

.sentence .box {
  display: block;
  width: 1em;
  height: 1em;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: #fff;
}


.pad-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.pad-container {
  position: relative;
  width: min(82vw, 48vh, 380px);
  aspect-ratio: 1 / 1;
  background: #fff;
  border: 3px solid #b9b2a4;
  border-radius: 8px;
  overflow: hidden;
}

.pad-guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.pad-guide line {
  stroke: #c9c2b4;
  stroke-width: 1;
  stroke-dasharray: 2.5 2.5;
  vector-effect: non-scaling-stroke;
}

#pad {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.answer-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-kyokasho);
  color: var(--answer-red);
  pointer-events: none;
  user-select: none;
  line-height: 1;
}

.judge-mark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  user-select: none;
  opacity: 0.9;
}
.judge-mark svg { width: 80%; height: 80%; display: block; }
.judge-mark.correct { color: var(--correct); }
.judge-mark.wrong { color: var(--wrong); }
.judge-mark.pop { animation: judge-pop 0.35s ease-out; }
@keyframes judge-pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 0.9; }
}

.practice-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}


.grade-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.check-btn {
  min-width: 170px;
  font-size: 1.15rem;
  padding: 14px 24px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  will-change: transform;
}
.check-btn.dragging { transition: none; }

.drag-hint {
  font-size: 1rem;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s, transform 0.15s;
  user-select: none;
}
.drag-hint.left { color: var(--wrong); }
.drag-hint.right { color: var(--correct); }
.grade-area.revealed .drag-hint { opacity: 0.45; }
.grade-area.revealed .drag-hint.active { opacity: 1; transform: scale(1.25); }

.grade-help {
  text-align: center;
  font-size: 0.78rem;
  color: var(--sub);
  margin: 8px 0 0;
}


.result-summary {
  text-align: center;
  font-size: 1.2rem;
  margin-bottom: 16px;
}
.result-summary .rate { font-size: 2.2rem; font-weight: 700; color: var(--primary); }

.result-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
}
.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
}
.result-item .mark { font-size: 1.4rem; font-weight: 700; width: 1.6em; text-align: center; }
.result-item .mark.correct { color: var(--correct); }
.result-item .mark.wrong { color: var(--wrong); }
.result-item .r-sentence {
  font-family: var(--font-kyokasho);
  font-size: 1.05rem;
  flex: 1;
  line-height: 1.9;
}
.result-item .r-sentence .r-answer { color: #c11e1e; font-weight: 600; }
.result-item .r-level { font-size: 0.72rem; color: var(--sub); white-space: nowrap; }


.stats-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.stats-row .lv { width: 3.4em; font-weight: 600; font-size: 0.9rem; }
.stats-row .bar-track {
  flex: 1;
  height: 14px;
  background: #efe9dd;
  border-radius: 7px;
  overflow: hidden;
}
.stats-row .bar {
  height: 100%;
  background: var(--primary);
  border-radius: 7px;
}
.stats-row .num {
  width: 7em;
  text-align: right;
  font-size: 0.8rem;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
}

.stats-total { font-size: 1rem; line-height: 1.9; }


@media (min-width: 600px) {
  .level-list { grid-template-columns: repeat(3, 1fr); }
}
