:root {
  --bg: #0b0d17;
  --surface: #151829;
  --surface-2: #1c2036;
  --border: #272c47;
  --text: #f1f3fb;
  --muted: #8b91ad;
  --accent: #3d7bff;
  --accent-2: #6aa8ff;
  --green: #34d399;
  --red: #f87171;
  --skip: #5b6180;
  --radius: 14px;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(900px 500px at 50% -180px, rgba(61, 123, 255, 0.28), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Yläpalkki ---------- */

header {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px 6px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 34px; }
.logo rect:first-child { fill: var(--accent); }
.logo g { fill: #fff; }
h1 { margin: 0; font: 800 1.55rem/1 var(--display); letter-spacing: -0.02em; }

.modes {
  justify-self: center;
  display: flex;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.modes button {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.modes button.active { background: var(--accent); color: #fff; }
.modes button:not(.active):hover { color: var(--text); }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
}
.icon-btn:hover { color: var(--text); border-color: var(--muted); }

@media (max-width: 480px) {
  header { grid-template-columns: 1fr auto; }
  .modes { grid-column: 1 / -1; grid-row: 2; width: 100%; }
  .modes button { flex: 1; }
}

main { max-width: 560px; margin: 0 auto; padding: 12px 16px 48px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* ---------- Arvausrivit ---------- */

#board { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
#board li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  background: rgba(21, 24, 41, 0.6);
  border: 1px dashed var(--border);
  color: var(--muted);
}
#board .len {
  flex: none;
  width: 44px;
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  opacity: 0.6;
}
#board .txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board .icon { flex: none; font-weight: 700; }

#board li.current { border: 1px solid var(--accent); background: rgba(61, 123, 255, 0.08); }
#board li.current .len { color: var(--accent-2); opacity: 1; }
#board li.wrong, #board li.skip, #board li.correct { border-style: solid; background: var(--surface); color: var(--text); }
#board li.wrong { border-color: rgba(248, 113, 113, 0.45); }
#board li.wrong .icon { color: var(--red); }
#board li.skip { color: var(--muted); }
#board li.correct { border-color: var(--green); background: rgba(52, 211, 153, 0.1); font-weight: 600; }
#board li.correct .icon, #board li.correct .len { color: var(--green); opacity: 1; }

/* ---------- Soitin ---------- */

.player-card { margin-bottom: 16px; }

#bar { display: flex; gap: 5px; height: 10px; }
#bar .seg { flex: 1; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
#bar .seg.unlocked { background: #2e3557; }
#bar .seg .fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

#ticks { display: flex; gap: 5px; margin-top: 6px; }
#ticks span {
  flex: 1;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.45;
  font-variant-numeric: tabular-nums;
}
#ticks span.unlocked { opacity: 1; }

.player {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}
#limit { text-align: right; }

#play {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 0;
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 28px rgba(61, 123, 255, 0.45);
  display: grid;
  place-items: center;
  transition: transform 0.12s;
}
#play:hover { transform: scale(1.05); }
#play:active { transform: scale(0.96); }
#play svg { width: 30px; height: 30px; fill: #fff; }
#play .i-play { margin-left: 3px; }
#play .i-stop, #play.playing .i-play { display: none; }
#play.playing .i-stop { display: block; }
#play.playing::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent-2);
  animation: pulse 1s ease-out infinite;
}
@keyframes pulse { to { transform: scale(1.45); opacity: 0; } }

/* ---------- Arvauskenttä ---------- */

.search { position: relative; }
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}
#guess {
  width: 100%;
  padding: 14px 14px 14px 42px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#guess::placeholder { color: var(--muted); }
#guess:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(61, 123, 255, 0.25); }

#suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  max-height: 260px;
  overflow-y: auto;
  z-index: 10;
}
#suggestions li { padding: 9px 10px; border-radius: 8px; cursor: pointer; }
#suggestions li:hover, #suggestions li.active { background: rgba(61, 123, 255, 0.18); }

.actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4f88ff; }
#skip { flex: 0 1 auto; color: var(--muted); }

#message { min-height: 1.5em; margin: 12px 0 0; color: var(--muted); text-align: center; font-size: 0.9rem; }

/* ---------- Tulos ---------- */

#result { text-align: center; padding: 24px 18px; }
#result-emoji { font-size: 2.6rem; line-height: 1; }
#result h2 { margin: 10px 0 4px; font: 800 1.6rem/1.2 var(--display); }
#result-answer {
  margin: 0 0 14px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent-2);
}
#result-squares { font-size: 1.5rem; letter-spacing: 3px; }
#result .actions { margin-top: 18px; }
#countdown { margin: 16px 0 0; color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }

#stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
#stats b { display: block; font: 800 1.5rem/1.2 var(--display); }
#stats span { font-size: 0.72rem; color: var(--muted); }

/* YouTube-soitin on ruudun ulkopuolella arvailun ajan */
#yt-wrap { position: fixed; left: -10000px; top: 0; width: 320px; height: 180px; }
#yt-wrap.revealed {
  position: static;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  margin-top: 16px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
#yt-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ---------- Ohjeet ---------- */

dialog {
  width: min(440px, calc(100% - 32px));
  padding: 24px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(5, 6, 12, 0.7); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 12px; font: 800 1.5rem/1.2 var(--display); }
dialog ol { padding-left: 20px; margin: 0 0 12px; display: grid; gap: 8px; }
dialog p { color: var(--muted); margin: 0 0 18px; }
dialog form { display: flex; }
