/* ΦΙΔΑΚΙ 3D — UI shell. The 3D scene owns the whole viewport; everything here
   is a translucent layer on top of it. Sized generously: this is used on
   classroom tablets by children, so nothing is smaller than a fingertip. */

:root {
  --ink: #f2f6ff;
  --ink-dim: #9fb0d0;
  --accent: #4fd1c5;
  --accent-2: #ffd166;
  --danger: #ff6b6b;
  --good: #7bed9f;
  --panel: rgba(14, 20, 40, 0.82);
  --panel-line: rgba(140, 180, 255, 0.22);
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: #070b16;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.layer { position: fixed; inset: 0; z-index: 2; }
.layer[hidden] { display: none; }

.overlay {
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: radial-gradient(ellipse at center, rgba(6, 10, 22, 0.55), rgba(4, 6, 14, 0.9));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade 0.25s ease both;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* --------------------------------------------------------------- panels --- */

.panel {
  width: min(680px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: clamp(20px, 4vw, 34px);
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 26px;
  box-shadow: var(--shadow);
  animation: pop 0.35s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

.panel.small { width: min(460px, 100%); }

@keyframes pop {
  from { transform: scale(0.9) translateY(14px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.title {
  font-size: clamp(38px, 9vw, 68px);
  letter-spacing: 3px;
  line-height: 1;
  background: linear-gradient(180deg, #ffffff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 38px rgba(79, 209, 197, 0.35);
}
.title span { color: var(--accent-2); -webkit-text-fill-color: var(--accent-2); }

.subtitle {
  margin: 10px 0 22px;
  color: var(--ink-dim);
  font-size: clamp(15px, 3.4vw, 19px);
}

.panel h2 {
  font-size: clamp(26px, 6vw, 38px);
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.panel p { color: var(--ink-dim); font-size: 17px; line-height: 1.5; }

/* ---------------------------------------------------------------- modes --- */

.modes { display: grid; gap: 12px; margin-bottom: 20px; }
@media (min-width: 560px) { .modes { grid-template-columns: repeat(3, 1fr); } }

.mode-btn {
  display: grid;
  gap: 3px;
  padding: 16px 12px;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}
.mode-btn:hover, .mode-btn:focus-visible {
  transform: translateY(-3px);
  background: rgba(79, 209, 197, 0.16);
  border-color: var(--accent);
  outline: none;
}
.mode-btn:active { transform: translateY(0) scale(0.98); }
.mode-emoji { font-size: 28px; }
.mode-name { font-weight: 700; font-size: 19px; letter-spacing: 1.5px; }
.mode-desc { font-size: 13px; color: var(--ink-dim); }

/* ------------------------------------------------------------- settings --- */

.settings { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; }

.toggle {
  padding: 9px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--ink-dim);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  transition: all 0.15s;
}
.toggle[aria-pressed="true"] { color: #06202a; background: var(--accent); border-color: var(--accent); }
.toggle:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.hint-line, .best-line { font-size: 14px; color: var(--ink-dim); margin-top: 6px; }
kbd {
  padding: 2px 7px;
  font: inherit;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
}

/* -------------------------------------------------------------- buttons --- */

.big-btn, .ghost-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 15px 18px;
  font: inherit;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-decoration: none;
  cursor: pointer;
  border-radius: 14px;
  transition: transform 0.15s, filter 0.15s;
}
.big-btn {
  color: #052a26;
  background: linear-gradient(180deg, #6ff0e2, var(--accent));
  border: none;
  box-shadow: 0 8px 24px rgba(79, 209, 197, 0.35);
}
.ghost-btn {
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid var(--panel-line);
  font-size: 16px;
}
.big-btn:hover, .ghost-btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.big-btn:active, .ghost-btn:active { transform: scale(0.98); }

/* ------------------------------------------------------------------ HUD --- */

#hud { pointer-events: none; }
#hud button { pointer-events: auto; }

.hud-top {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.chip {
  display: flex;
  gap: 7px;
  align-items: baseline;
  padding: 7px 13px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  font-size: 17px;
  font-weight: 700;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.chip-label { font-size: 10px; letter-spacing: 1.4px; color: var(--ink-dim); font-weight: 400; }
#lives { color: var(--danger); letter-spacing: 2px; }
.chip.bump { animation: bump 0.35s ease; }
@keyframes bump { 50% { transform: scale(1.18); } }

.icon-btn {
  width: 42px;
  height: 42px;
  font-size: 17px;
  color: var(--ink);
  cursor: pointer;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 50%;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#btn-pause { margin-left: auto; }
.icon-btn:active { transform: scale(0.92); }

/* ------------------------------------------------------- word + picture --- */

.hud-word {
  position: absolute;
  left: 50%;
  bottom: calc(14px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  align-items: center;
  max-width: calc(100% - 20px);
  padding: 10px 16px 10px 10px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.pic-card {
  flex: none;
  width: 74px;
  height: 74px;
  padding: 5px;
  cursor: pointer;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  overflow: hidden;
}
.pic-card img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pic-card:active { transform: scale(0.95); }

.word-slots { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }

.slot {
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 42px;
  padding: 0 4px;
  font-size: 24px;
  font-weight: 700;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid var(--panel-line);
  border-bottom-width: 3px;
  border-radius: 9px;
}
.slot.done {
  color: #06251f;
  background: linear-gradient(180deg, #a8f5c8, var(--good));
  border-color: var(--good);
  animation: slotpop 0.3s cubic-bezier(0.2, 1.5, 0.4, 1);
}
.slot.next {
  color: var(--accent-2);
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.2);
  animation: nextpulse 1.4s ease-in-out infinite;
}
@keyframes slotpop { 0% { transform: scale(0.4) rotate(-12deg); } 100% { transform: none; } }
@keyframes nextpulse { 50% { box-shadow: 0 0 0 8px rgba(255, 209, 102, 0.05); } }

/* --------------------------------------------------------------- badges --- */

.hud-badges {
  position: absolute;
  right: 10px;
  top: calc(62px + var(--safe-t));
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.badge {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #06202a;
  background: var(--accent);
  border-radius: 999px;
  animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.badge[hidden] { display: none; }
.badge-shield { background: var(--good); }
.badge-slow { background: #8fd8ff; }
.badge-hint { background: #ffb3e6; }
#badge-combo { background: linear-gradient(90deg, var(--accent-2), #ff9f68); }

/* ---------------------------------------------------------------- toast --- */

.toast {
  position: absolute;
  left: 50%;
  top: 28%;
  transform: translateX(-50%);
  padding: 14px 26px;
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 700;
  letter-spacing: 2px;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
  animation: toast 1.1s ease-out both;
  pointer-events: none;
}
.toast.good { color: var(--good); }
.toast.bad { color: var(--danger); }
.toast.gold { color: var(--accent-2); }
@keyframes toast {
  0% { transform: translateX(-50%) scale(0.6); opacity: 0; }
  25% { transform: translateX(-50%) scale(1.1); opacity: 1; }
  70% { transform: translateX(-50%) translateY(-10px) scale(1); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-40px) scale(0.95); opacity: 0; }
}

/* ----------------------------------------------------------------- dpad --- */

.dpad {
  position: absolute;
  right: calc(14px + var(--safe-b));
  bottom: calc(112px + var(--safe-b));
  display: grid;
  grid-template-areas: ". u ." "l . r" ". d .";
  gap: 6px;
}
.dpad[hidden] { display: none; }
.dpad button {
  width: 58px;
  height: 58px;
  font-size: 22px;
  color: var(--ink);
  cursor: pointer;
  background: rgba(20, 28, 52, 0.7);
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.dpad button:active { background: var(--accent); color: #052a26; transform: scale(0.93); }
.dpad [data-dir="up"] { grid-area: u; }
.dpad [data-dir="left"] { grid-area: l; }
.dpad [data-dir="right"] { grid-area: r; }
.dpad [data-dir="down"] { grid-area: d; }

/* --------------------------------------------------------- celebrations --- */

.celebrate .stars {
  font-size: 52px;
  letter-spacing: 8px;
  color: #2c3350;
  margin-bottom: 6px;
}
.celebrate .stars b {
  color: var(--accent-2);
  font-weight: inherit;
  text-shadow: 0 0 26px rgba(255, 209, 102, 0.7);
  display: inline-block;
  animation: starpop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.celebrate .stars b:nth-child(2) { animation-delay: 0.12s; }
.celebrate .stars b:nth-child(3) { animation-delay: 0.24s; }
@keyframes starpop { from { transform: scale(0) rotate(-90deg); } to { transform: none; } }

@media (max-width: 420px) {
  .pic-card { width: 58px; height: 58px; }
  .slot { min-width: 27px; height: 34px; font-size: 19px; }
  .chip { font-size: 15px; padding: 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
