:root {
  --ink: #ffffff;
  --muted: #b8c6e8;
  --accent: #ffd23f;
  --accent-deep: #ffb703;
  --danger: #ff7a59;
  --panel-top: #243563;
  --panel-bottom: #131c37;
  font-family: ui-rounded, "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #141d36;
  color: var(--ink);
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

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

.hidden { display: none !important; }

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
  transition: opacity .25s ease;
}

#hud.hidden { display: flex !important; opacity: 0; visibility: hidden; }

.hud-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 2px solid rgba(255, 255, 255, .14);
  border-radius: 999px;
  background: rgba(13, 21, 43, .76);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .28);
  backdrop-filter: blur(8px);
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.hud-pill > span:first-child { color: #a9b8dd; }
.hud-pill strong {
  font-size: 1.3rem;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.hud-pill.time-warning strong { color: var(--danger); animation: pulse .55s ease-in-out infinite alternate; }
.hud-carry { gap: 6px; }
.hud-monsters strong { color: #ff9f9f; font-size: 1.12rem; white-space: nowrap; }

#carry-dots { display: inline-flex; gap: 4px; }
.carry-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .2);
  transition: background .15s ease, transform .15s ease;
}
.carry-dot.filled { border-color: rgba(255, 255, 255, .8); transform: scale(1.08); }

.hud-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.hud-button {
  pointer-events: auto;
  padding: 8px 12px;
  border: 2px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  background: rgba(13, 21, 43, .76);
  color: var(--muted);
  font: inherit;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.hud-button:active { transform: translateY(1px); }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 20%, rgba(46, 71, 130, .5), rgba(7, 11, 24, .8) 75%);
  backdrop-filter: blur(5px);
}

.panel {
  width: min(560px, 100%);
  margin: auto;
  padding: clamp(18px, 4vw, 34px);
  border: 2px solid rgba(255, 255, 255, .13);
  border-radius: 28px;
  background: linear-gradient(165deg, var(--panel-top), var(--panel-bottom));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .12);
  text-align: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: #91a8da;
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: clamp(1.9rem, 6vw, 3rem);
  line-height: 1.05;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .25);
}

h1 span { color: #fff; }

.tagline {
  margin: 0 auto 18px;
  max-width: 42ch;
  color: var(--muted);
  font-size: clamp(.95rem, 2.4vw, 1.05rem);
  line-height: 1.45;
}

.how-to {
  margin: 0 auto 22px;
  padding: 0 0 0 1.1em;
  max-width: 46ch;
  color: #dce5fb;
  font-size: .92rem;
  line-height: 1.55;
  text-align: left;
}
.how-to li { margin: 6px 0; }
.how-to li::marker { color: var(--accent); }
.how-to b { color: #fff; }

.big-button,
#score-form button {
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.big-button {
  padding: 15px 52px;
  background: linear-gradient(180deg, #ffe066, var(--accent-deep));
  color: #3c2500;
  font-size: 1.35rem;
  letter-spacing: .01em;
  box-shadow: 0 6px 0 #a86f00, 0 14px 28px rgba(0, 0, 0, .38);
  transition: transform .1s ease, box-shadow .1s ease, filter .15s ease;
}
.big-button:hover { filter: brightness(1.06); }
.big-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #a86f00, 0 8px 18px rgba(0, 0, 0, .34);
}

.big-button:focus-visible,
.hud-button:focus-visible,
input:focus-visible,
#score-form button:focus-visible {
  outline: 3px solid #8ce7ff;
  outline-offset: 3px;
}

.centres-count {
  margin: -6px 0 10px;
  color: #9fd6c8;
  font-size: .88rem;
  font-weight: 700;
}

.qualify {
  min-height: 1.4em;
  margin: 0 0 10px;
  color: var(--accent);
  font-weight: 800;
}

#score-form,
#win-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0 8px;
  text-align: left;
}
#score-form label,
#win-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
#score-form input,
#win-form input {
  width: 100%;
  padding: 11px 13px;
  border: 2px solid rgba(255, 255, 255, .16);
  border-radius: 13px;
  background: rgba(6, 11, 25, .62);
  color: #fff;
  font: inherit;
  font-size: 1rem;
  letter-spacing: 0;
  text-transform: none;
}
#score-form[hidden],
#win-form[hidden] { display: none; }
#score-form button,
#win-form button {
  grid-column: 1 / -1;
  padding: 12px 20px;
  background: #4cd964;
  color: #09360f;
  font-size: 1.02rem;
  box-shadow: 0 4px 0 #24802f;
}
#score-form button:active,
#win-form button:active { transform: translateY(2px); box-shadow: 0 2px 0 #24802f; }
#score-form button:disabled,
#win-form button:disabled { opacity: .55; cursor: wait; }

.form-status {
  min-height: 1.3em;
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: .88rem;
}

#play-again { margin-top: 6px; }

.scores-box {
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(4, 9, 22, .34);
  text-align: left;
}
.scores-box h2 {
  margin: 0 0 8px;
  color: #9fb2dd;
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.scores-status {
  margin: 0;
  color: var(--muted);
  font-size: .85rem;
}
.scores-board {
  display: grid;
  gap: 2px;
  max-height: 210px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.scores-board:empty { display: none; }
.scores-board li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 5px 3px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
  font-size: .9rem;
}
.scores-board li:last-child { border-bottom: 0; }
.scores-board .rank { color: var(--accent); font-weight: 900; }
.scores-board .score-value { color: #ffe066; font-variant-numeric: tabular-nums; font-weight: 800; }

#boss-bar {
  position: fixed;
  top: max(66px, calc(env(safe-area-inset-top) + 58px));
  left: 50%;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(520px, calc(100vw - 28px));
  padding: 7px 13px;
  border: 2px solid rgba(255, 122, 217, .55);
  border-radius: 999px;
  background: rgba(36, 12, 30, .88);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .38);
  backdrop-filter: blur(8px);
  color: #ffd9f2;
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}
#boss-bar.hidden { display: none; }
#boss-bar > span {
  max-width: 46%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.boss-track {
  flex: 1;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
}
#boss-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff5a5f, #ffd23f);
  transition: width .15s linear;
}

.big-score {
  margin: 4px 0 12px;
  color: var(--accent);
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .22);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border: 2px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  background: rgba(13, 21, 43, .92);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  color: #fff;
  font-size: .9rem;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 16px);
  transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: .45; }
}

@media (max-width: 560px) {
  #hud { gap: 5px; }
  .hud-pill { gap: 5px; padding: 5px 9px; font-size: .64rem; }
  .hud-pill strong { font-size: 1.1rem; }
  .hud-carry > span:first-child,
  .hud-monsters > span:first-child { display: none; }
  .carry-dot { width: 9px; height: 9px; }
  .hud-button { padding: 7px 9px; font-size: .64rem; }
  .panel { border-radius: 22px; }
  .how-to { font-size: .86rem; }
  #score-form,
  #win-form { grid-template-columns: 1fr; }
}

@media (max-width: 400px) {
  #hud { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .hud-pill { gap: 4px; padding: 4px 7px; }
  .hud-pill strong { font-size: 1rem; }
  #carry-dots { gap: 3px; }
  .carry-dot { width: 7px; height: 7px; }
  .hud-button { padding: 6px 7px; }
}

@media (max-width: 360px) {
  .hud-pill:first-child > span:first-child { display: none; }
  .hud-monsters strong { font-size: .95rem; }
}

@media (max-width: 400px) {
  #boss-bar { top: max(62px, calc(env(safe-area-inset-top) + 54px)); font-size: .62rem; }
}

@media (max-height: 560px) and (orientation: landscape) {
  #overlay { align-items: start; }
  .panel { padding: 16px 22px; }
  h1 { font-size: 1.8rem; }
  .how-to { font-size: .82rem; margin-bottom: 12px; }
  .tagline { margin-bottom: 10px; }
  .scores-board { max-height: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  .hud-pill.time-warning strong { animation: none; }
  * { scroll-behavior: auto; }
}
