:root {
  --paper: #f4ecdd;
  --paper-dark: #e9dfc8;
  --ink: #1c1917;
  --red: #c62828;
  --red-deep: #8e1b1b;
  --cyan: #4fb8c9;
  --gold: #d9a441;
  --shadow: 5px 5px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --font: "Bricolage Grotesque", "Segoe UI", sans-serif;
  --hand: "Caveat", cursive;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 20% 10%, rgba(198, 40, 40, 0.05) 0 40%, transparent 41%),
    radial-gradient(circle at 85% 80%, rgba(79, 184, 201, 0.07) 0 50%, transparent 51%);
}

main { max-width: 960px; margin: 0 auto; padding: 16px 16px 80px; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px 10px; max-width: 960px; margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-stamp {
  display: inline-block; background: var(--red); color: var(--paper);
  font-weight: 800; font-size: 15px; line-height: 1.05; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 8px 10px; border: 2.5px solid var(--ink);
  box-shadow: var(--shadow-sm); transform: rotate(-3deg); text-align: center;
}

.brand-meta { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.brand-meta b { font-size: 20px; font-weight: 800; }
.brand-meta span { font-size: 12px; opacity: 0.65; margin-right: 10px; text-transform: lowercase; }

.tabs { display: flex; gap: 8px; }

.tab {
  font-family: var(--font); font-weight: 700; font-size: 14px; cursor: pointer;
  background: var(--paper); color: var(--ink); border: 2px solid var(--ink);
  padding: 7px 14px; border-radius: 999px; transition: transform 0.08s, box-shadow 0.08s;
}
.tabs a { display: inline-block; text-decoration: none; }
.tab:hover { transform: translate(-1px, -1px); box-shadow: var(--shadow-sm); }
.tab.active { background: var(--ink); color: var(--paper); box-shadow: var(--shadow-sm); }

.panel { display: none; }
.panel.active { display: block; }

.steps { display: flex; align-items: center; gap: 8px; margin: 10px 0 22px; flex-wrap: wrap; }

.step-dot {
  font-size: 13px; font-weight: 700; text-transform: lowercase;
  border: 2px solid var(--ink); border-radius: 999px; padding: 5px 12px;
  background: var(--paper); opacity: 0.45;
}
.step-dot.active { background: var(--ink); color: var(--paper); opacity: 1; box-shadow: var(--shadow-sm); }
.step-dot.done { opacity: 1; background: var(--cyan); }
.step-arrow { font-weight: 800; opacity: 0.4; }

h2.hand-note, .hand-note {
  font-family: var(--hand); font-size: 26px; font-weight: 700;
  margin-bottom: 14px; transform: rotate(-1deg);
}

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.mode-card {
  font-family: var(--font); text-align: left; cursor: pointer; color: var(--ink);
  background: #fffdf6; border: 2.5px solid var(--ink); border-radius: 10px;
  padding: 18px 16px; box-shadow: var(--shadow); transition: transform 0.1s, box-shadow 0.1s;
  display: flex; flex-direction: column; gap: 6px;
}
.mode-card:hover { transform: translate(-2px, -2px) rotate(-0.5deg); box-shadow: 7px 7px 0 var(--ink); }
.mode-card:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.mode-card.selected { background: var(--cyan); transform: rotate(-1deg); }
.mode-card strong { font-size: 22px; font-weight: 800; }
.mode-card small { font-size: 13px; line-height: 1.35; opacity: 0.75; }

.config {
  margin-top: 20px; padding: 18px; background: #fffdf6;
  border: 2.5px dashed var(--ink); border-radius: 12px;
  animation: pop-in 0.2s ease-out;
}
.config-fields { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 6px; }
.config-fields label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 700; }
.config-fields input {
  font-family: var(--font); font-size: 20px; font-weight: 800; width: 130px;
  padding: 8px 12px; border: 2.5px solid var(--ink); border-radius: 8px;
  background: var(--paper); color: var(--ink);
}
.config-note { font-size: 20px; opacity: 0.8; margin-bottom: 12px; }

.side-forms { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: start; margin-bottom: 14px; }

.side-form {
  background: #fffdf6; border: 2.5px solid var(--ink); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
}
.side-form.a { transform: rotate(-0.4deg); }
.side-form.b { transform: rotate(0.4deg); }

.side-tag {
  align-self: flex-start; font-size: 12px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.08em; padding: 3px 10px; border-radius: 999px;
  border: 2px solid var(--ink); margin-bottom: 4px;
}
.side-form.a .side-tag { background: var(--red); color: var(--paper); }
.side-form.b .side-tag { background: var(--cyan); }

.side-form label { font-size: 13px; font-weight: 700; margin-top: 6px; }
.side-form input {
  font-family: var(--font); font-size: 17px; font-weight: 700;
  padding: 9px 12px; border: 2.5px solid var(--ink); border-radius: 8px;
  background: var(--paper); color: var(--ink); width: 100%;
}
.side-form input:focus { outline: 3px solid var(--gold); outline-offset: 1px; }

.reg-note { font-family: var(--hand); font-size: 17px; color: var(--red-deep); min-height: 22px; }

.vs { font-family: var(--hand); font-size: 34px; font-weight: 700; align-self: center; transform: rotate(-6deg); }

.btn {
  font-family: var(--font); font-weight: 800; font-size: 15px; cursor: pointer;
  border: 2.5px solid var(--ink); border-radius: 10px; padding: 10px 18px;
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow-sm);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: var(--shadow-sm); }
.btn.primary { background: var(--red); color: var(--paper); }
.btn.ghost { background: #fffdf6; }
.btn.danger { background: var(--ink); color: var(--paper); }
.btn.big { font-size: 18px; padding: 13px 26px; }
.btn.block { width: 100%; }

.row { display: flex; gap: 12px; justify-content: space-between; align-items: center; margin-top: 8px; }

.hint { font-size: 13.5px; opacity: 0.65; line-height: 1.45; }
.hint.center { text-align: center; margin-top: 14px; }

.game-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }

.chip {
  font-size: 13px; font-weight: 800; text-transform: lowercase; letter-spacing: 0.04em;
  background: var(--gold); border: 2px solid var(--ink); border-radius: 999px;
  padding: 5px 13px; box-shadow: var(--shadow-sm); transform: rotate(-1.5deg);
}

.game-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.timer-bar {
  position: relative; height: 42px; border: 2.5px solid var(--ink); border-radius: 10px;
  background: #fffdf6; box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 14px;
}
.timer-fill { position: absolute; inset: 0; background: var(--cyan); transform-origin: left; transition: transform 0.3s linear; }
.timer-fill.low { background: var(--red); }
.timer-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; letter-spacing: 0.05em; mix-blend-mode: multiply;
}

.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; margin-bottom: 18px; }

.sc-card {
  background: #fffdf6; border: 2.5px solid var(--ink); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow); text-align: center;
  display: flex; flex-direction: column; gap: 2px; position: relative; overflow: hidden;
}
.sc-card.a::before, .sc-card.b::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 8px;
}
.sc-card.a::before { background: var(--red); }
.sc-card.b::before { background: var(--cyan); }

.sc-name { font-size: 15px; font-weight: 800; margin-top: 4px; }
.sc-value { font-size: 52px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.sc-sub { font-size: 12.5px; opacity: 0.7; min-height: 17px; font-weight: 700; }

.sc-vs { font-family: var(--hand); font-size: 30px; font-weight: 700; align-self: center; transform: rotate(-8deg); }

.sc-card.turn { outline: 4px solid var(--gold); outline-offset: 2px; }
.sc-card.scored { animation: score-pop 0.35s ease-out; }

@keyframes wobble {
  0%, 100% { transform: rotate(-0.5deg); }
  50% { transform: rotate(0.5deg); }
}
@keyframes score-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.04) rotate(-1deg); }
  100% { transform: scale(1); }
}

#cups-wrap { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: start; }

.cups-side { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.cups-label {
  font-size: 13px; font-weight: 800; text-transform: lowercase;
  border: 2px solid var(--ink); border-radius: 999px; padding: 3px 12px;
  background: #fffdf6; box-shadow: var(--shadow-sm);
}

.pyramid { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.cup-row { display: flex; gap: 12px; justify-content: center; }

.cup {
  width: 64px; height: 64px; border-radius: 50% 50% 46% 46%; cursor: pointer;
  border: 3px solid var(--ink); background: var(--red); color: #fff;
  font-family: var(--font); font-weight: 800; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm); position: relative;
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}
.cup::after {
  content: ""; position: absolute; top: 7px; left: 14px; right: 14px; height: 8px;
  background: rgba(255, 255, 255, 0.35); border-radius: 999px;
}
.cup:hover { transform: translate(-1px, -2px) scale(1.05); box-shadow: 5px 6px 0 var(--ink); }
.cup:active { transform: translate(1px, 2px) scale(0.96); box-shadow: 0 0 0 var(--ink); }
.cup.sunk { background: var(--ink); opacity: 0.35; }
.cup.bump { animation: cup-bump 0.3s ease-out; }

@keyframes cup-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25) rotate(8deg); }
  100% { transform: scale(1); }
}

.cups-divider {
  align-self: center; writing-mode: vertical-rl; text-orientation: mixed;
  font-family: var(--hand); font-size: 19px; opacity: 0.6; transform: rotate(180deg);
  padding: 10px 4px; border-left: 2px dashed var(--ink);
}

#darts-turn-note { text-align: center; font-size: 23px; margin-bottom: 10px; }

.keypad {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; max-width: 640px; margin: 0 auto;
}
.key {
  font-family: var(--font); font-weight: 800; font-size: 18px; cursor: pointer;
  border: 2.5px solid var(--ink); border-radius: 10px; padding: 12px 4px;
  background: #fffdf6; color: var(--ink); box-shadow: var(--shadow-sm);
  transition: transform 0.06s, box-shadow 0.06s;
}
.key:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.key:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.key.special { background: var(--cyan); }
.key.miss { background: var(--paper-dark); font-size: 14px; }
.key.bust-shake { animation: shake 0.35s; background: var(--red); color: var(--paper); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.result {
  max-width: 480px; margin: 30px auto; text-align: center; padding: 34px 26px;
  background: #fffdf6; border: 3px solid var(--ink); border-radius: 16px; box-shadow: var(--shadow);
  transform: rotate(-0.6deg); animation: pop-in 0.3s ease-out;
}
.result-kicker {
  font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.14em;
  background: var(--gold); border: 2px solid var(--ink); border-radius: 999px;
  padding: 4px 14px; display: inline-block; transform: rotate(-2deg);
}
.result-name { font-size: 44px; font-weight: 800; margin: 14px 0 4px; line-height: 1.05; }
.result-score { font-size: 18px; font-weight: 700; opacity: 0.75; }
.result-saved { font-family: var(--hand); font-size: 21px; color: var(--red-deep); margin: 12px 0 18px; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.92) rotate(-0.6deg); }
  to { opacity: 1; transform: scale(1) rotate(-0.6deg); }
}

.list { display: flex; flex-direction: column; gap: 10px; }

.list-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #fffdf6; border: 2.5px solid var(--ink); border-radius: 10px;
  padding: 12px 16px; box-shadow: var(--shadow-sm);
}
.list-row .grow { flex: 1; min-width: 140px; }
.list-row .name { font-weight: 800; font-size: 17px; }
.list-row .sub { font-size: 12.5px; opacity: 0.65; }
.list-row .big-num { font-size: 26px; font-weight: 800; min-width: 40px; text-align: center; }
.list-row .rank {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px;
  background: var(--paper-dark); flex-shrink: 0;
}
.list-row .rank.gold { background: var(--gold); }
.list-row .rank.silver { background: #cfcfcf; }
.list-row .rank.bronze { background: #d29a6a; }

.mini-btn {
  font-family: var(--font); font-weight: 800; font-size: 13px; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 8px; padding: 5px 11px;
  background: var(--cyan); color: var(--ink); box-shadow: 2px 2px 0 var(--ink);
}
.mini-btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.mini-btn:active { transform: translate(1px, 1px); box-shadow: 0 0 0 var(--ink); }
.mini-btn.red { background: var(--red); color: var(--paper); }
.mini-btn.plain { background: var(--paper); }

.mode-tag {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em;
  border: 2px solid var(--ink); border-radius: 999px; padding: 2px 9px; background: var(--paper-dark);
}

.empty-note { font-family: var(--hand); font-size: 24px; text-align: center; opacity: 0.55; padding: 40px 0; }

.modal {
  position: fixed; inset: 0; background: rgba(28, 25, 23, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal[hidden] { display: none; }

.modal-card {
  position: relative; background: var(--paper); border: 3px solid var(--ink); border-radius: 16px;
  box-shadow: var(--shadow); padding: 26px 24px; max-width: 380px; width: 100%; text-align: center;
  animation: pop-in 0.25s ease-out;
}
.modal-card h3 { font-size: 24px; font-weight: 800; margin-bottom: 6px; }
.modal-close {
  position: absolute; top: 10px; right: 12px; font-size: 26px; font-weight: 800; cursor: pointer;
  background: none; border: none; color: var(--ink); line-height: 1;
}
.qr-box {
  display: inline-block; background: #fff; border: 2.5px solid var(--ink); border-radius: 10px;
  padding: 12px; margin: 12px 0 8px; box-shadow: var(--shadow-sm); transform: rotate(-1deg);
}
.qr-box svg, .qr-box img { display: block; width: 220px; height: 220px; }
.qr-url { font-weight: 800; font-size: 15px; word-break: break-all; margin-bottom: 4px; }
.qr-note { font-size: 19px; opacity: 0.75; margin: 0; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--ink); color: var(--paper); font-weight: 700; font-size: 15px;
  padding: 12px 22px; border-radius: 10px; border: 2px solid var(--ink);
  box-shadow: var(--shadow-sm); transition: transform 0.25s ease-out; z-index: 60;
  max-width: 90vw; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }

@media (max-width: 720px) {
  .modes { grid-template-columns: 1fr; }
  .side-forms { grid-template-columns: 1fr; }
  .vs { justify-self: center; }
  .scoreboard { grid-template-columns: 1fr; }
  .sc-vs { display: none; }
  #cups-wrap { grid-template-columns: 1fr; }
  .cups-divider { writing-mode: horizontal-tb; transform: none; border-left: none; border-top: 2px dashed var(--ink); padding: 6px 0; }
  .cup { width: 56px; height: 56px; font-size: 15px; }
  .keypad { grid-template-columns: repeat(4, 1fr); }
  .sc-value { font-size: 42px; }
  .topbar { justify-content: center; }
}
