/* ==========================================================================
   たのしい！タイピングアドベンチャー - PREMIUM KIDS CSS STYLING
   ========================================================================== */

/* --- Custom Variables & Theme tokens --- */
:root {
  --font-kids: 'Zen Maru Gothic', sans-serif;
  --font-english: 'Outfit', sans-serif;
  
  /* Core Colors */
  --bg-primary: #181524;
  --bg-card: rgba(30, 27, 43, 0.7);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  
  --text-main: #f5f2ff;
  --text-muted: #a39eb8;
  --text-active: #ffffff;
  
  --color-accent: #ff477e;
  --color-accent-glow: rgba(255, 71, 126, 0.4);
  
  /* Color-coded Hand Guide & Finger Keys Mapping */
  --color-pinky: #ff6b8b;      /* Pastel Rose */
  --color-ring: #ffa502;       /* Pastel Orange */
  --color-middle: #ffd12b;     /* Pastel Yellow */
  --color-index-l: #2ed573;    /* Pastel Mint Green */
  --color-index-r: #1e90ff;    /* Pastel Sky Blue */
  --color-thumb: #9c88ff;      /* Pastel Purple */
  
  /* Interface Feedback Colors */
  --color-correct: #2ed573;
  --color-incorrect: #ff4757;
  
  --transition-smooth: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  --transition-fast: all 0.1s ease;
  
  --shadow-premium: 0 12px 40px rgba(0, 0, 0, 0.3);
  --blur-glass: 16px;
}

/* --- Base Setup --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: var(--font-kids);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
}

/* --- Background Glowing Ambient Lights --- */
.bg-glow {
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  opacity: 0.25;
  pointer-events: none;
}

.bg-glow-1 {
  background: radial-gradient(circle, #70a1ff 0%, transparent 70%);
  top: -100px;
  left: -100px;
}

.bg-glow-2 {
  background: radial-gradient(circle, #ff6b8b 0%, transparent 70%);
  bottom: -100px;
  right: -100px;
}

/* --- Invisible input bridge for iPad --- */
#keyboard-bridge {
  position: absolute;
  top: -100px;
  left: -100px;
  width: 10px;
  height: 10px;
  opacity: 0;
  pointer-events: none;
  z-index: -999;
}

/* --- Main Layout Grid --- */
.app-container {
  width: 100vw;
  height: 100vh;
  max-width: 1200px;
  max-height: 800px;
  display: grid;
  grid-template-rows: 70px 1.1fr 0.9fr 1.3fr;
  gap: 12px;
  padding: 12px;
  position: relative;
}

/* Glassmorphism Panel Base */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(var(--blur-glass));
  -webkit-backdrop-filter: blur(var(--blur-glass));
  border: 1px solid var(--bg-card-border);
  border-radius: 20px;
  box-shadow: var(--shadow-premium);
  padding: 16px;
  overflow: hidden;
}

/* --- Header Component --- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  background: rgba(30, 27, 43, 0.8);
  border-bottom: 1px solid var(--bg-card-border);
  border-radius: 18px;
}

.logo-title {
  font-size: 1.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, #ffa502, #ff6b8b, #1e90ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  letter-spacing: 1px;
}

.stats-panel {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 6px 14px;
  border-radius: 50px;
  font-family: var(--font-english);
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: var(--transition-smooth);
}

.avatar-select-trigger {
  cursor: pointer;
}
.avatar-select-trigger:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

.avatar-icon {
  font-size: 1.3rem;
}

.stat-label {
  font-family: var(--font-kids);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.lives-container {
  letter-spacing: 2px;
}

.heart {
  display: inline-block;
  font-size: 1.2rem;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.heart.lost {
  transform: scale(0);
  opacity: 0.2;
}

.util-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
}

.util-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.1);
}

/* --- Game Stage: Main Workspace Split --- */
.game-stage {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 12px;
}

/* Left Side: Avatar Character */
.stage-left {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  background: linear-gradient(180deg, rgba(30, 27, 43, 0.6) 0%, rgba(47, 41, 69, 0.6) 100%);
}

.character-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.avatar-sprite {
  font-size: 6rem;
  position: relative;
  width: 140px;
  height: 140px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  transition: var(--transition-smooth);
}

.avatar-sprite.idle {
  animation: float 3s ease-in-out infinite;
}

.avatar-sprite.correct-jump {
  animation: bounce-joy 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.avatar-sprite.wrong-dizzy {
  animation: shake-dizzy 0.5s ease-in-out;
}

.avatar-shadow {
  position: absolute;
  bottom: -15px;
  width: 80px;
  height: 8px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 50%;
  filter: blur(2px);
  animation: shadow-float 3s ease-in-out infinite;
}

.avatar-speech {
  background: #ffffff;
  color: #333333;
  padding: 8px 16px;
  border-radius: 16px;
  font-weight: 700;
  font-size: 0.95rem;
  position: relative;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
  max-width: 200px;
  text-align: center;
  margin-top: 10px;
  transition: var(--transition-smooth);
}

.avatar-speech::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 0 10px 10px;
  border-style: solid;
  border-color: #ffffff transparent;
  display: block;
  width: 0;
}

/* Right Side: Typing Word Display Card */
.stage-right {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 24px;
}

.word-card {
  text-align: center;
  width: 100%;
  max-width: 500px;
}

.kana-display {
  font-size: 3.2rem;
  font-weight: 900;
  color: #ffd12b;
  margin-bottom: 8px;
  letter-spacing: 4px;
  text-shadow: 0 4px 12px rgba(255, 209, 43, 0.25);
  animation: pop-in-word 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.romaji-display {
  font-family: var(--font-english);
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: lowercase;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 24px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.romaji-display span {
  display: inline-block;
}

.romaji-display .typed {
  color: var(--text-muted);
  opacity: 0.35;
}

.romaji-display .current {
  color: #ff477e;
  border-bottom: 4px solid #ff477e;
  padding-bottom: 2px;
  font-size: 3.2rem;
  font-weight: 900;
  text-shadow: 0 0 15px rgba(255, 71, 126, 0.6);
  animation: pulse-current-letter 0.8s ease-in-out infinite alternate;
}

.romaji-display .upcoming {
  color: var(--text-main);
  opacity: 0.95;
}

.word-illustration-panel {
  position: absolute;
  right: 24px;
  bottom: 24px;
  font-size: 3.5rem;
  opacity: 0.85;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.2));
  animation: float 2.5s ease-in-out infinite alternate;
}

/* --- Control Levels Bar --- */
.levels-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
}

.level-btn-group {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none; /* Hide scrollbar for clean UI */
}
.level-btn-group::-webkit-scrollbar {
  display: none;
}

.level-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 6px 14px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-kids);
  font-weight: 700;
  transition: var(--transition-smooth);
}

.level-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.level-btn.active {
  background: linear-gradient(135deg, #ff477e, #ff6b8b);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 15px var(--color-accent-glow);
}

.level-num {
  font-family: var(--font-english);
  font-size: 1.1rem;
  background: rgba(0, 0, 0, 0.2);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-settings {
  display: flex;
  align-items: center;
}

.mode-toggle-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 14px;
  border-radius: 50px;
  font-size: 0.85rem;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.mini-btn {
  background: linear-gradient(135deg, #ff477e, #ff6b8b);
  border: none;
  color: #fff;
  border-radius: 20px;
  padding: 4px 12px;
  font-family: var(--font-kids);
  font-weight: 900;
  cursor: pointer;
  font-size: 0.85rem;
  margin-left: 6px;
  transition: var(--transition-fast);
  box-shadow: 0 2px 4px rgba(255, 71, 126, 0.3);
}
.mini-btn:hover {
  transform: scale(1.05);
  background: linear-gradient(135deg, #ff6b8b, #ff85a2);
  box-shadow: 0 4px 8px rgba(255, 71, 126, 0.5);
}

/* --- Keyboard & Hands Visual Guide --- */
.visual-guide {
  display: grid;
  grid-template-columns: 1fr;
  align-content: center;
  padding: 8px 12px;
}

.guide-wrapper {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.keyboard-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  max-width: 780px;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  width: 100%;
}

.key {
  position: relative;
  height: 36px; /* Reduced to fit perfectly without cut-offs */
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: var(--text-main);
  font-family: var(--font-english);
  font-weight: 900;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 4px; /* Balanced lifting of letters */
  cursor: pointer;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, background 0.15s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
  flex-grow: 1;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
}

/* Keyboard touch mode key styling */
.touch-mode .key {
  cursor: pointer;
}
.touch-mode .key:active {
  transform: translateY(3px) scale(0.96);
}

/* Key proportions */
.letter-key {
  max-width: 65px;
}
.num-key {
  max-width: 60px;
}
.space-key {
  max-width: 320px;
  font-family: var(--font-kids);
  font-size: 0.9rem;
}

/* Color-coded Finger mappings on QWERTY Keys (Bubbly Marshmallow Style) */
.finger-left-pinky {
  background: rgba(255, 107, 139, 0.12) !important;
  border-color: rgba(255, 107, 139, 0.25) !important;
  border-bottom: 4px solid var(--color-pinky) !important;
}
.finger-left-ring {
  background: rgba(255, 165, 2, 0.12) !important;
  border-color: rgba(255, 165, 2, 0.25) !important;
  border-bottom: 4px solid var(--color-ring) !important;
}
.finger-left-middle {
  background: rgba(255, 209, 43, 0.12) !important;
  border-color: rgba(255, 209, 43, 0.25) !important;
  border-bottom: 4px solid var(--color-middle) !important;
}
.finger-left-index {
  background: rgba(46, 213, 115, 0.12) !important;
  border-color: rgba(46, 213, 115, 0.25) !important;
  border-bottom: 4px solid var(--color-index-l) !important;
}

.finger-right-pinky {
  background: rgba(255, 107, 139, 0.12) !important;
  border-color: rgba(255, 107, 139, 0.25) !important;
  border-bottom: 4px solid var(--color-pinky) !important;
}
.finger-right-ring {
  background: rgba(255, 165, 2, 0.12) !important;
  border-color: rgba(255, 165, 2, 0.25) !important;
  border-bottom: 4px solid var(--color-ring) !important;
}
.finger-right-middle {
  background: rgba(255, 209, 43, 0.12) !important;
  border-color: rgba(255, 209, 43, 0.25) !important;
  border-bottom: 4px solid var(--color-middle) !important;
}
.finger-right-index {
  background: rgba(30, 144, 255, 0.12) !important;
  border-color: rgba(30, 144, 255, 0.25) !important;
  border-bottom: 4px solid var(--color-index-r) !important;
}

.finger-thumb {
  background: rgba(156, 136, 255, 0.12) !important;
  border-color: rgba(156, 136, 255, 0.25) !important;
  border-bottom: 4px solid var(--color-thumb) !important;
}

/* Home keys visual anchors (f, j, a, ;) */
.home-key::before {
  content: '';
  position: absolute;
  bottom: 5px;
  width: 14px;
  height: 2px;
  background: var(--text-muted);
  opacity: 0.6;
}

/* Tactile bumps specifically for pointer fingers (F & J) */
.key[data-key="f"]::after,
.key[data-key="j"]::after {
  content: '';
  position: absolute;
  bottom: 4px;
  width: 18px;
  height: 3px;
  background: #ffdf40; /* Yellow golden neon bump */
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(255, 223, 64, 0.8);
  animation: pulse-bump 1.5s infinite alternate;
}

@keyframes pulse-bump {
  0% { box-shadow: 0 0 3px rgba(255, 223, 64, 0.4); opacity: 0.8; }
  100% { box-shadow: 0 0 10px rgba(255, 223, 64, 1); opacity: 1; }
}

/* Highlights for keys on active inputs */
.key.active-target {
  background: var(--color-accent) !important;
  color: #fff !important;
  border-color: #fff !important;
  border-bottom-width: 4px !important;
  border-bottom-color: rgba(0, 0, 0, 0.35) !important;
  box-shadow: 0 0 20px var(--color-accent-glow), 0 4px 6px rgba(0, 0, 0, 0.3);
  transform: scale(1.08) translateY(-2px);
  animation: key-pulse-active 0.6s ease-in-out infinite alternate;
  z-index: 10;
}

.key.key-pressed {
  transform: translateY(3px) scale(0.96) !important;
  border-bottom-width: 1px !important;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0,0,0,0.1) !important;
}

/* --- Hands Guide SVGs --- */
.hand-svg {
  width: 140px; /* Scaled up from 105px */
  height: 140px; /* Scaled up from 105px */
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: var(--transition-smooth);
  flex-shrink: 0;
}

.hand-svg svg {
  width: 120px; /* Scaled up from 85px */
  height: 120px; /* Scaled up from 85px */
}

.hand-palm {
  fill: #1e1b29; /* Opaque solid color matching the dark panel background to block background grids */
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 2px;
  transition: var(--transition-smooth);
}

.finger {
  fill: #2f2a47; /* Opaque solid cute gray-lavender to block joint overlaps */
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 2px;
  transition: var(--transition-smooth);
}

/* Color Coding for Active Fingers inside SVG */
.finger.active-left-pinky, .finger.active-right-pinky {
  fill: var(--color-pinky);
  stroke: #ffffff;
}

.finger.active-left-ring, .finger.active-right-ring {
  fill: var(--color-ring);
  stroke: #ffffff;
}

.finger.active-left-middle, .finger.active-right-middle {
  fill: var(--color-middle);
  stroke: #ffffff;
}

.finger.active-left-index {
  fill: var(--color-index-l);
  stroke: #ffffff;
}

.finger.active-right-index {
  fill: var(--color-index-r);
  stroke: #ffffff;
}

.finger.active-thumb {
  fill: var(--color-thumb);
  stroke: #ffffff;
}

.hand-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 4px;
}

/* --- Overlays & Screen Dialogs --- */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(12, 10, 19, 0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Start / Splash screen panel */
.start-card {
  max-width: 650px;
  width: 90%;
  padding: 36px;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  animation: pop-in 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.start-title {
  font-size: 2.2rem;
  font-weight: 900;
  background: linear-gradient(135deg, #ffd12b, #ff477e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}

.start-desc {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 24px;
}

/* Character Customization Grid */
.avatar-selection-grid {
  margin-bottom: 20px;
}

.avatar-selection-grid h3, .mode-selection-box h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-main);
  text-align: left;
}

.avatar-options {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap; /* Wrap allowed for more avatars! */
}

.avatar-opt {
  min-width: 80px; /* Responsive sizing */
  flex: 1 1 calc(16.66% - 12px);
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  padding: 12px;
  cursor: pointer;
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.avatar-opt:hover {
  background: rgba(255, 255, 255, 0.07);
  transform: translateY(-4px);
}

.avatar-opt.active {
  background: rgba(255, 71, 126, 0.1);
  border-color: var(--color-accent);
  box-shadow: 0 8px 20px rgba(255, 71, 126, 0.2);
}

.avatar-preview {
  font-size: 2.8rem;
  width: 65px;
  height: 65px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  transition: var(--transition-smooth);
}

.avatar-opt:hover .avatar-preview {
  transform: scale(1.1);
}

.avatar-opt span {
  font-weight: 700;
  font-size: 0.9rem;
}

/* Game mode selector */
.mode-selection-box {
  margin-bottom: 28px;
}

.mode-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mode-opt-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  padding: 14px 20px;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  text-align: left;
  gap: 16px;
  transition: var(--transition-smooth);
  width: 100%;
}

.mode-opt-btn:hover {
  background: rgba(255, 255, 255, 0.07);
}

.mode-opt-btn.active {
  background: rgba(30, 144, 255, 0.12);
  border-color: #1e90ff;
  box-shadow: 0 8px 25px rgba(30, 144, 255, 0.2);
}

.mode-opt-btn .btn-emoji {
  font-size: 2.2rem;
}

.mode-opt-btn .btn-text {
  display: flex;
  flex-direction: column;
}

.mode-opt-btn .btn-text strong {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.mode-opt-btn .btn-text span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Button aesthetics */
.primary-btn {
  background: linear-gradient(135deg, #ff477e 0%, #ff6b8b 100%);
  border: none;
  border-radius: 50px;
  color: #fff;
  font-family: var(--font-kids);
  font-weight: 900;
  font-size: 1.3rem;
  padding: 14px 40px;
  cursor: pointer;
  transition: var(--transition-smooth);
  box-shadow: 0 10px 25px var(--color-accent-glow);
}

.primary-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 15px 30px rgba(255, 71, 126, 0.5);
}

.primary-btn:active {
  transform: translateY(1px) scale(0.98);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50px;
  color: var(--text-main);
  font-family: var(--font-kids);
  font-weight: 700;
  font-size: 1.1rem;
  padding: 12px 30px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Clear Screen Card & Modal */
.clear-card, .gameover-card {
  max-width: 500px;
  width: 90%;
  padding: 32px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.star-animation-container {
  font-size: 4rem;
  margin-bottom: 12px;
  letter-spacing: 12px;
  display: flex;
  justify-content: center;
  animation: star-glow 1.5s ease-in-out infinite alternate;
}

.rainbow-text {
  font-size: 2.2rem;
  font-weight: 900;
  background: linear-gradient(90deg, #ff4757, #ffa502, #2ed573, #1e90ff, #9c88ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.clear-stats {
  display: flex;
  gap: 16px;
  margin: 20px 0 28px 0;
  background: rgba(0, 0, 0, 0.2);
}

.clear-stat-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px;
}

.clear-stat-lbl {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.clear-stat-box strong {
  font-size: 1.3rem;
  font-family: var(--font-english);
}

.clear-btns {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.clear-btns .btn {
  width: 100%;
  max-width: 320px;
  white-space: nowrap;
  text-align: center;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.gameover-avatar-emoji {
  font-size: 5rem;
  margin-bottom: 16px;
  animation: float 2s infinite alternate;
}

/* --- Helper Classes & Animations --- */
.text-center { text-align: center; }

@keyframes float {
  0% { transform: translateY(0px); }
  100% { transform: translateY(-8px); }
}

@keyframes shadow-float {
  0% { transform: scale(1); opacity: 0.4; }
  100% { transform: scale(0.8); opacity: 0.2; }
}

@keyframes bounce-joy {
  0%, 100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-30px) scale(0.9, 1.15); }
  50% { transform: translateY(0) scale(1.1, 0.85); }
  75% { transform: translateY(-8px) scale(0.97, 1.03); }
}

@keyframes shake-dizzy {
  0%, 100% { transform: translateX(0) rotate(0); }
  20%, 60% { transform: translateX(-10px) rotate(-5deg); }
  40%, 80% { transform: translateX(10px) rotate(5deg); }
}

@keyframes finger-bounce {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-12px) scale(1, 1.1); }
}

@keyframes pulse-current-letter {
  0% { text-shadow: 0 0 10px rgba(255, 71, 126, 0.5); transform: scale(1); }
  100% { text-shadow: 0 0 25px rgba(255, 71, 126, 0.9); transform: scale(1.15); }
}

@keyframes key-pulse-active {
  0% { box-shadow: 0 0 8px var(--color-accent-glow); }
  100% { box-shadow: 0 0 20px rgba(255, 71, 126, 0.8); }
}

@keyframes star-glow {
  0% { filter: drop-shadow(0 0 5px rgba(255,209,43,0.5)); transform: scale(1); }
  100% { filter: drop-shadow(0 0 20px rgba(255,209,43,0.9)); transform: scale(1.08); }
}

@keyframes pop-in {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes pop-in-word {
  0% { transform: scale(0.85); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- iPad Custom Media Queries (Optimized Viewport Setup) --- */
@media (max-width: 1024px) {
  /* Performance Optimizations for iPad Safari (Smooth 60FPS) */
  .bg-glow {
    display: none !important; /* Hide GPU-heavy ambient blurs */
  }
  
  .glass-panel {
    backdrop-filter: none !important; /* Disable heavy backdrop blur */
    -webkit-backdrop-filter: none !important;
    background: rgba(28, 25, 41, 0.96) !important; /* Solid fallback */
  }
  
  /* GPU Hardware Acceleration triggers */
  .key {
    will-change: transform, background, border-color;
  }
  .finger {
    will-change: fill, stroke;
  }
  .avatar-sprite {
    will-change: transform;
  }

  /* Grid Layout Optimization - Expand Keyboard Space */
  /* Header Layout Optimizations on iPad (Prevent all awkward line wraps!) */
  .app-header {
    padding: 0 8px !important;
    gap: 8px !important;
  }
  
  .logo-title {
    font-size: 1.1rem !important; /* Smaller logo font on iPad to fit */
    white-space: nowrap !important;
  }
  
  .mode-toggle-inline {
    padding: 4px 8px !important;
    gap: 4px !important;
    font-size: 0.7rem !important;
  }
  
  #inline-mode-text {
    font-size: 0.75rem !important;
    white-space: nowrap !important;
  }
  
  .stats-panel {
    gap: 6px !important;
  }
  
  .stat-item {
    padding: 4px 8px !important;
    font-size: 0.85rem !important;
    gap: 4px !important;
  }
  
  .stat-label {
    display: none !important; /* Hide "アバター" text label to save huge horizontal space, keeping the 🐻 emoji */
  }

  .util-btn {
    width: 32px !important;
    height: 32px !important;
    font-size: 1rem !important;
  }

  .app-container {
    max-width: 100%;
    max-height: 100%;
    grid-template-rows: 55px 1.0fr 44px 2.1fr; /* Reduced stage and level bar heights, expanded keyboard to 2.1fr */
    gap: 8px;
    padding: 8px;
  }
  
  .game-stage {
    grid-template-columns: 200px 1fr; /* Narrow character side slightly to maximize typing area */
    gap: 8px;
  }
  
  .avatar-sprite {
    width: 90px;
    height: 90px;
    font-size: 4rem;
  }

  .avatar-speech {
    font-size: 0.85rem;
    padding: 6px 12px;
    margin-top: 6px;
  }
  
  .kana-display {
    font-size: 2.4rem;
    margin-bottom: 4px;
  }
  
  .romaji-display {
    font-size: 2.0rem;
    padding: 6px 18px;
  }
  
  .romaji-display .current {
    font-size: 2.4rem;
  }
  
  /* Level Bar Height Slimming */
  .levels-bar {
    padding: 4px 8px !important;
  }
  
  .level-btn {
    padding: 4px 10px !important;
    font-size: 0.8rem !important;
    border-radius: 8px !important;
  }
  
  .level-num {
    width: 20px !important;
    height: 20px !important;
    font-size: 0.85rem !important;
  }

  .level-title {
    font-size: 0.75rem !important;
  }

  .game-settings #open-editor-btn {
    height: 30px !important;
    font-size: 0.75rem !important;
    padding: 4px 10px !important;
    border-radius: 8px !important;
  }

  /* Keyboard sizing optimization (Enlarge Keys) */
  .key {
    height: 52px !important; /* Doubled height for large tap targets */
    font-size: 1.35rem !important; /* Huge child-friendly text */
    border-radius: 10px !important;
    border-bottom-width: 4px !important;
  }

  .space-key {
    font-size: 1.0rem !important;
  }
  
  .hand-svg {
    width: 100px;
    height: 100px;
    flex-shrink: 0;
  }
  
  .hand-svg svg {
    width: 85px;
    height: 85px;
  }

  .hand-label {
    font-size: 0.7rem;
    margin-top: 2px;
  }
}

/* iPad Portrait Orientation Safety Catch */
@media (max-width: 768px) and (orientation: portrait) {
  body::before {
    content: "📱 がめんを よこむきに してあそんでね！";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #181524;
    color: #ffd12b;
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
    z-index: 9999;
  }
  .app-container {
    display: none;
  }
}

/* ==========================================================================
   指定文字練習（ことばエディタ）追加スタイル
   ========================================================================== */

.editor-card {
  max-width: 500px;
  width: 90%;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.editor-title {
  font-size: 1.6rem;
  font-weight: 900;
  background: linear-gradient(135deg, #2ed573, #1e90ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
}

.editor-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  margin-top: -8px;
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
}

.form-group input[type="text"] {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text-main);
  font-family: var(--font-kids);
  font-size: 1rem;
  font-weight: 700;
  outline: none;
  transition: var(--transition-fast);
}

.form-group input[type="text"]:focus {
  border-color: #2ed573;
  box-shadow: 0 0 8px rgba(46, 213, 115, 0.3);
}

.emoji-selector-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-top: 4px;
}

.emoji-opt {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  font-size: 1.4rem;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.emoji-opt:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: scale(1.08);
}

.emoji-opt.active {
  background: rgba(46, 213, 115, 0.15);
  border-color: #2ed573;
  box-shadow: 0 0 10px rgba(46, 213, 115, 0.3);
  transform: scale(1.1);
}

.custom-words-list-container {
  text-align: left;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 12px;
}

.custom-words-list-container h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.custom-words-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 110px;
  overflow-y: auto;
  padding-right: 4px;
}

/* Custom word list scrollbar styling */
.custom-words-list::-webkit-scrollbar {
  width: 4px;
}
.custom-words-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.custom-word-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.custom-word-tag:hover {
  background: rgba(255, 71, 87, 0.12);
  border-color: #ff4757;
  color: #ff4757;
  transform: scale(1.05);
}

.custom-word-tag::after {
  content: "×";
  font-size: 0.9rem;
  font-weight: bold;
  opacity: 0.6;
  margin-left: 2px;
}

.custom-word-tag:hover::after {
  opacity: 1;
}

.editor-footer {
  margin-top: 4px;
}

/* Glow animation for editor button when on level 6 */
@keyframes button-glow-green {
  0% { box-shadow: 0 0 4px rgba(46, 213, 115, 0.4); }
  100% { box-shadow: 0 0 15px rgba(46, 213, 115, 0.8); }
}

#open-editor-btn.active-glow {
  animation: button-glow-green 0.8s ease-in-out infinite alternate;
}

