/* ============================================
   ひらがな なぞりあそび — スタイルシート
   ============================================ */

/* --- リセット & 基本設定 --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  font-family: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'Rounded Mplus 1c', sans-serif;
  background: linear-gradient(150deg, #FFF8E7 0%, #FFE8F0 50%, #E8F4FF 100%);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* --- ひろばに戻るボタン --- */
.btn-back-hub {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #2C3E50;
  background: rgba(255, 255, 255, 0.85);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  text-decoration: none;
  font-family: inherit;
  touch-action: manipulation;
  transition: transform 0.12s, box-shadow 0.12s;
}

.btn-back-hub:active {
  transform: scale(0.95);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* --- アプリコンテナ --- */
.app-container {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* --- 画面共通 --- */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 16px 20px;
  min-height: 100dvh;
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===================================
   ホーム画面
   =================================== */
.home-title {
  font-size: 2.4em;
  font-weight: 900;
  color: #2C3E50;
  text-align: center;
  margin-top: 15vh;
  line-height: 1.4;
}

.home-subtitle {
  font-size: 1.05em;
  color: #8E99A4;
  margin-top: 8px;
}

.home-mascot {
  font-size: 96px;
  margin: 36px 0;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-14px); }
}

.btn-play {
  background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
  color: #fff;
  border: none;
  padding: 18px 64px;
  font-size: 1.7em;
  font-weight: 900;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(255, 107, 107, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
  font-family: inherit;
  letter-spacing: 0.05em;
}

.btn-play:active {
  transform: scale(0.94);
  box-shadow: 0 3px 12px rgba(255, 107, 107, 0.35);
}

/* ===================================
   もじ選択画面
   =================================== */
.select-header {
  width: 100%;
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  margin-top: 16px;
}

.btn-back {
  background: none;
  border: none;
  font-size: 1.4em;
  cursor: pointer;
  padding: 10px 12px;
  color: #2C3E50;
  border-radius: 12px;
  transition: background 0.15s;
}

.btn-back:active {
  background: rgba(0,0,0,0.05);
}

.select-title {
  font-size: 1.45em;
  font-weight: 700;
  color: #2C3E50;
  margin-left: 6px;
}

.row-label {
  font-size: 1em;
  font-weight: 700;
  color: #95A5A6;
  margin-bottom: 16px;
  letter-spacing: 0.1em;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 340px;
}

.char-card {
  aspect-ratio: 1;
  background: #fff;
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 2.6em;
  font-weight: 900;
  color: #2C3E50;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.07);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  border: 3px solid transparent;
}

.char-card:active {
  transform: scale(0.95);
}

.char-card.completed {
  border-color: #2ECC71;
  background: linear-gradient(135deg, #F0FFF4, #E8FCF1);
}

.char-card.current {
  border-color: #4ECDC4;
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(78, 205, 196, 0.15); }
  50%      { box-shadow: 0 4px 28px rgba(78, 205, 196, 0.45); }
}

.char-card-star {
  position: absolute;
  bottom: 8px;
  font-size: 0.35em;
  letter-spacing: 2px;
}

/* ===================================
   なぞり画面
   =================================== */
.trace-screen {
  padding-top: max(20px, 4vh);
}

.trace-top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.trace-char-display {
  text-align: center;
  margin: 4px 0 10px;
}

.trace-example {
  font-size: 2.2em;
  font-weight: 700;
  color: #2C3E50;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  line-height: 1.4;
}

.trace-emoji {
  font-size: 1.15em;
}

.highlight-char {
  color: #FF6B6B;
  text-decoration: underline;
  text-decoration-color: #FF6B6B;
  text-underline-offset: 6px;
  text-decoration-thickness: 3px;
  font-weight: 900;
}

.trace-stroke-info {
  font-size: 0.95em;
  color: #95A5A6;
  font-weight: 700;
  background: rgba(0,0,0,0.04);
  padding: 6px 14px;
  border-radius: 20px;
}

/* --- キャンバス --- */
.canvas-wrapper {
  position: relative;
  width: calc(100vw - 32px);
  max-width: 420px;
  aspect-ratio: 1;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
  overflow: hidden;
  border: 3px solid #F0EBE3;
}

.canvas-wrapper canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#canvas-draw {
  cursor: crosshair;
}

/* --- ブブー！シェイクアニメーション --- */
.canvas-wrapper.shake {
  animation: shake 0.45s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%      { transform: translateX(-8px); }
  20%      { transform: translateX(8px); }
  30%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  50%      { transform: translateX(-4px); }
  60%      { transform: translateX(4px); }
  70%      { transform: translateX(-2px); }
  80%      { transform: translateX(2px); }
  90%      { transform: translateX(-1px); }
}

/* --- ボタン群 --- */
.trace-buttons {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-trace {
  background: #fff;
  border: 2px solid #E0E0E0;
  padding: 12px 22px;
  font-size: 1.05em;
  font-weight: 700;
  border-radius: 16px;
  cursor: pointer;
  color: #2C3E50;
  font-family: inherit;
  transition: transform 0.12s, box-shadow 0.12s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-trace:active {
  transform: scale(0.95);
}

.btn-icon {
  font-size: 0.9em;
}

.btn-trace.primary {
  background: linear-gradient(135deg, #4ECDC4, #44B8B0);
  color: #fff;
  border: none;
  box-shadow: 0 4px 16px rgba(78, 205, 196, 0.3);
}

.btn-trace.primary:active {
  box-shadow: 0 2px 8px rgba(78, 205, 196, 0.3);
}

.btn-trace.danger {
  border-color: #FFB3B3;
  color: #FF6B6B;
}

/* ===================================
   けっか画面
   =================================== */
.result-screen {
  justify-content: center;
}

.result-char {
  font-size: 5em;
  font-weight: 900;
  color: #2C3E50;
  margin-bottom: 12px;
  animation: resultPop 0.5s ease;
}

@keyframes resultPop {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.result-stars {
  font-size: 3em;
  margin-bottom: 16px;
  animation: starPop 0.6s ease 0.2s both;
}

@keyframes starPop {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; }
  60%  { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.result-message {
  font-size: 1.5em;
  font-weight: 700;
  color: #2C3E50;
  margin-bottom: 28px;
  animation: fadeIn 0.4s ease 0.5s both;
}

.result-buttons {
  display: flex;
  gap: 14px;
  animation: fadeIn 0.4s ease 0.7s both;
}

.result-buttons .btn-trace {
  padding: 14px 28px;
  font-size: 1.15em;
}

/* ===================================
   レスポンシブ
   =================================== */
@media (max-width: 360px) {
  .home-title {
    font-size: 2em;
  }
  .btn-play {
    padding: 16px 48px;
    font-size: 1.5em;
  }
  .char-grid {
    gap: 10px;
  }
  .char-card {
    font-size: 2.2em;
    border-radius: 18px;
  }
  .trace-buttons {
    gap: 8px;
  }
  .btn-trace {
    padding: 10px 16px;
    font-size: 0.95em;
  }
}

@media (min-height: 800px) {
  .home-title {
    margin-top: 20vh;
  }
  .trace-screen {
    padding-top: max(20px, 3vh);
  }
  .trace-char-display {
    margin: 8px 0 14px;
  }
}
