/* ---- Spudvivor: dark, minimalist, purple-accented (Hotlap-Daily-styled) ---- */
:root {
  --bg: #eef0f6;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #f4f5f9;
  --line: #dcdee9;
  --text: #1b1c28;
  --muted: #62657a;
  --accent: #6d49d6;       /* purple, darkened for contrast on white */
  --accent-2: #5a37c0;
  --good: #1f9d57;
  --warn: #b9780f;
  --bad: #d23b3b;
  --xp: #2f9fd0;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  /* Montserrat stands in for Brandon Text (commercial, HVD Fonts) */
  --sans: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-2), var(--bg));
  color: var(--text);
  font-family: var(--sans);
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  /* mobile: no rubber-band scroll, no long-press selection / accidental zoom */
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
input { user-select: text; -webkit-user-select: text; }

#app {
  width: min(960px, 100vw);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* wraps the stage; a passthrough block on desktop, a centering box on mobile */
.stage-area { width: 100%; }

/* ---- top bar ---- */
#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: 1px; font-size: 18px; }
.brand span { color: var(--accent); }
.daily-tag { color: var(--muted); font-size: 13px; margin-left: auto; }

/* ---- stage ---- */
#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 960 / 600;
  background: #0a0a10;
}
#game {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  touch-action: none; /* the joystick handles touches here; don't scroll/zoom */
}

/* ---- touch joystick (floating, appears under the finger while playing) ---- */
#joystick {
  position: fixed; width: 104px; height: 104px;
  margin-left: -52px; margin-top: -52px;
  border-radius: 50%;
  border: 2px solid rgba(167, 121, 240, 0.55);
  background: rgba(20, 20, 30, 0.22);
  z-index: 60; pointer-events: none; touch-action: none;
}
#joyKnob {
  position: absolute; left: 50%; top: 50%;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(167, 121, 240, 0.65);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
}

/* on-screen pause button, lives in the HUD's top row */
.hud-btn {
  margin-left: auto; pointer-events: auto; cursor: pointer;
  background: rgba(20, 20, 30, 0.72); color: #f0f0f5;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 12px; font-size: 14px; line-height: 1;
}

/* ---- overlays ---- */
.overlay { position: absolute; inset: 0; }
.hidden { display: none !important; }
.screen {
  display: flex; align-items: center; justify-content: center;
  background: rgba(238, 240, 246, 0.9);
  backdrop-filter: blur(3px);
  padding: 16px;
  overflow: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  width: min(560px, 100%);
  box-shadow: 0 18px 50px rgba(40, 40, 70, .18);
}
.panel.wide { width: min(720px, 100%); }
.panel h1 { font-size: 30px; letter-spacing: 1px; }
.panel h2 { margin-top: 6px; font-size: 20px; }
.subtitle { color: var(--muted); margin: 8px 0 16px; line-height: 1.5; font-size: 14px; }
.muted { color: var(--muted); font-weight: 400; font-size: 13px; }

/* ---- buttons ---- */
.primary-btn {
  width: 100%; margin-top: 16px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 10px;
  padding: 12px 16px; font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform .06s ease, filter .15s ease;
}
.primary-btn:hover:not(:disabled) { filter: brightness(1.08); }
.primary-btn:active:not(:disabled) { transform: translateY(1px); }
.primary-btn:disabled { opacity: .4; cursor: not-allowed; }
.ghost-btn {
  background: transparent; color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 14px; font-size: 14px; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); }

/* ---- daily banner ---- */
.daily-banner {
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; font-size: 14px;
  margin-bottom: 18px;
}
.daily-banner b { color: var(--accent); font-family: var(--mono); }
.mode-toggle { margin-left: auto; color: var(--muted); cursor: pointer; user-select: none; }

/* ---- character select ---- */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.char-card {
  background: var(--panel-2); border: 2px solid var(--line);
  border-radius: 10px; padding: 12px; cursor: pointer; text-align: left;
  transition: border-color .12s ease, transform .06s ease;
}
.char-card:hover { transform: translateY(-2px); }
.char-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(167,121,240,.18); }
.char-card .emoji { font-size: 26px; }
.char-card .name { font-weight: 700; margin: 4px 0; }
.char-card .desc { color: var(--muted); font-size: 12px; line-height: 1.4; }

/* ---- HUD ---- */
/* HUD overlays the dark gameplay canvas, so it keeps light text + dark pills
   regardless of the (light) page theme. */
#hud { pointer-events: none; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; color: #f0f0f5; }
.hud-top { display: flex; gap: 8px; }
.hud-pill {
  background: rgba(20,20,30,.72); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; font-family: var(--mono);
}
.hud-bars { display: flex; flex-direction: column; gap: 5px; max-width: 320px; }
.bar {
  position: relative; height: 18px; border-radius: 6px; overflow: hidden;
  background: rgba(20,20,30,.72); border: 1px solid var(--line);
}
.bar-fill { position: absolute; inset: 0; transform-origin: left; width: 100%; }
.bar.hp .bar-fill { background: linear-gradient(90deg, #f06a6a, #ff8a5a); }
.bar.xp { height: 12px; }
.bar.xp .bar-fill { background: linear-gradient(90deg, var(--xp), var(--accent)); }
.bar span {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-family: var(--mono); text-shadow: 0 1px 2px #000;
}
.hud-weapons { display: flex; gap: 6px; }
.hud-weapons .wslot {
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  background: rgba(20,20,30,.72); border: 1px solid var(--line); border-radius: 8px; font-size: 16px;
}

/* ---- level up choices ---- */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; cursor: pointer; text-align: left;
}
.choice:hover { border-color: var(--accent); }
.choice .ico { font-size: 22px; }
.choice .lbl { font-weight: 700; margin-top: 4px; }
.choice .val { color: var(--good); font-family: var(--mono); }

/* ---- shop ---- */
.shop-panel { width: min(900px, 100%); }
.shop-head { display: flex; align-items: center; justify-content: space-between; }
.shop-money { font-family: var(--mono); font-size: 16px; }
.shop-money b { color: var(--warn); }
.shop-body { display: grid; grid-template-columns: 1fr 240px; gap: 16px; margin-top: 14px; }
.shop-offers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-content: start; }
.offer {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  display: flex; flex-direction: column; gap: 6px; min-height: 132px;
}
.offer.locked { border-color: var(--warn); }
.offer.tier-1 { border-left: 4px solid #9aa0b0; }
.offer.tier-2 { border-left: 4px solid #5ac8f0; }
.offer.tier-3 { border-left: 4px solid var(--accent); }
.offer.tier-4 { border-left: 4px solid var(--warn); }
.offer .otop { display: flex; align-items: center; gap: 8px; }
.offer .oemoji { font-size: 22px; }
.offer .oname { font-weight: 700; font-size: 14px; }
.offer .okind { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.offer .odesc { color: var(--muted); font-size: 12px; line-height: 1.4; flex: 1; }
.offer .obot { display: flex; gap: 6px; }
.offer .buy { flex: 1; }
.offer .buy:disabled { opacity: .4; cursor: not-allowed; }
.offer .lockbtn { padding: 8px 10px; }
.price { color: var(--warn); font-family: var(--mono); }

.shop-side h3 { font-size: 13px; color: var(--muted); margin: 4px 0 6px; text-transform: uppercase; letter-spacing: .5px; }
.loadout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.loadout .slot {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px dashed var(--line); border-radius: 8px;
  font-size: 18px; cursor: pointer; position: relative;
}
.loadout .slot.filled { border-style: solid; }
.loadout .slot.filled:hover { border-color: var(--bad); }
.loadout .slot .sell { position: absolute; bottom: 2px; font-size: 9px; color: var(--bad); }
.loadout .slot.empty { color: var(--muted); font-size: 12px; cursor: default; }
.loadout .slot .tierbadge {
  position: absolute; top: 2px; right: 4px; font-size: 9px; font-family: var(--mono);
  font-weight: 700; color: var(--accent);
}

/* weapon merging */
.merge-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.merge-btn {
  width: 100%; font-size: 12px; text-align: left; padding: 8px 10px;
  border-color: var(--accent); color: var(--accent);
}
.merge-btn:hover { background: rgba(109, 73, 214, .1); }

.statsheet { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; font-size: 12px; }
.statsheet .row { display: flex; justify-content: space-between; font-family: var(--mono); }
.statsheet .row .sv { color: var(--accent); }

.shop-foot { display: flex; gap: 10px; align-items: center; margin-top: 16px; }
.shop-foot .primary-btn { margin-top: 0; flex: 1; }

/* ---- end screen ---- */
.end-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.end-stats .row { display: flex; justify-content: space-between; background: var(--panel-2); padding: 8px 12px; border-radius: 8px; font-family: var(--mono); font-size: 13px; }
.end-stats .row b { color: var(--accent); }

/* ---- leaderboard ---- */
.lb-open { width: 100%; margin-top: 8px; }
.lb-head { display: flex; align-items: baseline; justify-content: space-between; }
.lb-list { margin: 12px 0 16px; max-height: 48vh; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.lb-row {
  display: grid; grid-template-columns: 34px 1fr auto auto; gap: 10px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font-size: 13px;
}
.lb-row .rank { font-family: var(--mono); color: var(--muted); font-weight: 700; }
.lb-row .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .pwave { font-family: var(--mono); color: var(--accent); }
.lb-row .pkills { font-family: var(--mono); color: var(--muted); }
.lb-row.me { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(109,73,214,.18); }
.lb-row .medal { font-size: 15px; }
.lb-empty, .lb-msg { color: var(--muted); font-size: 13px; padding: 14px 4px; text-align: center; line-height: 1.5; }
.lb-msg code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

/* end-screen submit block */
.lb-block { margin-top: 14px; }
.lb-submit { display: flex; gap: 8px; margin-top: 6px; }
.lb-submit input {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 9px 12px; font-family: var(--sans); font-size: 14px;
}
.lb-submit input:focus { outline: none; border-color: var(--accent); }
.lb-submit button { white-space: nowrap; }
.lb-result { margin-top: 10px; font-size: 14px; }
.lb-result b { color: var(--accent); }

/* ---- footer ---- */
#footer { padding: 10px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 760px) {
  .shop-body { grid-template-columns: 1fr; }
  .choice-grid { grid-template-columns: 1fr; }
  .shop-panel { width: 100%; }
}

/* phones & touch devices: fit the canvas to the screen, full-screen menus,
   no footer, comfortable tap targets */
@media (max-width: 860px), (pointer: coarse) {
  #app { height: 100dvh; }
  .stage-area {
    flex: 1; min-height: 0;
    display: flex; align-items: center; justify-content: center;
    background: #0a0a10;
  }
  #stage { max-width: 100%; max-height: 100%; }   /* JS sizes it precisely */
  #footer { display: none; }
  #topbar { padding: 8px 12px; gap: 8px; }
  .brand { font-size: 16px; }
  .daily-tag { font-size: 12px; }

  /* menus/shop/end/pause cover the whole viewport instead of the small canvas */
  .overlay.screen { position: fixed; z-index: 80; padding: 12px; }

  /* fatter tap targets */
  .ghost-btn, .primary-btn { padding: 12px 14px; }
  .offer { min-height: 120px; }
  .offer .buy, .offer .lockbtn { padding: 11px 10px; }
  .loadout .slot { font-size: 20px; }
  .char-card { padding: 14px; }
}
