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

:root {
  --grass: #7ec850;
  --grass-dark: #5aa03a;
  --dirt: #6b3f1d;
  --sky-1: #78c8f0;
  --sky-2: #a9e0ff;
  --ink: #1a1a1a;
  --gold: #ffd94a;
  --diamond: #4ad3ff;
  --red: #ff4a4a;
  --panel: #f5ecd4;
  --panel-line: #8b6b3a;
  --body-font: 'Lexend', sans-serif;
  --heading-font: 'Press Start 2P', monospace;
}

html, body {
  height: 100%;
  font-family: var(--body-font);
  font-weight: 400;
  color: var(--ink);
  overflow-x: hidden;
  font-size: 18px;
  line-height: 1.5;
}

body {
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 60%, #c8e89a 100%);
  min-height: 100vh;
  position: relative;
}

.sky {
  position: fixed; inset: 0;
  background:
    radial-gradient(circle at 20% 15%, #fff5 0 3px, transparent 4px),
    radial-gradient(circle at 80% 30%, #fff5 0 2px, transparent 3px),
    radial-gradient(circle at 50% 70%, #fff4 0 2px, transparent 3px);
  z-index: 0; pointer-events: none;
}

.clouds { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.cloud {
  position: absolute; width: 120px; height: 40px; background: #fff;
  border-radius: 40px; opacity: 0.85;
  box-shadow: 30px -10px 0 -5px #fff, -30px -5px 0 -8px #fff;
  animation: drift 60s linear infinite;
}
.cloud.c1 { top: 8%; left: -150px; animation-duration: 80s; }
.cloud.c2 { top: 20%; left: -200px; animation-duration: 120s; animation-delay: -40s; transform: scale(0.7); }
.cloud.c3 { top: 5%; left: -250px; animation-duration: 100s; animation-delay: -20s; transform: scale(1.2); }
@keyframes drift { to { left: 110%; } }

.game-wrap {
  position: relative; z-index: 1;
  max-width: 880px; margin: 0 auto; padding: 16px;
  min-height: 100vh; display: flex; flex-direction: column; gap: 12px;
}

/* ===== HUD ===== */
.hud {
  display: flex; justify-content: space-between; align-items: center;
  background: #2a2a2a; color: #fff;
  border: 4px solid #1a1a1a;
  padding: 10px 14px; border-radius: 4px;
  box-shadow: 0 4px 0 #111;
  font-family: var(--heading-font); font-size: 12px;
}
.logo-block { display: flex; flex-direction: column; gap: 2px; }
.logo-main { color: var(--gold); text-shadow: 2px 2px 0 #7a1a1a; font-size: 18px; letter-spacing: 2px; }
.logo-sub { color: var(--grass); font-size: 8px; letter-spacing: 2px; }
.hud-right { display: flex; gap: 14px; align-items: center; }
.stat { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.stat-label { font-size: 8px; color: #aaa; }
.stat-value { font-size: 14px; color: var(--gold); }
.xp-bar { width: 120px; height: 10px; background: #111; border: 2px solid #555; }
.xp-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #7ec850, #cfff6a); transition: width 0.3s ease; }
.hearts { display: flex; gap: 4px; }
.heart { color: #ff4a6e; font-size: 22px; text-shadow: 1px 1px 0 #111; transition: opacity 0.2s, transform 0.2s; }
.heart.lost { opacity: 0.2; transform: scale(0.7); }

/* ===== HUB ===== */
.hub {
  background: var(--panel);
  border: 4px solid var(--panel-line); border-radius: 4px;
  padding: 24px;
  box-shadow: 0 6px 0 #5a3f1a, inset 0 0 0 2px #d9c590;
  flex: 1;
}
.hub-title {
  font-family: var(--heading-font); font-size: 16px;
  text-align: center; margin-bottom: 20px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.hub-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 500px) { .hub-grid { grid-template-columns: 1fr; } }

.hub-card {
  background: #fff; border: 4px solid var(--ink); border-radius: 8px;
  padding: 24px 16px; cursor: pointer;
  box-shadow: 0 4px 0 #000;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: transform 0.08s;
  border-left: 8px solid var(--accent, var(--gold));
}
.hub-card:hover { transform: translateY(-2px); }
.hub-card:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.hub-icon { font-size: 48px; }
.hub-name {
  font-family: var(--heading-font); font-size: 14px;
  letter-spacing: 2px;
}
.hub-progress { font-size: 14px; color: #666; }

/* ===== Panel ===== */
.panel {
  background: var(--panel);
  border: 4px solid var(--panel-line); border-radius: 4px;
  padding: 16px;
  box-shadow: 0 6px 0 #5a3f1a, inset 0 0 0 2px #d9c590;
  display: flex; flex-direction: column; gap: 14px;
  flex: 1;
}
.panel-header {
  display: flex; align-items: center; gap: 12px;
}
.panel-title {
  font-family: var(--heading-font); font-size: 14px;
}
.btn-back {
  background: #ddd; font-size: 9px; padding: 6px 10px;
}

/* ===== Tabs ===== */
.type-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.type-tab {
  flex: 1; min-width: 130px;
  background: #fff; border: 3px solid var(--ink); color: var(--ink);
  padding: 10px 8px; cursor: pointer;
  font-family: var(--heading-font); font-size: 9px;
  text-align: center; border-radius: 4px;
  box-shadow: 0 3px 0 #000; transition: transform 0.08s;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
}
.type-tab:hover { transform: translateY(-1px); }
.type-tab:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
.type-tab.active { background: var(--gold); }
.type-tab .tab-ico { font-size: 22px; }
.type-tab .tab-sub { font-size: 7px; opacity: 0.7; font-weight: normal; }

/* ===== Progress ===== */
.progress-row {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--heading-font); font-size: 10px;
}
.progress-label { white-space: nowrap; }
.progress-bar { flex: 1; height: 12px; background: #000; border: 2px solid #333; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #ff8a3a, #ffd94a); transition: width 0.3s ease; }

/* ===== Scene ===== */
.scene {
  display: grid; grid-template-columns: 160px 1fr; gap: 16px; align-items: center;
  background: linear-gradient(180deg, #bfe9ff 0%, #d9f2b6 70%, #7ec850 100%);
  border: 3px solid var(--ink); border-radius: 4px;
  padding: 12px; min-height: 170px;
}
@media (max-width: 600px) {
  .scene { grid-template-columns: 100px 1fr; }
}
.tree-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tree-svg { width: 100%; height: auto; max-width: 160px; }
.tree-label {
  font-family: var(--heading-font); font-size: 8px;
  background: #1a1a1a; color: var(--gold); padding: 3px 8px; border-radius: 2px;
}

#crown .stage { display: none; }
#crown.stage-1 .s1,
#crown.stage-2 .s2,
#crown.stage-3 .s3,
#crown.stage-4 .s4,
#crown.stage-5 .s5 { display: block; animation: pop 0.4s ease-out; }
@keyframes pop {
  0% { transform: translateY(8px) scale(0.6); opacity: 0; }
  60% { transform: translateY(-2px) scale(1.08); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.dialogue {
  background: #fff; border: 3px solid var(--ink); border-radius: 4px;
  padding: 12px 14px; font-size: 20px; line-height: 1.4;
  position: relative;
  display: flex; align-items: flex-start; gap: 8px;
}
.dialogue::before {
  content: ''; position: absolute; left: -14px; top: 20px;
  border: 8px solid transparent; border-right-color: var(--ink);
}
.dialogue::after {
  content: ''; position: absolute; left: -10px; top: 22px;
  border: 6px solid transparent; border-right-color: #fff;
}
#dialogueText { flex: 1; }
.dialogue-tts { flex-shrink: 0; margin-top: 2px; }

/* ===== TTS button (everywhere) ===== */
.tts-btn {
  background: var(--diamond); border: 2px solid var(--ink); border-radius: 4px;
  padding: 4px 8px; cursor: pointer; font-size: 16px;
  line-height: 1; display: inline-flex; align-items: center;
  transition: transform 0.08s;
}
.tts-btn:hover { transform: scale(1.1); }
.tts-btn:active { transform: scale(0.95); }

/* ===== Controls & Buttons ===== */
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  font-family: var(--heading-font); font-size: 11px;
  border: 3px solid var(--ink); border-radius: 4px; padding: 10px 14px;
  cursor: pointer; background: #fff; color: var(--ink);
  box-shadow: 0 3px 0 #000; display: inline-flex; gap: 6px; align-items: center;
  transition: transform 0.08s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn .ico { font-size: 16px; }
.btn-speak { background: var(--diamond); color: #0a2a3a; }
.btn-hint { background: var(--gold); }
.btn-check { background: var(--grass); color: #0a2a0a; }

/* ===== Type A options ===== */
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: #fff; border: 3px solid var(--ink); border-radius: 4px;
  padding: 14px 16px; cursor: pointer;
  box-shadow: 0 3px 0 #000;
  font-size: 20px; text-align: left;
  transition: transform 0.08s;
}
.option:hover { transform: translateY(-1px); background: #fff8d0; }
.option:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
.option.correct { background: #b9f0a0; border-color: #2e5a12; }
.option.wrong { background: #ffb0b0; border-color: #7a1a1a; }
.option[disabled] { cursor: default; }
.option .opt-text { flex: 1; }
.option .opt-play {
  background: var(--diamond); border: 2px solid var(--ink); border-radius: 4px;
  padding: 4px 8px; cursor: pointer; font-size: 14px;
}

/* ===== Type B input ===== */
.prompt-da {
  background: #fff; border: 3px dashed var(--ink); border-radius: 4px;
  padding: 14px; font-size: 24px; text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.answer-form { display: flex; gap: 8px; }
.answer-input {
  flex: 1; font-family: var(--body-font); font-size: 22px;
  padding: 12px 14px; border: 3px solid var(--ink); border-radius: 4px;
  background: #fff;
}
.answer-input:focus { outline: 3px solid var(--gold); }

/* ===== Type C build ===== */
.build-slots {
  min-height: 60px;
  display: flex; flex-wrap: wrap; gap: 6px;
  background: #fff; border: 3px dashed var(--ink); border-radius: 4px;
  padding: 10px;
}
.build-bank { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0; }
.word-block {
  font-family: var(--heading-font); font-size: 11px;
  background: #d9c590; border: 3px solid var(--ink); border-radius: 4px;
  padding: 10px 12px; cursor: pointer;
  box-shadow: 0 3px 0 #000; user-select: none;
  transition: transform 0.08s;
}
.word-block:hover { transform: translateY(-1px); background: #ffd94a; }
.word-block:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
.word-block.slot { background: #b9f0a0; }
.word-block.used { opacity: 0.3; pointer-events: none; }

/* ===== Komma-klik ===== */
.comma-view { padding: 10px 0; }
.comma-words {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  font-size: 22px; line-height: 2.2;
}
.comma-word {
  padding: 4px 2px;
}
.comma-slot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 36px;
  background: #eee; border: 2px dashed #aaa; border-radius: 4px;
  cursor: pointer; font-size: 24px; font-weight: 600; color: #555;
  transition: background 0.15s, border-color 0.15s;
}
.comma-slot:hover { background: #fff3c0; border-color: var(--gold); }
.comma-slot.selected {
  background: var(--gold); border-color: var(--ink);
  color: var(--ink); border-style: solid;
}
.comma-slot.correct-comma {
  background: #b9f0a0; border-color: #2e5a12; color: #2e5a12;
  border-style: solid;
}
.comma-slot.wrong-comma {
  background: #ffb0b0; border-color: #7a1a1a; color: #7a1a1a;
  border-style: solid;
}

/* ===== Feedback ===== */
.feedback {
  min-height: 28px;
  font-family: var(--heading-font); font-size: 12px;
  text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.feedback.ok { color: #2e5a12; }
.feedback.bad { color: #7a1a1a; }
.feedback-tts.hidden { display: none; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1a1a1a; color: #fff; border: 3px solid var(--gold);
  padding: 12px 18px; border-radius: 4px;
  font-family: var(--heading-font); font-size: 11px;
  display: flex; gap: 10px; align-items: center;
  z-index: 50; animation: toastIn 0.3s ease-out;
}
.toast.hidden { display: none; }
.toast-emoji { font-size: 22px; }
@keyframes toastIn {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ===== Overlay ===== */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }
.win-card {
  background: var(--panel); border: 4px solid var(--panel-line); border-radius: 4px;
  padding: 30px; text-align: center;
  box-shadow: 0 6px 0 #5a3f1a; max-width: 400px;
}
.win-card h2 {
  font-family: var(--heading-font); font-size: 18px;
  color: #7a1a1a; margin-bottom: 14px;
}
.win-card p { font-size: 20px; margin-bottom: 12px; }
.win-stats { font-family: var(--heading-font); font-size: 10px; color: #555; }

/* ===== Footer ===== */
.foot {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 16px; padding: 4px;
}
.link-btn {
  background: none; border: none; color: #7a1a1a; cursor: pointer;
  font-family: var(--body-font); font-size: 16px;
}
.foot-tip { color: #444; font-size: 14px; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 200; }

.shake { animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.task-view[hidden] { display: none; }
