:root {
  --charcoal: #1c1830;
  --charcoal-2: #241f3d;
  --amber: #ffb347;
  --violet: #8a3fe0;
  --ink: #241f3d;
  --muted: #746e8c;
  --grad-accent: linear-gradient(135deg, #ffb347 0%, #ff7a3d 45%, #b14bff 100%);
  --glass: rgba(255, 255, 255, 0.62);
  --glass-strong: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(255, 255, 255, 0.75);
  --green: #2fae63;
  --red: #e0463c;
  --gold: #ffbf47;
  --shadow-soft: 0 18px 40px -20px rgba(28, 24, 48, 0.4);
}

* { box-sizing: border-box; }

html {
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
  background:
    radial-gradient(1200px 600px at 15% -5%, #f0e9ff 0%, rgba(240,233,255,0) 60%),
    radial-gradient(900px 500px at 100% 0%, #fff3d6 0%, rgba(255,243,214,0) 55%),
    linear-gradient(180deg, #f7f3fd 0%, #f2eefa 45%, #fdf3e8 100%);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Kelluvat väriläikät taustalla */
.bg-blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-blobs::before, .bg-blobs::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.4;
}
.bg-blobs::before {
  width: 46vmax; height: 46vmax; left: -12vmax; top: 30vh;
  background: radial-gradient(circle, #b14bff, transparent 65%);
  animation: float1 18s ease-in-out infinite;
}
.bg-blobs::after {
  width: 40vmax; height: 40vmax; right: -14vmax; top: 8vh;
  background: radial-gradient(circle, #ffb347, transparent 65%);
  animation: float2 22s ease-in-out infinite;
}
@keyframes float1 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(4vmax,-3vmax) scale(1.08); } }
@keyframes float2 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-4vmax,3vmax) scale(1.1); } }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  color: white;
  flex-wrap: wrap;
  position: relative;
  overflow: hidden;
  background: linear-gradient(120deg, var(--charcoal) 0%, var(--charcoal-2) 55%, #3a2a5c 100%);
  margin: calc(env(safe-area-inset-top) * -1) calc(env(safe-area-inset-left) * -1) 0 calc(env(safe-area-inset-right) * -1);
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-left: calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
  box-shadow: 0 8px 30px -12px rgba(28, 24, 48, 0.7);
}
.topbar::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 40%, rgba(255,255,255,0.10) 50%, transparent 60%);
}
.brand { display: flex; align-items: center; gap: 12px; z-index: 1; }
.logo {
  width: 54px; height: 54px; border-radius: 18px; display: flex; align-items: center; justify-content: center;
  font-size: 1.7rem; background: rgba(255,255,255,0.14);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 0 0 2px rgba(255,255,255,0.15), 0 6px 16px -6px rgba(0,0,0,0.5);
  backdrop-filter: blur(6px);
}
.brand-text h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.3px; font-family: Georgia, "Iowan Old Style", serif; }
.tagline { font-size: 0.72rem; color: #ffdca0; text-transform: uppercase; letter-spacing: 1px; }

.stats-strip { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; z-index: 1; }
.stat { display: flex; flex-direction: column; min-width: 78px; }
.stat-label { font-size: 0.68rem; text-transform: uppercase; color: #e6d9ff; opacity: 0.85; letter-spacing: 0.05em; }
.stat-value { font-size: 1.2rem; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; text-shadow: 0 1px 8px rgba(177,75,255,0.4); }

.sound-toggle {
  background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.25); color: white;
  padding: 9px 12px; border-radius: 12px; cursor: pointer; font-size: 0.95rem; backdrop-filter: blur(6px);
  transition: transform 0.15s, background 0.15s;
}
.sound-toggle:hover { background: rgba(255,255,255,0.24); }
.sound-toggle:active { transform: scale(0.92); }
.sound-toggle.muted { opacity: 0.6; }

.tabs { display: flex; gap: 8px; padding: 16px 16px 0; flex-wrap: wrap; max-width: 900px; margin: 0 auto; }
.tab-btn {
  border: 1px solid transparent; background: rgba(255,255,255,0.45); color: var(--ink); padding: 10px 18px;
  border-radius: 14px; font-size: 0.9rem; cursor: pointer; font-weight: 700; opacity: 0.8;
  backdrop-filter: blur(6px); transition: transform 0.15s, opacity 0.15s, box-shadow 0.2s;
}
.tab-btn.active {
  background: var(--glass-strong); opacity: 1; border-color: var(--glass-border);
  box-shadow: 0 8px 20px -10px rgba(138,63,224,0.5); color: #7a2fd0;
}
.tab-btn:hover { opacity: 1; }
.tab-btn:active { transform: scale(0.96); }

main { padding: 18px; max-width: 900px; margin: 0 auto; }
.tab-panel {
  display: none; background: var(--glass); border: 1px solid var(--glass-border); border-radius: 22px;
  padding: 20px; box-shadow: var(--shadow-soft); backdrop-filter: blur(14px);
}
.tab-panel.active { display: block; animation: panel-in 0.35s ease; }
@keyframes panel-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

h2 { margin-top: 0; font-family: Georgia, "Iowan Old Style", serif; color: var(--charcoal); }
.intro { color: var(--muted); font-size: 0.9rem; margin-top: -6px; }

/* ---------- Pelialue ---------- */
.play-layout { display: flex; flex-direction: column; align-items: center; gap: 16px; }

.play-hud { display: flex; gap: 10px; width: min(100%, 400px); }
.hud-box {
  flex: 1; background: rgba(255,255,255,0.55); border: 1px solid var(--glass-border); border-radius: 16px;
  padding: 8px 10px; text-align: center; box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}
.hud-box .label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.hud-box .value {
  font-family: ui-monospace, "SF Mono", Consolas, monospace; font-variant-numeric: tabular-nums;
  font-size: 1.3rem; font-weight: 800; color: var(--charcoal);
}

/* Tumma "huone"-paneeli jonka sisällä valot hehkuvat */
.board-wrap {
  position: relative;
  width: min(100%, 400px);
  border-radius: 26px;
  padding: clamp(10px, 2.4vmin, 18px);
  background: linear-gradient(160deg, #2a2444, #1a1630);
  border: 1.5px solid rgba(255,255,255,0.08);
  box-shadow:
    0 30px 60px -25px rgba(10, 5, 25, 0.7),
    inset 0 2px 3px rgba(255,255,255,0.06),
    inset 0 -14px 30px -18px rgba(0,0,0,0.5);
  transition: transform 0.05s linear;
}
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: 18px;
  overflow: hidden;
  touch-action: none;
}
.fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.grid {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n, 5), 1fr);
  grid-template-rows: repeat(var(--n, 5), 1fr);
  gap: clamp(4px, 1.6vmin, 8px);
}
.cell {
  border: none;
  border-radius: 20%;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 90ms ease, background 160ms ease, box-shadow 160ms ease;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), inset 0 -4px 8px -4px rgba(0,0,0,0.35);
}
.cell::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0.04) 35%, rgba(255,255,255,0) 55%);
}
.cell:active { transform: scale(0.92); }
.cell.hint-target { box-shadow: 0 0 0 3px var(--gold), inset 0 1px 0 rgba(255,255,255,0.3); animation: hint-glow 900ms ease-in-out infinite; }
@keyframes hint-glow { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.3); } }
.cell.pop { animation: cell-pop 220ms ease; }
@keyframes cell-pop { 0% { transform: scale(1); } 40% { transform: scale(0.86); } 100% { transform: scale(1); } }

.popups { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.score-pop {
  position: absolute; font-family: ui-monospace, "SF Mono", monospace; font-weight: 800; font-size: 0.95rem;
  color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,0.8);
  transform: translate(-50%, -50%); animation: float-up 750ms ease-out forwards;
}
.score-pop.combo {
  color: #fff; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--grad-accent); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; text-shadow: none; filter: drop-shadow(0 2px 6px rgba(177,75,255,0.6));
}
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.9); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -130%) scale(1.05); }
}

/* ---------- Kehityskaari ---------- */
.chain-wrap { width: min(100%, 400px); }
.chain-title {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted);
  font-weight: 800; text-align: center; margin-bottom: 6px;
}
.chain {
  display: flex; align-items: center; justify-content: center; flex-wrap: nowrap; gap: 4px;
  background: rgba(255,255,255,0.4); border: 1px solid var(--glass-border); border-radius: 16px;
  padding: 8px 6px; box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
  overflow-x: auto; scrollbar-width: none;
}
.chain::-webkit-scrollbar { display: none; }
.chain-cell {
  min-width: 26px; height: 26px; padding: 0 3px; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; flex-shrink: 0; font-family: ui-monospace, "SF Mono", monospace; font-weight: 800;
  font-size: 0.7rem; color: #fff; box-shadow: inset 0 1px 0 rgba(255,255,255,0.25);
  background: linear-gradient(160deg, #3a3350, #241f3d);
}
.chain-cell.goal { box-shadow: 0 0 0 2px var(--gold), 0 0 8px rgba(255,191,71,0.6); }
.chain-cell.locked {
  background: rgba(36,31,61,0.12); color: var(--muted); font-weight: 800; font-size: 0.7rem;
  box-shadow: none;
}

.controls { display: flex; gap: 8px; width: min(100%, 400px); flex-wrap: wrap; }
.controls button {
  font-family: inherit; font-size: 0.8rem; font-weight: 700; padding: 12px 10px; border-radius: 14px;
  border: 1px solid var(--glass-border); background: rgba(255,255,255,0.55); color: var(--ink); cursor: pointer;
  display: flex; align-items: center; gap: 6px; justify-content: center; flex: 1;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
}
.controls button:hover { background: rgba(255,255,255,0.75); }
.controls button:active { transform: scale(0.95); }
.controls button:disabled { opacity: 0.4; cursor: not-allowed; }
.controls button.primary {
  background: var(--grad-accent); color: white; border-color: transparent;
  box-shadow: 0 10px 22px -10px rgba(177,75,255,0.6);
}
.controls button.hidden-control { display: none; }
.charge-count { font-size: 0.7rem; background: rgba(0,0,0,0.1); border-radius: 6px; padding: 1px 6px; }

.hint { margin: 0; text-align: center; font-size: 0.75rem; color: var(--muted); width: min(100%, 400px); line-height: 1.5; }

/* ---------- Kauppa / Kosmetiikka / Tilastot ---------- */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.shop-card {
  border: 1px solid var(--glass-border); border-radius: 18px; padding: 16px;
  background: rgba(255,255,255,0.55); box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
  transition: transform 0.15s, box-shadow 0.2s;
}
.shop-card:hover { transform: translateY(-2px); box-shadow: 0 14px 28px -18px rgba(28,24,48,0.5); }
.shop-card.affordable { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), inset 0 1px 0 rgba(255,255,255,0.6); }
.shop-card h3 { margin: 0 0 6px; font-size: 1.05rem; display: flex; align-items: center; gap: 6px; color: var(--charcoal); }
.shop-card .tier-current { font-size: 0.8rem; color: var(--muted); margin-bottom: 10px; }
.shop-card button {
  width: 100%; padding: 11px; border: none; border-radius: 12px; background: var(--grad-accent); color: white;
  font-weight: 800; cursor: pointer; font-size: 0.85rem; transition: transform 0.12s, filter 0.15s;
}
.shop-card button:hover { filter: brightness(1.05); }
.shop-card button:active { transform: scale(0.96); }
.shop-card button:disabled { background: #ded9e8; color: #948da3; cursor: not-allowed; filter: none; }
.shop-card .maxed { color: var(--green); font-weight: 800; font-size: 0.85rem; }
.shop-card.equipped { border-color: var(--green); box-shadow: 0 0 0 2px rgba(47,174,99,0.3); }
.shop-card button.equip-btn { background: linear-gradient(135deg, #35c26f, #22a35c); }
.shop-card .equipped-tag { color: var(--green); font-weight: 800; font-size: 0.85rem; }

.cosmetic-preview {
  height: 56px; border-radius: 12px; margin-bottom: 10px; display: flex; overflow: hidden;
  border: 1px solid var(--glass-border); box-shadow: inset 0 2px 6px rgba(0,0,0,0.1);
}
.cosmetic-preview span { flex: 1; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stats-grid .stat-card {
  border: 1px solid var(--glass-border); border-radius: 16px; padding: 16px; text-align: center;
  background: rgba(255,255,255,0.55); box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}
.stats-grid .stat-card .num { font-size: 1.4rem; font-weight: 900; display: block; font-variant-numeric: tabular-nums; color: var(--charcoal); }
.stats-grid .stat-card .label { font-size: 0.76rem; color: var(--muted); }

.danger-btn {
  background: linear-gradient(135deg, #ef5a4f, #cf3a30); border: none; color: white; padding: 11px 20px;
  border-radius: 12px; font-weight: 800; cursor: pointer; box-shadow: 0 10px 20px -12px rgba(207,58,48,0.7);
}
.danger-btn:active { transform: scale(0.97); }

/* ---------- Ylivuoto (ratkaistu) ---------- */
.result-overlay {
  position: fixed; inset: 0; background: rgba(28,24,48,0.55); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 20;
}
.result-overlay.show { display: flex; animation: fade-in 0.3s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.result-card {
  background: var(--glass-strong); border: 1px solid var(--glass-border); border-radius: 24px;
  padding: 30px 26px; max-width: 340px; width: 100%; text-align: center;
  box-shadow: 0 30px 60px -25px rgba(10,5,25,0.7); backdrop-filter: blur(18px);
  animation: card-pop 0.4s cubic-bezier(0.2,1.3,0.4,1);
}
@keyframes card-pop { from { opacity: 0; transform: scale(0.85) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.result-card h2 {
  margin: 0 0 8px; font-size: 1.5rem;
  background: var(--grad-accent); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.result-card p { margin: 0 0 8px; color: var(--muted); font-size: 0.92rem; line-height: 1.5; }
.result-card .earned { color: #d98a1a; font-weight: 900; font-size: 1.15rem; margin-bottom: 20px; }
.result-card .row { display: flex; gap: 10px; }
.result-card .row button {
  flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--glass-border); background: rgba(255,255,255,0.6);
  font-weight: 800; cursor: pointer; font-size: 0.85rem; transition: transform 0.12s;
}
.result-card .row button:active { transform: scale(0.96); }
.result-card .row button.primary { background: var(--grad-accent); color: white; border-color: transparent; box-shadow: 0 10px 22px -10px rgba(177,75,255,0.6); }

@media (max-width: 480px) {
  main { padding: 14px; }
  .topbar { padding: 12px 14px; }
  .brand-text h1 { font-size: 1.2rem; }
}
