:root {
  --ink: #1d2433;
  --muted: #5b6577;
  --card: rgba(255, 255, 255, 0.95);
  --green: #4cd964;
  --green-dark: #2a9e45;
  --gold: #ffcc33;
  --gold-dark: #cc9a00;
  --slate: #3a4558;
  --slate-dark: #222a37;
  --purple: #9945ff;
  --teal: #14f195;
  --red: #e53935;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8fd3ff;
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 600;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

a { color: #6b2fd6; }

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

.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.hud { pointer-events: none !important; }
.hud .score {
  font-family: 'Lilita One', sans-serif;
  font-size: 64px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.hud .top {
  font-family: 'Lilita One', sans-serif;
  font-size: 18px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.bar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.coin {
  display: inline-block;
  width: 1em;
  height: 1em;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #ffe27a 0 34%, #ffcc33 36% 100%);
  box-shadow: inset 0 -2px 0 #d9a400;
  vertical-align: -0.15em;
}
.coin-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Lilita One', sans-serif;
  font-size: 20px;
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px 6px 10px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
}
.coin-pill b { font-weight: 400; }
.addr {
  font: 800 13px 'Nunito', sans-serif;
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--muted);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
  cursor: pointer;
}
.addr:hover { background: #ffe3e3; color: var(--red); }

/* ---------- buttons ---------- */
.btn {
  font-family: 'Lilita One', sans-serif;
  font-size: 18px;
  letter-spacing: 0.5px;
  border: 0;
  border-radius: 14px;
  padding: 12px 20px;
  cursor: pointer;
  color: #fff;
  background: var(--slate);
  box-shadow: 0 5px 0 var(--slate-dark);
  transition: transform 0.06s, box-shadow 0.06s, filter 0.15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--slate-dark); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--green); box-shadow: 0 5px 0 var(--green-dark); }
.btn.primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--green-dark); }
.btn.gold { background: var(--gold); color: #4a3500; box-shadow: 0 5px 0 var(--gold-dark); }
.btn.gold:active:not(:disabled) { box-shadow: 0 1px 0 var(--gold-dark); }
.btn.big { font-size: 28px; padding: 14px 44px; }
.btn.small { font-size: 15px; padding: 9px 14px; box-shadow: 0 4px 0 var(--slate-dark); }
.btn.small.primary { box-shadow: 0 4px 0 var(--green-dark); }
.btn.small.gold { box-shadow: 0 4px 0 var(--gold-dark); }

/* ---------- overlay screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 20px;
  padding: 96px 16px 24px;
  overflow-y: auto;
  pointer-events: none;
}
.card {
  pointer-events: auto;
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 22px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.14), 0 24px 48px rgba(0, 0, 0, 0.16);
}

.logo {
  margin: 0;
  font-family: 'Lilita One', sans-serif;
  font-weight: 400;
  font-size: 60px;
  line-height: 1;
  letter-spacing: 1px;
  filter: drop-shadow(0 5px 0 rgba(0, 0, 0, 0.18));
}
.sol-word {
  background: linear-gradient(135deg, var(--purple), #5e7bff 60%, var(--teal));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hop-word { color: var(--green); }

.tag { margin: 10px 0 20px; color: var(--muted); font-size: 16px; line-height: 1.4; }
.keys { margin: 14px 0 0; color: var(--muted); font-size: 13px; }

.coin-note {
  margin: 18px 0 0;
  padding: 12px 14px;
  background: #fff8e1;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  color: #6b5400;
}

.board-card h2 { margin: 0 0 12px; font: 400 26px 'Lilita One', sans-serif; }
.board { list-style: none; margin: 0; padding: 0; text-align: left; }
.board li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 15px;
}
.board li:nth-child(odd) { background: #f4f6fa; }
.board li.me { background: #e5fbe9; }
.board li.empty { justify-content: center; color: var(--muted); background: none; }
.board .rank { font-family: 'Lilita One', sans-serif; width: 22px; color: var(--muted); }
.board li:nth-child(1) .rank { color: #e0a800; }
.board .who { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.board b { font-family: 'Lilita One', sans-serif; font-weight: 400; font-size: 18px; }
.pool { margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.fine { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- game over ---------- */
.cause { margin: 0; font: 400 26px 'Lilita One', sans-serif; color: var(--red); }
.final { margin: 8px 0 2px; display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.final b { font: 400 84px 'Lilita One', sans-serif; line-height: 1; }
.final span { font: 400 22px 'Lilita One', sans-serif; color: var(--muted); }
.best-line { margin: 0; color: var(--muted); }
.result {
  margin: 18px 0 8px;
  padding: 12px;
  border-radius: 14px;
  background: #fff8e1;
  font: 400 24px 'Lilita One', sans-serif;
}
.result small { display: block; margin-top: 2px; font: 600 13px 'Nunito', sans-serif; color: var(--muted); }
.board-line { margin: 0 0 18px; font-size: 14px; color: var(--muted); }
.board-line.ok { color: var(--green-dark); }
.board-line.err { color: #b3261e; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.actions .btn.big { min-width: 230px; }

/* ---------- character shop ---------- */
.shop-card { max-width: 560px; }
.shop-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.shop-head h2 { margin: 0; font: 400 28px 'Lilita One', sans-serif; }
.shop-head .coin-pill { box-shadow: none; background: #fff8e1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.char {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px 12px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: #f4f6fa;
  font: 600 14px 'Nunito', sans-serif;
  color: var(--ink);
  cursor: pointer;
}
.char:hover { background: #eaf6ff; }
.char img { width: 84px; height: 84px; }
.char .name { font: 400 16px 'Lilita One', sans-serif; }
.char .tag-line { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.char.selected { border-color: var(--green); background: #e9fbe9; }
.char.locked img { filter: saturate(0.7) brightness(0.9); opacity: 0.85; }
.char.affordable .tag-line { color: #8a6a00; font-weight: 800; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  max-width: min(520px, calc(100vw - 32px));
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 15px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.toast a { color: var(--teal); }

@media (max-width: 560px) {
  .hud .score { font-size: 48px; }
  .logo { font-size: 46px; }
  .card { padding: 20px; }
  .screen { align-content: flex-start; padding-top: 84px; }
  .btn.small { font-size: 14px; padding: 8px 11px; }
  .btn.big { font-size: 24px; padding: 12px 28px; }
  .coin-pill { font-size: 17px; }
}
