/* SLEIGH DEFENSE - Bold Cartoon Vector UI */
:root {
  --ink: #1d1433;
  --red: #e63946;
  --red-d: #a4161a;
  --green: #2bb24c;
  --green-d: #1b7a33;
  --gold: #ffc93c;
  --snow: #f4f8ff;
  --sky: #13254a;
  --good: #2ee86b;
  --warn: #ffd60a;
  --bad: #ff3b3b;
  --font: 'Arial Black', 'Segoe UI Black', 'Trebuchet MS', Impact, system-ui, sans-serif;
  --body: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #23407a 0%, var(--sky) 70%);
  color: var(--ink); font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}
body { display: flex; align-items: center; justify-content: center; }

/* Stage: canvas + overlays, 3:2, fit to viewport */
.sd-root, #stage {
  position: relative;
  width: min(100vw, 150vh);
  height: min(66.6667vw, 100vh);
  user-select: none;
  container-type: size;
}
.sd-root > canvas, #stage > canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; image-rendering: auto;
  border-radius: 0;
}
.sd-ui { position: absolute; inset: 0; pointer-events: none; font-size: clamp(9px, 1.6cqw, 18px); }
.sd-ui [hidden] { display: none !important; }
.sd-ui button, .sd-ui input, .sd-card, .sd-mute { pointer-events: auto; }

kbd {
  display: inline-block; min-width: 1.7em; padding: .1em .4em; margin: 0 .12em;
  font: 900 .85em/1.3 var(--font); text-align: center; color: var(--ink);
  background: #fff; border: 3px solid var(--ink); border-radius: .4em;
  box-shadow: 0 3px 0 var(--ink);
}
kbd.wide { min-width: 5em; }

/* ---------- HUD ---------- */
.sd-hud {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1em;
  padding: 2.4em 1.1em 0;
}
.sd-bars { display: flex; flex-direction: column; gap: .45em; width: 30%; }
.sd-bar { display: grid; grid-template-columns: 4.6em 1fr auto; align-items: center; gap: .4em; }
.sd-lbl, .sd-val {
  font: 900 .9em var(--font); color: #fff; letter-spacing: .04em;
  -webkit-text-stroke: 0; text-shadow: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink), 0 3px 0 var(--ink);
}
.sd-val { font-size: .75em; min-width: 4.2em; text-align: right; }
.sd-track {
  height: 1.15em; background: #3a2f55; border: 3px solid var(--ink); border-radius: 999px;
  overflow: hidden; box-shadow: 0 3px 0 var(--ink);
}
.sd-fill {
  display: block; height: 100%; width: 100%; border-radius: 999px;
  background: var(--good); transition: width .18s ease-out;
  box-shadow: inset 0 -.25em 0 rgba(0,0,0,.18), inset 0 .2em 0 rgba(255,255,255,.45);
}
.sd-fill[data-c="warn"] { background: var(--warn); }
.sd-fill[data-c="bad"] { background: var(--bad); animation: sdPulse .5s ease-in-out infinite alternate; }
[data-bar="sleigh"] .sd-fill[data-c="good"] { background: var(--gold); }

.sd-mid { text-align: center; }
.sd-wave, .sd-score {
  font: 900 1.05em var(--font); color: #fff; letter-spacing: .06em;
  text-shadow: -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink), 0 4px 0 var(--ink);
}
.sd-wave b { color: var(--gold); }
.sd-score { font-size: 1.9em; line-height: 1.1; }

.sd-right { display: flex; gap: .6em; align-items: center; width: 30%; justify-content: flex-end; }
.sd-cd { position: relative; width: 3.2em; height: 3.2em; }
.sd-cd svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.sd-cd-bg { fill: #ff7eb6; stroke: var(--ink); stroke-width: 7; }
.sd-cd-ring { fill: none; stroke: #fff; stroke-width: 4; stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset .1s linear; }
.sd-cd:not(.sd-ready) .sd-cd-bg { fill: #8b7f9e; }
.sd-cd-icon {
  position: absolute; inset: 22%; border-radius: 3px;
  background:
    linear-gradient(90deg, transparent 40%, var(--gold) 40% 60%, transparent 60%),
    linear-gradient(transparent 40%, var(--gold) 40% 60%, transparent 60%),
    var(--red);
  border: 2px solid var(--ink);
}
.sd-cd:not(.sd-ready) .sd-cd-icon { filter: grayscale(.8) brightness(.85); }
.sd-cd.sd-ready { animation: sdBob .9s ease-in-out infinite alternate; }
.sd-cd-key {
  position: absolute; right: -.35em; bottom: -.35em; font: 900 .7em var(--font);
  background: #fff; border: 2px solid var(--ink); border-radius: .35em; padding: 0 .3em; color: var(--ink);
}
.sd-mute {
  width: 2.8em; height: 2.8em; padding: .35em; cursor: pointer;
  background: #fff; border: 3px solid var(--ink); border-radius: 50%; box-shadow: 0 3px 0 var(--ink);
}
.sd-mute svg { width: 100%; height: 100%; display: block; }
.sd-mute:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.sd-mute.sd-muted { background: #e3e6ef; }

/* ---------- Screens ---------- */
.sd-screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: auto;
  background: rgba(19, 37, 74, .55);
}
.sd-title { background: rgba(19, 37, 74, .35); }
.sd-panel {
  background: var(--snow); border: 4px solid var(--ink); border-radius: 1.4em;
  box-shadow: 0 .5em 0 var(--ink), 0 1em 2em rgba(0,0,0,.35);
  padding: 1.2em 1.6em; text-align: center; position: relative;
  animation: sdPop .35s cubic-bezier(.2, 1.6, .4, 1) both;
}
.sd-panel::before { /* snowcap */
  content: ''; position: absolute; left: 6%; right: 6%; top: -1.05em; height: 1.4em;
  background: #fff; border: 4px solid var(--ink); border-bottom: none;
  border-radius: 1.2em 1.2em 0 0;
}
.sd-small { min-width: 40%; }
.sd-screen h2 {
  margin: 0 0 .4em; font: 900 2.4em var(--font); color: var(--gold); letter-spacing: .05em;
  text-shadow: -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink), 0 5px 0 var(--ink);
}
.sd-panel h2 { color: var(--red); }
.sd-title-panel { width: 82%; padding-top: .4em; }
.sd-logo svg { width: 78%; max-height: 32cqh; display: block; margin: 0 auto; filter: drop-shadow(0 6px 0 rgba(29,20,51,.25)); }
.sd-tag { margin: .1em 0 .7em; font-weight: 700; font-size: 1.05em; }
.sd-title-row { display: flex; gap: 1em; text-align: left; align-items: stretch; }
.sd-controls, .sd-mini {
  flex: 1.5; background: #fff; border: 3px solid var(--ink); border-radius: 1em; padding: .6em .9em;
  box-shadow: 0 4px 0 var(--ink);
}
.sd-mini { flex: 1; }
.sd-mini:empty { display: none; }
.sd-controls h3, .sd-mini h3 { margin: 0 0 .35em; font: 900 1em var(--font); color: var(--green-d); letter-spacing: .06em; }
.sd-controls ul { list-style: none; margin: 0; padding: 0; }
.sd-controls li { margin: .28em 0; font-size: .92em; display: flex; align-items: center; flex-wrap: wrap; gap: .1em; }
.sd-controls li span { margin: 0 .5em 0 .4em; font-weight: 700; }
.sd-tip { margin: .45em 0 0; font-size: .85em; font-weight: 700; color: #3c3357; }
.sd-tip em { color: var(--green); font-style: normal; font-weight: 900; }
.sd-mini ol { margin: 0; padding-left: 1.4em; font-size: .9em; }
.sd-mini li { display: list-item; margin: .2em 0; }
.sd-mini li span { font-weight: 900; }
.sd-mini li b { float: right; color: var(--red); }

.sd-btn {
  margin-top: .8em; padding: .55em 1.4em; cursor: pointer;
  font: 900 1.2em var(--font); letter-spacing: .05em; color: #fff;
  background: linear-gradient(var(--red), var(--red-d));
  border: 4px solid var(--ink); border-radius: 999px; box-shadow: 0 5px 0 var(--ink);
  text-shadow: 0 2px 0 var(--ink);
}
.sd-btn:hover { filter: brightness(1.08); }
.sd-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.sd-btn:disabled { filter: grayscale(.7); cursor: default; }
.sd-start { animation: sdBob .8s ease-in-out infinite alternate; }
.sd-btn:focus-visible, .sd-card:focus-visible, .sd-mute:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }

/* ---------- Upgrade cards ---------- */
.sd-cards { display: flex; gap: 1.4em; justify-content: center; }
.sd-card {
  position: relative; width: 13em; padding: 1.2em .9em 1em; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: .4em;
  background: #fff; border: 4px solid var(--ink); border-radius: 1.2em;
  box-shadow: 0 .45em 0 var(--ink); font-family: var(--body); color: var(--ink);
  transition: transform .12s, box-shadow .12s;
  animation: sdPop .4s cubic-bezier(.2, 1.6, .4, 1) both;
}
.sd-card:nth-child(2) { animation-delay: .07s; }
.sd-card:nth-child(3) { animation-delay: .14s; }
.sd-card.sd-sel, .sd-card:hover { transform: translateY(-.5em) scale(1.04) rotate(-1deg); box-shadow: 0 .9em 0 var(--ink); background: #fffbe6; }
.sd-card.sd-sel { outline: 4px solid var(--gold); outline-offset: 3px; }
.sd-key {
  position: absolute; top: -.9em; left: -.9em; width: 2em; height: 2em; line-height: 1.6em;
  font: 900 1.1em/1.6em var(--font); color: #fff; background: var(--green);
  border: 3px solid var(--ink); border-radius: 50%; box-shadow: 0 3px 0 var(--ink);
}
.sd-icon { width: 5em; height: 5em; display: block; }
.sd-icon svg { width: 100%; height: 100%; }
.sd-cname { font: 900 1.05em var(--font); color: var(--red); text-align: center; }
.sd-cdesc { font-size: .9em; font-weight: 700; text-align: center; line-height: 1.25; }
.sd-hint { margin-top: 1.4em; color: #fff; font-weight: 900; text-shadow: 0 2px 0 var(--ink); }

/* ---------- Game over ---------- */
.sd-over-panel { width: 62%; max-height: 92%; display: flex; flex-direction: column; padding-top: .4em; }
.sd-over-h { font-size: 2.8em !important; margin-bottom: .1em !important; }
.sd-final { margin: 0 0 .5em; font: 900 1.2em var(--font); }
.sd-final b { color: var(--red); font-size: 1.3em; }
.sd-final i { font-style: normal; color: var(--green-d); }
.sd-name-form label { display: block; font: 900 .9em var(--font); letter-spacing: .08em; color: var(--green-d); }
.sd-name-row { display: flex; gap: .5em; justify-content: center; align-items: center; }
.sd-name-row input {
  width: 11em; padding: .35em .6em; font: 900 1.3em var(--font); letter-spacing: .12em;
  text-transform: uppercase; text-align: center; color: var(--ink);
  background: #fff; border: 4px solid var(--ink); border-radius: .6em; box-shadow: inset 0 3px 0 #d9e3f2;
}
.sd-name-row input:focus { outline: 4px solid var(--gold); }
.sd-name-row .sd-btn { margin-top: 0; font-size: 1em; padding: .45em 1em; background: linear-gradient(#3fd36a, var(--green-d)); }
.sd-name-form.sd-done { display: none; }
.sd-name-err { min-height: 1.2em; margin: .25em 0 0; color: var(--red-d); font-weight: 900; font-size: .9em; }
.sd-status { min-height: 1.2em; margin: 0 0 .3em; font-weight: 900; color: var(--green-d); }
.sd-over .sd-board { overflow: auto; min-height: 0; flex: 1; border: 3px solid var(--ink); border-radius: .8em; background: #fff; }
.sd-board table { width: 100%; border-collapse: collapse; font-size: .9em; }
.sd-board th { position: sticky; top: 0; background: var(--ink); color: #fff; font: 900 .85em var(--font); padding: .35em; letter-spacing: .06em; }
.sd-board td { padding: .25em .5em; border-bottom: 2px dashed #d5dcea; font-weight: 700; }
.sd-board td:nth-child(2) { text-align: left; font-weight: 900; }
.sd-board td:last-child { text-align: right; color: var(--red); font-weight: 900; }
.sd-board tr:nth-child(1) td:first-child { color: #d9930d; font-weight: 900; }
.sd-board tr.sd-me td { background: #fff3b0; }
.sd-empty { margin: .8em; font-weight: 700; }
.sd-again { align-self: center; }

@keyframes sdPop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes sdBob { from { transform: translateY(0); } to { transform: translateY(-4px); } }
@keyframes sdPulse { from { filter: brightness(1); } to { filter: brightness(1.4); } }

@media (prefers-reduced-motion: reduce) {
  .sd-panel, .sd-card, .sd-start, .sd-cd.sd-ready, .sd-fill { animation: none !important; transition: none !important; }
}
