:root {
  --ink: #2b2118;
  --paper: #fbf5e8;
  --accent: #8e3b46;
  --accent-ink: #fff8ef;
  --gold: #d9a441;
  --muted: #6f6253;
  --bg: #1f1a16;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#hud {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #3a2c22;
  color: var(--paper);
  border-radius: 10px;
  padding: 6px 10px;
  flex-wrap: wrap;
}
.hud-item { display: flex; flex-direction: column; min-width: 78px; flex: 1; }
.hud-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .7; }
.hud-item span:last-child { font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
.hud-btn {
  background: var(--gold); color: var(--ink); border: 0; border-radius: 8px;
  font-weight: 800; width: 40px; height: 36px; cursor: pointer; font-size: 15px;
}

#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 960 / 640;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
canvas#game { width: 100%; height: 100%; display: block; touch-action: manipulation; cursor: pointer; }

.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(31, 22, 15, .55);
  padding: 12px;
  overflow-y: auto;
}
.hidden { display: none !important; }

.card {
  background: var(--paper);
  border-radius: 14px;
  padding: 22px 26px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  border: 3px solid #e2cfa8;
  max-height: 100%;
  overflow-y: auto;
}
.card.wide { max-width: 620px; text-align: left; }
.card.wide h2, .card.wide .btn { display: block; margin-left: auto; margin-right: auto; text-align: center; }

h1, h2 { font-family: "Fraunces", Georgia, serif; margin: 0 0 10px; color: var(--accent); }
h1 { font-size: clamp(40px, 9vw, 72px); font-weight: 800; letter-spacing: .01em; line-height: 1; }
h2 { font-size: 28px; }
.studio { text-transform: uppercase; letter-spacing: .18em; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 700; }
.tagline { color: var(--muted); font-style: italic; margin: 6px 0 18px; }
.title-card { background: rgba(251, 245, 232, .96); }

.btn {
  font: inherit; font-weight: 800;
  border: 2px solid var(--accent);
  background: transparent; color: var(--accent);
  padding: 10px 20px; border-radius: 10px; cursor: pointer;
  min-width: 160px; font-size: 16px;
}
.btn:hover { background: rgba(142, 59, 70, .08); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-col { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

.how-list { padding-left: 20px; margin: 8px 0; }
.how-list li { margin: 4px 0; }
.muted { color: var(--muted); font-size: 14px; }

.board { padding: 0; margin: 10px 0 16px; list-style: none; counter-reset: rank; }
.board li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 10px; border-bottom: 1px dashed #d8c6a3;
  counter-increment: rank; font-variant-numeric: tabular-nums;
}
.board li::before { content: counter(rank) "."; width: 28px; color: var(--muted); font-weight: 700; }
.board li .name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .pts { font-weight: 800; }
.board li.me { background: #f4e2b8; border-radius: 6px; }
.board .empty::before { content: none; }

.stats { width: 100%; border-collapse: collapse; margin: 6px 0 16px; text-align: left; }
.stats td { padding: 5px 4px; border-bottom: 1px dashed #d8c6a3; }
.stats td:last-child { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats tr.total td { font-size: 18px; color: var(--accent); border-bottom: 0; }

.big-score { font-family: "Fraunces", Georgia, serif; font-size: 34px; margin: 4px 0; font-weight: 800; }
#score-form { margin-top: 12px; }
#score-form label { font-weight: 700; display: block; margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.row input {
  flex: 1; min-width: 0; font: inherit; padding: 9px 12px; border-radius: 10px;
  border: 2px solid #d8c6a3; background: #fff;
}
.row .btn { min-width: 0; }

.perk-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.perk {
  font: inherit; display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: #fff; border: 2px solid #e2cfa8; border-radius: 12px; padding: 14px 10px;
  cursor: pointer; color: var(--ink); text-align: center;
}
.perk:hover, .perk:focus-visible { border-color: var(--accent); background: #fff8ef; transform: translateY(-2px); }
.perk-icon { font-size: 34px; line-height: 1; }
.perk-name { font-weight: 800; color: var(--accent); }
.perk-desc { font-size: 13px; color: var(--muted); }

footer { text-align: center; color: #8a7b6a; font-size: 12px; padding: 4px; }

@media (max-width: 600px) {
  #app { padding: 4px; }
  .hud-item { min-width: 60px; }
  .hud-item span:last-child { font-size: 14px; }
  .card { padding: 14px 16px; }
  h2 { font-size: 22px; }
  .btn { min-width: 120px; padding: 8px 14px; font-size: 15px; }
  .perk-list { grid-template-columns: 1fr; }
  .perk { flex-direction: row; text-align: left; padding: 10px; }
  .perk-icon { font-size: 26px; }
  .perk-name { min-width: 110px; }
}
