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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Fredoka', 'Comic Neue', 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #76fbaa 100%);
  min-height: 100vh;
  min-height: 100dvh;
  color: #333;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px;
  min-height: 100vh;
  min-height: 100dvh;
}

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

.home-header {
  text-align: center;
  padding: 20px 16px 16px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  margin-bottom: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

.home-header h1 {
  font-size: 1.6rem;
  color: #4a4a4a;
  font-weight: 700;
}

.home-header .subtitle {
  font-size: 0.95rem;
  color: #888;
  margin-top: 4px;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding-bottom: 32px;
}

.game-card {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  position: relative;
  -webkit-user-select: none;
  user-select: none;
}

.game-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.game-card:active {
  transform: scale(0.97);
}

.game-card .game-icon {
  font-size: 2.2rem;
  margin-bottom: 6px;
}

.game-card .game-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #555;
}

.game-card .game-desc {
  font-size: 0.75rem;
  color: #999;
  margin-top: 4px;
}

.back-btn {
  background: rgba(255,255,255,0.85);
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  color: #666;
  transition: all 0.2s;
  margin-bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

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

.game-area {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 20px;
  padding: 20px 16px;
  min-height: 300px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.game-title {
  font-size: 1.3rem;
  color: #4a4a4a;
  margin-bottom: 6px;
  text-align: center;
}

.game-instruction {
  text-align: center;
  color: #888;
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.admin-toggle {
  display: block;
  width: 100%;
  padding: 10px;
  background: #f0f0f0;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  margin-bottom: 8px;
}

.admin-toggle:active {
  transform: scale(0.98);
}

.admin-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease, margin 0.3s ease;
  padding: 0;
  margin: 0;
}

.admin-panel.open {
  max-height: 600px;
  padding: 12px 0;
  margin-bottom: 12px;
}

.words-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px;
  background: rgba(102,126,234,0.04);
  border-radius: 14px;
  min-height: 40px;
}

.word-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #e0c3fc, #a8edea);
  border-radius: 20px;
  padding: 6px 10px 6px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #555;
  transition: all 0.2s;
}

.word-chip-text {
  letter-spacing: 0.5px;
}

.word-chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(220,53,69,0.15);
  color: #dc3545;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
}

.word-chip-x:hover {
  background: #dc3545;
  color: #fff;
  transform: scale(1.15);
}

.add-word-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-word-row .spell-input {
  flex: 1;
  min-width: 0;
}

.import-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
}

.import-label {
  background: #667eea;
  color: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.import-label:active {
  transform: scale(0.97);
}

.import-input {
  display: none;
}

.import-status {
  font-size: 0.85rem;
  font-weight: 600;
  color: #888;
}

.import-status.working {
  color: #667eea;
}

.import-status.success {
  color: #28a745;
}

.import-status.error {
  color: #dc3545;
}

.score-display {
  text-align: center;
  margin: 16px 0;
  font-size: 1.1rem;
  color: #888;
}

.score-display .score-num {
  font-weight: 700;
  color: #f39c12;
  font-size: 1.4rem;
}

.word-display {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  color: #667eea;
  margin: 10px 0 16px;
  letter-spacing: 2px;
}

.letter-slots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 12px 0;
  flex-wrap: wrap;
}

.letter-slot {
  width: 44px;
  height: 50px;
  border: 3px dashed #ccc;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  color: #667eea;
  background: rgba(102, 126, 234, 0.05);
  transition: all 0.2s;
}

.letter-slot.filled { border-style: solid; border-color: #667eea; background: rgba(102, 126, 234, 0.1); }
.letter-slot.correct { border-color: #28a745; background: #d4edda; color: #155724; }
.letter-slot.wrong { border-color: #dc3545; background: #f8d7da; color: #721c24; animation: shake 0.4s ease; }

.letter-bank {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.letter-tile {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #a8edea, #84fab0);
  border: 2px solid #7dd3c0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: #333;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  -webkit-user-select: none;
}

.letter-tile:hover { transform: scale(1.08); }
.letter-tile:active { transform: scale(0.93); }
.letter-tile.used { opacity: 0.3; pointer-events: none; transform: scale(0.8); }
.letter-tile.dragging { opacity: 0.5; transform: scale(1.1); }

.drag-drop-area { display: flex; flex-direction: column; align-items: center; gap: 16px; }

.drag-source {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
  padding: 10px; background: rgba(102, 126, 234, 0.05); border-radius: 12px; min-height: 60px;
}

.drag-target {
  display: flex; gap: 6px; justify-content: center;
  padding: 10px; background: rgba(255, 193, 7, 0.08); border: 2px dashed #ffc107; border-radius: 12px; min-height: 60px;
}

.drag-tile {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, #ffd6a5, #caffbf);
  border: 2px solid #ffc107; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 700; color: #333;
  cursor: grab; transition: all 0.15s; user-select: none; -webkit-user-select: none;
}

.drag-tile:active { cursor: grabbing; }
.drag-tile:hover { transform: scale(1.06); }
.drag-tile.placed { background: #d4edda; border-color: #28a745; cursor: default; }

.missing-char-word { display: flex; justify-content: center; gap: 4px; margin: 14px 0; flex-wrap: wrap; }

.char-box {
  width: 40px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 700; border-radius: 10px;
}

.char-box.visible { background: #f0f0f0; border: 2px solid #ddd; color: #555; }
.char-box.missing { border: 3px dashed #667eea; background: rgba(102, 126, 234, 0.08); color: #667eea; cursor: pointer; transition: all 0.2s; }
.char-box.missing:hover { background: rgba(102, 126, 234, 0.15); }
.char-box.missing.correct { border-style: solid; border-color: #28a745; background: #d4edda; color: #155724; }
.char-box.missing.wrong { border-color: #dc3545; background: #f8d7da; color: #721c24; animation: shake 0.4s ease; }

.char-choices { display: flex; justify-content: center; gap: 8px; margin: 14px 0; flex-wrap: wrap; }

.char-choice {
  width: 42px; height: 42px;
  background: #f8f8f8; border: 2px solid #e0e0e0; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 700; cursor: pointer; transition: all 0.15s; color: #555;
}

.char-choice:hover { background: #e8e8e8; transform: scale(1.08); }
.char-choice.used { opacity: 0.3; pointer-events: none; }

.word-scramble-area { text-align: center; }

.scrambled-letters { display: flex; justify-content: center; gap: 6px; margin: 14px 0; flex-wrap: wrap; }

.scramble-tile {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, #ffd6a5, #caffbf);
  border: 2px solid #ffc107; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 700; cursor: pointer;
  transition: all 0.15s; color: #333;
  user-select: none; -webkit-user-select: none;
}

.scramble-tile:hover { transform: scale(1.06); box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.scramble-tile.selected { background: linear-gradient(135deg, #a8edea, #84fab0); border-color: #28a745; transform: scale(0.9); opacity: 0.6; }

.answer-slots { display: flex; justify-content: center; gap: 6px; margin: 10px 0; }

.answer-slot {
  width: 48px; height: 48px;
  border: 3px dashed #ccc; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 700; color: #667eea; cursor: pointer; transition: all 0.2s;
}

.answer-slot.filled { border-style: solid; border-color: #667eea; background: rgba(102, 126, 234, 0.1); }
.answer-slot.correct { border-color: #28a745; background: #d4edda; color: #155724; }

.action-btn {
  background: #667eea; color: #fff; border: none; border-radius: 14px;
  padding: 12px 24px; font-size: 1.05rem; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
  display: block; margin: 16px auto 0;
}

.action-btn:hover { transform: scale(1.03); }
.action-btn:active { transform: scale(0.97); }
.action-btn.secondary { background: #f0f0f0; color: #666; }
.action-btn.hint { background: #ffc107; color: #333; }

.progress-dots { display: flex; justify-content: center; gap: 5px; margin: 10px 0; }

.progress-dot { width: 10px; height: 10px; border-radius: 50%; background: #e0e0e0; transition: all 0.3s; }
.progress-dot.correct { background: #28a745; }
.progress-dot.wrong { background: #dc3545; }
.progress-dot.current { background: #667eea; transform: scale(1.3); }

.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #333; color: #fff; padding: 10px 20px; border-radius: 12px;
  font-size: 0.95rem; font-weight: 600; z-index: 2000;
  transition: transform 0.3s ease; opacity: 0; max-width: 90vw; text-align: center;
}

.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: #28a745; }
.toast.error { background: #dc3545; }

.celebration-overlay {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center;
}

.celebration-overlay.active { display: flex; }

.celebration-content {
  background: #fff; border-radius: 24px; padding: 32px 24px; text-align: center;
  z-index: 1001; animation: popIn 0.4s ease; max-width: 360px; width: 90vw;
}

@keyframes popIn { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.celebration-stars { font-size: 2.5rem; margin-bottom: 10px; }
.celebration-content h2 { font-size: 1.6rem; color: #4a4a4a; margin-bottom: 6px; }
.celebration-content p { color: #888; font-size: 1rem; margin-bottom: 20px; }

.celebration-btn {
  background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; border: none;
  border-radius: 14px; padding: 12px 28px; font-size: 1.05rem; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.2s;
}

.celebration-btn:active { transform: scale(0.97); }

.confetti-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1000; }
.confetti { position: absolute; width: 10px; height: 10px; animation: confettiFall 3s linear forwards; }

@keyframes confettiFall { 0% { transform: translateY(-100vh) rotate(0deg); opacity: 1; } 100% { transform: translateY(100vh) rotate(720deg); opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }

.hint-text { text-align: center; font-size: 0.85rem; color: #aaa; margin-top: 6px; }

.spell-input {
  font-family: inherit; font-size: 1rem; padding: 10px 14px;
  border: 2px solid #ddd; border-radius: 12px; outline: none;
  transition: border-color 0.2s; color: #4a4a4a; width: 100%;
}

.spell-input:focus { border-color: #667eea; }

textarea.spell-input { font-size: 1rem; letter-spacing: 1px; line-height: 1.6; resize: vertical; }

.card-actions { display: flex; gap: 6px; justify-content: center; margin-top: 10px; }

.card-btn {
  border: none; border-radius: 8px; padding: 6px 14px;
  font-size: 0.8rem; font-weight: 600; cursor: pointer; font-family: inherit; transition: all 0.15s;
}

.card-btn.play { background: #667eea; color: #fff; }
.card-btn.play:active { background: #5a6fd6; }
.card-btn.edit { background: #f0f0f0; color: #666; }
.card-btn.edit:active { background: #e0e0e0; }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 16px 0; }
.stat-card { background: #f8f8f8; border-radius: 14px; padding: 14px 10px; text-align: center; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: #667eea; }
.stat-label { font-size: 0.75rem; color: #888; margin-top: 4px; font-weight: 600; }

.chart-container { overflow-x: auto; padding: 8px 0; -webkit-overflow-scrolling: touch; }

.bar-chart { display: flex; align-items: flex-end; gap: 3px; min-height: 140px; padding-bottom: 36px; position: relative; }
.bar-col { flex: 1; min-width: 22px; display: flex; flex-direction: column; align-items: center; position: relative; }
.bar-wrapper { width: 100%; max-width: 28px; height: 100px; background: #f0f0f0; border-radius: 5px 5px 0 0; position: relative; overflow: hidden; }
.bar-fill { position: absolute; bottom: 0; width: 100%; border-radius: 5px 5px 0 0; transition: height 0.5s ease; }
.bar-label { font-size: 0.6rem; color: #999; margin-top: 3px; white-space: nowrap; }
.bar-value { font-size: 0.6rem; font-weight: 700; color: #555; position: absolute; top: -14px; }

.breakdown-list { margin: 12px 0; }
.breakdown-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.breakdown-name { font-weight: 600; color: #555; min-width: 90px; font-size: 0.85rem; }
.breakdown-bar-bg { flex: 1; min-width: 60px; height: 16px; background: #f0f0f0; border-radius: 8px; overflow: hidden; }
.breakdown-bar { height: 100%; border-radius: 8px; transition: width 0.5s ease; }
.breakdown-pct { font-weight: 700; font-size: 0.85rem; min-width: 36px; text-align: right; }
.breakdown-detail { font-size: 0.7rem; color: #999; min-width: 100px; }

.history-list { margin: 10px 0; max-height: 350px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.history-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid #f0f0f0; font-size: 0.8rem; flex-wrap: wrap; }
.history-date { color: #999; min-width: 80px; font-size: 0.75rem; }
.history-game { font-weight: 600; color: #555; min-width: 80px; }
.history-group { color: #888; min-width: 60px; font-size: 0.75rem; }
.history-score { font-weight: 700; min-width: 60px; }
.history-stars { min-width: 30px; }

@media (min-width: 480px) {
  #app { padding: 16px; }
  .home-header h1 { font-size: 1.8rem; }
  .game-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 768px) {
  #app { padding: 20px; }
  .home-header h1 { font-size: 2.2rem; }
  .home-header { padding: 28px 24px 20px; }
  .game-grid { grid-template-columns: repeat(3, 1fr); gap: 16px; }
  .game-area { padding: 24px; }
  .game-card { padding: 24px 16px; }
  .game-card .game-icon { font-size: 2.5rem; }
  .game-card .game-name { font-size: 1rem; }
  .letter-slot { width: 48px; height: 56px; font-size: 1.8rem; }
  .letter-tile { width: 48px; height: 48px; font-size: 1.5rem; }
  .scramble-tile, .answer-slot { width: 52px; height: 52px; font-size: 1.6rem; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .breakdown-name { min-width: 120px; }
  .breakdown-detail { display: block; }
  .history-group { display: block; }
}

@media (max-width: 479px) {
  .breakdown-detail { display: none; }
  .history-group { display: none; }
  .bar-chart { min-height: 120px; }
  .bar-wrapper { height: 80px; }
}
