:root {
  --red: #db2b00;
  --lightblue: #35d6f8;
  --green: #7fce29;
  --orange: #f5a623;
  --purple: #ba5adc;
  --pink: #f065f1;
  --bar-h: clamp(56px, 9vh, 96px);
  --font: 'Dosis', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  overscroll-behavior: none;
  background: #1b2a4a;
  color: #fff;
}

body {
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app { position: fixed; inset: 0; overflow: hidden; }

.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: flex; }

/* ---------- Splash ---------- */
#splash {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vh;
  background: radial-gradient(circle at 50% 35%, #3a5ba0 0%, #1b2a4a 70%);
  cursor: pointer;
}
#splash img { width: min(60vw, 420px); filter: drop-shadow(0 8px 20px rgba(0,0,0,.4)); animation: pop .6s ease; }
#splash .tap-hint { font-size: clamp(16px, 3vw, 24px); opacity: .85; letter-spacing: .04em; animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 0%,100% { opacity: .35 } 50% { opacity: .95 } }
@keyframes pop { 0% { transform: scale(.7); opacity: 0 } 100% { transform: scale(1); opacity: 1 } }

/* ---------- Theme selection ---------- */
#themes {
  flex-direction: column;
  background: url('../assets/img/ui/bg_themes.png') center/cover no-repeat, #2a3f6e;
  overflow-y: auto;
}
.themes-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 48px);
  gap: 16px;
}
.themes-header h1 {
  font-size: clamp(22px, 4vw, 40px); margin: 0; font-weight: 800;
  text-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.lang-bar { display: flex; gap: 8px; }
.lang-bar button {
  border: 3px solid transparent; background: none; padding: 0; cursor: pointer;
  border-radius: 8px; overflow: hidden; line-height: 0; transition: transform .12s;
}
.lang-bar button img { height: clamp(26px, 4vw, 38px); display: block; }
.lang-bar button.active { border-color: #fff; }
.lang-bar button:hover { transform: translateY(-2px); }

.themes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 80vw), 1fr));
  gap: clamp(16px, 2.5vw, 28px);
  padding: clamp(12px, 3vw, 32px);
  align-content: start;
}
.theme-card {
  position: relative; cursor: pointer; border: none; padding: 0;
  border-radius: 22px; overflow: hidden; aspect-ratio: 4 / 3;
  background: linear-gradient(160deg, #ffffff22, #ffffff08);
  box-shadow: 0 10px 24px rgba(0,0,0,.35);
  transition: transform .15s ease, box-shadow .15s ease;
  display: flex; align-items: center; justify-content: center;
}
.theme-card:hover { transform: translateY(-4px) scale(1.02); box-shadow: 0 16px 32px rgba(0,0,0,.45); }
.theme-card img.thumb {
  max-width: 62%; max-height: 62%; object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.3));
}
.theme-card .caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,.72), transparent);
  padding: 28px 16px 14px; text-align: center;
}
.theme-card .caption .cat { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .12em; opacity: .8; }
.theme-card .caption .title { display: block; font-size: clamp(18px, 2.4vw, 26px); font-weight: 800; }

/* ---------- Game ---------- */
#game {
  flex-direction: column;
  background: url('../assets/img/ui/gameBgImg2017.png') center/cover no-repeat, #6fc3df;
}

.game-bar {
  display: flex; align-items: center; gap: clamp(8px, 1.5vw, 16px);
  padding: 8px clamp(10px, 2vw, 24px);
  height: var(--bar-h);
  flex: none;
}
.game-bar .icon-btn {
  background: none; border: none; cursor: pointer; padding: 0; line-height: 0;
  transition: transform .12s;
}
.game-bar .icon-btn:hover { transform: scale(1.08); }
.game-bar .icon-btn img { height: calc(var(--bar-h) * 0.62); display: block; filter: drop-shadow(0 2px 4px rgba(0,0,0,.35)); }
.game-bar .stars-btn img { height: calc(var(--bar-h) * 0.72); }
.game-bar .spacer { flex: 1; }
.game-bar .game-langs { display: flex; gap: 6px; }
.game-bar .game-langs button { border: 3px solid transparent; background: none; padding: 0; cursor: pointer; border-radius: 7px; overflow: hidden; line-height: 0; }
.game-bar .game-langs button img { height: calc(var(--bar-h) * 0.42); display: block; }
.game-bar .game-langs button.active { border-color: #fff; }

.play-area {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  padding: 0 clamp(8px, 2vw, 28px);
}

.char-zone {
  flex: 1.05; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(6px, 1.4vh, 18px);
  position: relative;
}
.char-image { max-height: 46%; max-width: 60%; object-fit: contain; filter: drop-shadow(0 8px 14px rgba(0,0,0,.3)); transition: all .9s ease; }
.char-image.fly { position: fixed; z-index: 60; pointer-events: none; }

.word-row { display: flex; align-items: center; gap: clamp(4px, 0.9vw, 10px); flex-wrap: wrap; justify-content: center; }
.target {
  --c: var(--purple);
  width: var(--tile, 52px); height: calc(var(--tile, 52px) * 1.18);
  border-radius: 8px; background: var(--c);
  display: flex; align-items: center; justify-content: center;
  font-family: 'SchoolKX', var(--font); color: #fff;
  font-size: calc(var(--tile, 52px) * 0.62); font-weight: 700;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.15), 0 3px 5px rgba(0,0,0,.25);
  position: relative; transition: background .2s;
}
.target.matched { box-shadow: inset 0 -4px 0 rgba(0,0,0,.2), 0 3px 6px rgba(0,0,0,.3); }
.target.hint-purple { --c: var(--purple); }

.speaker-btn { background: none; border: none; cursor: pointer; padding: 0; line-height: 0; }
.speaker-btn img { height: calc(var(--tile, 52px) * 1.0); display: block; filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)); transition: transform .12s; }
.speaker-btn:active img { transform: scale(.9); }
.word-with-speaker { display: flex; align-items: center; gap: clamp(8px, 1.6vw, 18px); }

/* Tile keyboard */
.tile-grid {
  flex: none; display: flex; flex-direction: column; align-items: center;
  gap: clamp(3px, 0.7vh, 7px);
  padding: clamp(6px, 1.4vh, 14px) 0;
}
.tile-row { display: flex; gap: clamp(3px, 0.7vw, 7px); justify-content: center; }
.tile {
  --c: var(--red);
  width: var(--tile, 52px); height: calc(var(--tile, 52px) * 1.18);
  border-radius: 8px; background: var(--c);
  display: flex; align-items: center; justify-content: center;
  font-family: 'SchoolKX', var(--font); color: #fff;
  font-size: calc(var(--tile, 52px) * 0.6); font-weight: 700;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.18), 0 3px 5px rgba(0,0,0,.3);
  cursor: grab; touch-action: none; user-select: none;
  transition: transform .08s;
}
.tile.spacer-gap { background: none; box-shadow: none; pointer-events: none; }
.tile.dragging { cursor: grabbing; }
.tile.drag-clone { position: fixed; z-index: 80; pointer-events: none; transform: scale(1.18); box-shadow: 0 10px 20px rgba(0,0,0,.45); }

/* progress bar */
.progress-bar {
  flex: none; display: flex; align-items: center; gap: 2px;
  background: #fff; padding: 6px clamp(6px, 1.5vw, 18px);
  height: calc(var(--bar-h) * 0.95);
}
.progress-bar .mini {
  flex: 1; height: 100%; object-fit: contain; min-width: 0;
  transition: filter .4s, opacity .4s;
}
.progress-bar .mini.locked { filter: grayscale(1) brightness(1.4); opacity: .5; }
.progress-bar .mini.current { filter: drop-shadow(0 0 4px var(--purple)); }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  background: rgba(10,16,32,.72); backdrop-filter: blur(6px);
  padding: 5vw;
}
.overlay.active { display: flex; }
.overlay-card {
  background: linear-gradient(165deg, #34508c, #233861);
  border-radius: 26px; padding: clamp(22px, 4vw, 46px);
  max-width: 560px; width: 100%; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.5); border: 2px solid #ffffff22;
}
.overlay-card .star { font-size: clamp(54px, 10vw, 92px); line-height: 1; filter: drop-shadow(0 4px 10px rgba(255,200,0,.5)); }
.overlay-card h2 { font-size: clamp(22px, 4vw, 34px); margin: 12px 0 18px; }
.overlay-card p { font-size: clamp(15px, 2.4vw, 20px); line-height: 1.5; white-space: pre-line; opacity: .92; margin: 0 0 22px; }
.overlay-card .btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn {
  font-family: var(--font); font-weight: 700; font-size: clamp(15px, 2.4vw, 19px);
  border: none; border-radius: 999px; padding: 12px 28px; cursor: pointer;
  background: var(--orange); color: #fff; box-shadow: 0 5px 0 #b5731a;
  transition: transform .1s, box-shadow .1s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b5731a; }
.btn.secondary { background: #5a76b8; box-shadow: 0 5px 0 #3d5894; }
.btn.secondary:active { box-shadow: 0 2px 0 #3d5894; }

/* help difficulty rows */
.help-levels { text-align: left; margin: 8px 0 22px; display: grid; gap: 10px; }
.help-levels .lvl { display: flex; align-items: center; gap: 12px; font-size: clamp(13px, 2vw, 17px); }
.help-levels .lvl img { height: 26px; flex: none; }

@media (orientation: landscape) and (min-width: 760px) {
  .char-image { max-height: 52%; }
}
