:root {
  --bg: #14121c;
  --panel: rgba(28, 25, 40, 0.86);
  --panel-solid: #1f1b2d;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f3f0fa;
  --muted: #a9a3bb;
  --gold: #f5b041;
  --gold-dark: #c8861a;
  --accent: #7bd3c4;
  --danger: #ff7a7a;
  --radius: 14px;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }

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

.hud {
  position: fixed; top: 12px; left: 12px; right: 12px;
  display: flex; align-items: center; gap: 12px; pointer-events: none;
}
.hud > * { pointer-events: auto; }
.brand { font-weight: 800; font-size: 18px; letter-spacing: 0.3px; margin-right: auto; text-shadow: 0 2px 8px rgba(0,0,0,.5); }
.brand span { color: var(--gold); margin-left: 4px; }

.coins {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px 6px 8px; font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums;
  backdrop-filter: blur(8px);
}
.coin-icon {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe39a, var(--gold) 55%, var(--gold-dark));
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.2);
}
.coins.bump { animation: bump .25s ease; }
@keyframes bump { 50% { transform: scale(1.08); } }

.pill {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; backdrop-filter: blur(8px); white-space: nowrap;
}
.pill:hover { border-color: rgba(255,255,255,.25); }

.progress {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  width: min(520px, calc(100% - 24px)); pointer-events: none;
}
.progress-label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 6px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.progress-label span:first-child { color: var(--text); font-weight: 700; }
.bar { height: 8px; border-radius: 999px; background: rgba(255,255,255,.1); overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width .2s ease; }

.shop {
  position: fixed; right: 12px; top: 110px; width: 300px; max-height: calc(100% - 200px);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(10px); overflow: hidden;
}
.panel-head { display: flex; align-items: center; border-bottom: 1px solid var(--line); padding: 6px; gap: 4px; flex-shrink: 0; }
.ptabs { display: flex; gap: 2px; flex: 1; min-width: 0; }
.ptab { flex: 1; background: none; border: 0; border-radius: 8px; padding: 7px 4px; font-size: 12.5px; font-weight: 700; color: var(--muted); position: relative; white-space: nowrap; }
.ptab.active { background: rgba(255,255,255,.1); color: var(--text); }
.ptab .dot { position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.collapse { background: none; border: 0; color: var(--muted); padding: 6px 8px; font-size: 14px; }
.shop.collapsed .collapse { transform: rotate(-90deg); }
.shop.collapsed .panel-body { display: none !important; }
.panel-body {
  overflow-y: auto; padding: 8px;
  /* without min-height: 0 a flex child never shrinks below its content, so the panel
     was cut off instead of scrolling (on phones especially) */
  min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch;
}
.sub-hint { padding: 0 6px; margin: -4px 0 8px; }
.upgrade.booster .lvl { color: var(--gold); }
.panel-body[hidden] { display: none; }
.shop-list { display: grid; gap: 8px; }

.upgrade {
  display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px;
  background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; text-align: left;
}
.upgrade:not(:disabled):hover { background: rgba(255,255,255,.08); border-color: rgba(245,176,65,.5); }
.upgrade:disabled { cursor: default; }
.upgrade:disabled .price { opacity: .45; }
.upgrade .icon { font-size: 20px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: rgba(255,255,255,.07); }
.upgrade .name { font-weight: 700; font-size: 14px; }
.upgrade .lvl { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 4px; }
.upgrade .desc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.upgrade .price { display: flex; align-items: center; gap: 4px; font-weight: 800; font-size: 13px; color: var(--gold); white-space: nowrap; }
.upgrade .price::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); }
.upgrade.maxed .price { color: var(--muted); }
.upgrade.maxed .price::before { display: none; }

.stats { padding: 0 6px; font-size: 12px; color: var(--muted); display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; }
.stats b { color: var(--text); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

.tools { position: fixed; left: 12px; bottom: 12px; display: flex; gap: 8px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 72px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; font-size: 12px; font-weight: 700; backdrop-filter: blur(8px);
}
.tool-icon { font-size: 20px; line-height: 1; }
.tool.active { border-color: var(--gold); color: var(--gold); }
.tool[hidden] { display: none; }

.toasts { position: fixed; left: 50%; top: 110px; transform: translateX(-50%); display: grid; gap: 8px; pointer-events: none; z-index: 5; }
.toast {
  background: var(--panel-solid); border: 1px solid rgba(245,176,65,.5); border-radius: 12px;
  padding: 10px 16px; font-weight: 700; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.4);
  animation: toast 3.2s ease forwards;
}
.toast small { display: block; color: var(--gold); font-size: 13px; margin-top: 2px; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 22px; width: min(380px, calc(100% - 32px));
  background: var(--panel-solid); color: var(--text);
}
dialog::backdrop { background: rgba(8, 6, 14, .6); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 6px; font-size: 20px; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.4; margin: 0 0 14px; }
.tabs { display: flex; gap: 4px; background: rgba(255,255,255,.06); padding: 4px; border-radius: 10px; margin-bottom: 14px; }
.tab { flex: 1; background: none; border: 0; border-radius: 8px; padding: 8px; font-weight: 700; color: var(--muted); }
.tab.active { background: rgba(255,255,255,.1); color: var(--text); }
dialog label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
dialog input {
  font: inherit; color: var(--text); background: rgba(0,0,0,.25); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; -webkit-user-select: text; user-select: text;
}
dialog input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 0 0 10px; }
.row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.primary { background: var(--gold); color: #2a1a00; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 800; }
.primary:disabled { opacity: .6; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; color: var(--muted); }

.fatal { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; background: var(--bg); }
.fatal[hidden] { display: none; }

@media (max-width: 640px) {
  .brand { font-size: 15px; }
  .brand span { display: block; margin-left: 0; }
  .coins { font-size: 17px; }
  .pill { font-size: 13px; padding: 7px 11px; }
  .progress { top: 60px; }
  .shop { top: auto; bottom: 12px; right: 12px; left: auto; width: calc(100% - 24px); max-height: 55%; }
  .shop.collapsed { width: auto; left: auto; bottom: 80px; } /* above the camera buttons */
  .shop.collapsed .ptabs { display: none; }
  .shop.collapsed .panel-head::before { content: "Upgrades & more"; font-weight: 800; font-size: 14px; padding: 4px 8px; }
  .shop:not(.collapsed) ~ .tools { display: none; }
  .upgrade { grid-template-columns: 1fr auto; padding: 8px; gap: 6px; }
  .upgrade .icon { display: none; }
  .tools { flex-wrap: wrap; right: 12px; gap: 6px; }
  .tool { min-width: 54px; padding: 6px 8px; }
}

/* --- idle features --- */
.coin-stack { display: flex; flex-direction: column; line-height: 1.05; }
.rate { font-size: 11px; font-weight: 600; color: var(--muted); }
.rate:empty { display: none; }
.frenzy {
  background: linear-gradient(90deg, #ff9d2e, #ffd84a); color: #3a1d00; font-weight: 900; font-size: 13px;
  padding: 7px 12px; border-radius: 999px; letter-spacing: .5px; animation: pulse 0.8s ease-in-out infinite alternate;
}
.frenzy[hidden] { display: none; }
@keyframes pulse { to { filter: brightness(1.2); transform: scale(1.04); } }

.sub { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 14px 6px 8px; }
.sub:first-child { margin-top: 4px; }
.muted-sm { color: var(--muted); font-size: 12px; line-height: 1.4; margin: 4px 0; }
.ascend-card { background: linear-gradient(160deg, rgba(123,211,196,.14), rgba(160,120,255,.12)); border: 1px solid rgba(123,211,196,.3); border-radius: 12px; padding: 12px; }
.shard-row { display: flex; align-items: center; gap: 8px; font-size: 22px; }
.shard-row b { font-variant-numeric: tabular-nums; }
.shard-icon { width: 18px; height: 22px; background: linear-gradient(160deg, #c6fff4, #7bd3c4 45%, #8b6cff); clip-path: polygon(50% 0, 100% 35%, 50% 100%, 0 35%); }
.ascend-info { font-size: 14px; margin: 8px 0; }
.ascend-info b { color: var(--accent); }
.primary.wide { width: 100%; margin: 4px 0 6px; }
.primary.confirm { background: var(--accent); }
.upgrade.perk .price { color: var(--accent); }
.upgrade.perk .price::before { background: var(--accent); border-radius: 2px; transform: rotate(45deg) scale(.8); }

.trophies { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.trophy { border: 1px solid var(--line); border-radius: 10px; padding: 8px; font-size: 11.5px; color: var(--muted); background: rgba(255,255,255,.02); }
.trophy b { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }
.trophy.got { border-color: rgba(245,176,65,.45); background: rgba(245,176,65,.08); color: var(--text); }
.trophy.got b { color: var(--gold); }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; padding: 4px 6px; }
.setting select { font: inherit; color: var(--text); background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
.setting input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }
.row-left { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 6px; }
.ghost.small { padding: 6px 10px; font-size: 12px; }
.ghost.danger { color: var(--danger); border-color: rgba(255,122,122,.35); }
#save-text { width: calc(100% - 12px); margin: 8px 6px 0; font: 11px ui-monospace, monospace; color: var(--text); background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 8px; padding: 8px; -webkit-user-select: text; user-select: text; resize: vertical; }

.floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 4; }
.floater { position: absolute; font-weight: 900; font-size: 15px; color: #ffe08a; text-shadow: 0 2px 6px rgba(0,0,0,.7); animation: floatUp .9s ease-out forwards; white-space: nowrap; transform: translate(-50%, -50%); }
.floater.crit { font-size: 22px; color: #ff9d5c; }
.floater.gold { font-size: 24px; color: #ffd84a; }
@keyframes floatUp { to { opacity: 0; transform: translate(-50%, -160%); } }

@media (max-width: 640px) {
  .frenzy { position: fixed; top: 100px; left: 50%; transform: translateX(-50%); }
  .ptab { font-size: 11px; padding: 6px 2px; }
}

/* guest name (account dialog) */
.guest-name { border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.guest-name[hidden] { display: none; }
.guest-name-row { display: flex; gap: 6px; }
.guest-name-row input { flex: 1; min-width: 0; }

/* settings dialog (controls + credits), shared by both modes */
.settings-dialog { width: min(460px, calc(100% - 32px)); max-height: min(720px, calc(100% - 32px)); padding: 18px 18px 14px; display: none; flex-direction: column; }
.settings-dialog[open] { display: flex; }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.settings-head h2 { margin: 0; }
.settings-x { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 4px 8px; border-radius: 8px; }
.settings-x:hover { color: var(--text); background: rgba(255,255,255,.08); }
.settings-body { overflow-y: auto; min-height: 0; flex: 1; margin: 0 -6px; padding: 0 2px 4px; }
.settings-body[hidden] { display: none; }
.settings-dialog label.setting { display: flex; margin: 0; color: var(--text); padding: 6px; }
.settings-dialog label.setting > span { display: grid; gap: 2px; }
.setting-hint { color: var(--muted); font-size: 11.5px; line-height: 1.35; }
.settings-dialog .setting select { max-width: 52%; }
.keymap { display: grid; gap: 2px; padding: 0 6px; }
.keymap.off { opacity: .45; }
.keymap-row { display: grid; grid-template-columns: 1fr 86px 86px; gap: 6px; align-items: center; font-size: 13px; }
.keycap { font: 600 12px ui-monospace, monospace; color: var(--text); background: rgba(0,0,0,.3); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 7px; padding: 5px 4px; }
.keycap.empty { color: var(--muted); }
.keycap.listening { border-color: var(--gold); color: var(--gold); font-family: inherit; }
.keycap:disabled { cursor: default; }
.settings-note { min-height: 1.4em; padding: 0 6px; color: var(--accent); }
.credit-notes { padding: 0 6px; font-size: 13px; }
.credit-notes p { margin: 0 0 6px; }
.credit-list { list-style: none; margin: 0; padding: 0 6px; display: grid; gap: 8px; }
.credit-list li { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: center; }
.credit-list img, .credit-noimg { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: rgba(255,255,255,.06); border: 1px solid var(--line); }
.credit-list b { font-size: 12px; color: var(--muted); font-weight: 600; word-break: break-all; }
.credit-list p, .credit-notes p { margin: 2px 0 0; font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.settings-dialog a { color: var(--accent); }
.credit-layers { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* About tab (Settings → About), filled in on the admin page */
.about-body { padding: 0 6px; font-size: 14px; line-height: 1.5; }
.about-body p { margin: 0 0 10px; overflow-wrap: anywhere; }
.about-title { margin: 4px 0 8px; font-size: 17px; }
.about-sub { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.about-links { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-dialog a.about-link { text-decoration: none; display: inline-flex; align-items: center; }
.settings-dialog a.about-link.primary { color: #2a1a00; }
.primary.small { padding: 6px 12px; font-size: 12px; }
