/* ============================================================
   ひらがな なぞりがき - スタイル
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --accent: #FF8C00;
  --bg: #FFF9F0;
  --card: #FFFFFF;
  --text: #333333;
  --muted: #888888;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(0,0,0,0.10);
}

html, body {
  height: 100%;
  background: var(--bg);
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.hidden { display: none !important; }

/* ============================================================
   文字選択画面
   ============================================================ */
#select-screen {
  /* グリッドが縦にもはみ出さないよう幅を計算
     他要素の合計高さ≈240px、グリッドの縦横比＝11/5=2.2 */
  --grid-w: min(calc(100vw - 32px), calc((100svh - 240px) * 2.2));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 32px;
  min-height: 100svh;
}

#select-screen h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 16px;
  letter-spacing: 0.05em;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  padding: 8px 28px;
  border: 2px solid #E0D8CC;
  border-radius: 999px;
  background: var(--card);
  font-size: 1rem;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

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

.char-grid {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  grid-template-columns: repeat(11, 1fr);
  grid-auto-flow: column;
  direction: rtl;
  gap: calc(var(--grid-w) * 0.012);
  width: var(--grid-w);
}

#reset-btn {
  margin-top: 20px;
  background: none;
  border: 1px solid #CCC;
  border-radius: 10px;
  padding: 8px 20px;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
}

#reset-btn:active {
  background: #EEE;
}

.char-btn {
  background: var(--card);
  border: 2px solid #E0D8CC;
  border-radius: calc(var(--grid-w) / 11 * 0.15);
  font-size: calc(var(--grid-w) / 11 * 0.45);
  aspect-ratio: 1;
  padding: 0;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s, background 0.12s;
  color: var(--text);
}

.char-btn:active {
  transform: scale(0.92);
  background: #FFF0D8;
  border-color: var(--accent);
}

.char-btn--done {
  background: #E8F5E9;
  border-color: #4CAF50;
  color: #2E7D32;
  position: relative;
}

.char-btn--done::after {
  content: '✓';
  position: absolute;
  top: 2px;
  right: 5px;
  font-size: 0.65rem;
  color: #4CAF50;
  font-weight: 700;
}

/* ============================================================
   練習画面
   ============================================================ */
#practice-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  min-height: 100vh;
  gap: 16px;
}

.practice-header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(92vw, calc(100svh - 240px));
}

#back-btn {
  background: #EEE;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
  color: #555;
  flex-shrink: 0;
}

#back-btn:active {
  background: #DDD;
}

#current-char {
  font-size: 3rem;
  font-weight: 700;
  color: var(--accent);
  flex: 1;
  text-align: center;
}

#stroke-info {
  font-size: 1rem;
  color: var(--muted);
  flex-shrink: 0;
  min-width: 80px;
  text-align: right;
}

/* Canvas コンテナ */
.canvas-container {
  position: relative;
  width: min(92vw, calc(100svh - 240px));
  height: min(92vw, calc(100svh - 240px));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #FFFFFF;
  overflow: hidden;
}

#guide-canvas,
#draw-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#draw-canvas {
  z-index: 2;
}

/* ============================================================
   ボタンエリア
   ============================================================ */
.controls {
  display: flex;
  gap: 12px;
  width: min(92vw, calc(100svh - 240px));
}

.controls button {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.1s, opacity 0.1s;
}

.controls button:active {
  transform: scale(0.95);
  opacity: 0.85;
}

#clear-btn {
  background: #EEE;
  color: #555;
}

#next-char-btn {
  background: var(--accent);
  color: #FFF;
}

/* ============================================================
   完了メッセージ
   ============================================================ */
#success-message {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 100;
  animation: pop-in 0.3s ease;
}

#success-message span {
  background: #4CAF50;
  color: #FFF;
  font-size: 2.2rem;
  font-weight: 700;
  padding: 24px 48px;
  border-radius: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.20);
  letter-spacing: 0.08em;
}

@keyframes pop-in {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ============================================================
   凡例（色説明）
   ============================================================ */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ============================================================
   レスポンシブ調整（小さい画面）
   ============================================================ */
@media (max-width: 440px) {
  .canvas-container {
    width: 92vw;
    height: 92vw;
  }

  #current-char {
    font-size: 2.4rem;
  }

}
