:root {
  --ink: #fff6ec;
  --ink-dim: rgba(255, 246, 236, 0.66);
  --panel: rgba(28, 19, 15, 0.72);
  --panel-edge: rgba(255, 196, 140, 0.18);
  --ember: #ff8a24;
  --ember-hot: #ffd05b;
  --steel: #90a4ae;
  --good: #7ee0a3;
  --warn: #ffb547;
  --bad: #ff6b5b;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a120e;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

button { font: inherit; color: inherit; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.panel-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

/* ---- Loading ---------------------------------------------------------- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 60%, #4a2412 0%, #1a120e 70%);
  transition: opacity 0.5s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.loading-card { text-align: center; width: min(320px, 80vw); }
.loading-title { font-size: 32px; font-weight: 700; letter-spacing: 0.02em; color: var(--ember-hot); text-shadow: 0 0 24px rgba(255, 138, 36, 0.6); }
.loading-sub { margin: 8px 0 16px; color: var(--ink-dim); font-size: 14px; }
.loading-bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
#loading-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--ember), var(--ember-hot)); transition: width 0.25s ease; }

/* ---- Top bar ---------------------------------------------------------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  pointer-events: none;
}
.brand { font-weight: 700; font-size: 18px; color: var(--ember-hot); text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); }
.topbar-right { display: flex; gap: 8px; align-items: center; pointer-events: auto; }
.coins {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--panel-edge);
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.coin-dot { width: 10px; height: 10px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff2b3, #e0a43a); }
.icon-btn {
  min-width: 36px; height: 34px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--panel-edge);
  background: var(--panel); cursor: pointer;
}
.icon-btn:hover { border-color: rgba(255, 196, 140, 0.45); }

/* ---- Order card ------------------------------------------------------- */
#order-card {
  position: fixed; top: 60px; left: 16px; z-index: 10;
  width: min(250px, calc(50vw - 24px));
  padding: 10px 12px;
}
.order-name { font-size: 17px; font-weight: 700; margin: 2px 0 4px; }
.order-brief { font-size: 13px; color: var(--ink-dim); line-height: 1.35; }
.order-color { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.5); }

/* ---- Shelf card ------------------------------------------------------- */
#shelf-card {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 10;
  width: min(300px, calc(100vw - 32px));
  padding: 10px 12px; text-align: center;
}
#shelf-card .order-name { display: flex; align-items: center; justify-content: center; gap: 6px; }
.shelf-stars { font-size: 18px; letter-spacing: 2px; color: var(--ember-hot); }
.shelf-stars .off { color: rgba(255, 255, 255, 0.18); }

/* ---- Meters ----------------------------------------------------------- */
#meters {
  position: fixed; top: 60px; right: 16px; z-index: 10;
  width: min(230px, calc(50vw - 24px));
  padding: 10px 12px;
  display: grid; gap: 8px;
}
.meter-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.meter-head span:last-child { color: var(--ink-dim); }
.meter-track { position: relative; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.meter-zone { position: absolute; top: 0; bottom: 0; background: rgba(126, 224, 163, 0.18); border-left: 1px solid rgba(126, 224, 163, 0.5); border-right: 1px solid rgba(126, 224, 163, 0.5); }
.meter-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 4px; background: linear-gradient(90deg, #6b3a1f, var(--ember), var(--ember-hot)); }
.center-fill { background: var(--good); }
.wall-fill { background: var(--steel); }
.shape-readout { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 2px 0 0; font-size: 12px; }
.shape-readout dt { color: var(--ink-dim); }
.shape-readout dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Bruno ------------------------------------------------------------ */
#bruno {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(150px + var(--safe-bottom)); z-index: 11;
  width: min(460px, calc(100vw - 32px));
  padding: 10px 14px;
  font-size: 14px; line-height: 1.4;
  animation: rise 0.25s ease;
}
.speaker { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ember-hot); margin-bottom: 2px; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---- Stations --------------------------------------------------------- */
#stations {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom)); z-index: 10;
  display: flex; gap: 6px; padding: 5px;
  border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-edge);
  max-width: calc(100vw - 32px); overflow-x: auto;
}
.station-btn {
  white-space: nowrap; border: 0; border-radius: 999px;
  padding: 7px 12px; background: transparent; cursor: pointer; font-size: 13px;
  color: var(--ink-dim);
}
.station-btn .key { opacity: 0.55; font-size: 11px; margin-right: 4px; }
.station-btn .timer { color: var(--ember-hot); font-variant-numeric: tabular-nums; margin-left: 4px; }
.station-btn.active { background: rgba(255, 138, 36, 0.22); color: var(--ink); box-shadow: inset 0 0 0 1px rgba(255, 138, 36, 0.55); }
.station-btn:disabled { opacity: 0.35; cursor: default; }

/* ---- Hold controls ---------------------------------------------------- */
#controls {
  position: fixed; left: 16px; right: 16px; z-index: 10;
  bottom: calc(16px + var(--safe-bottom));
  display: flex; justify-content: space-between; align-items: flex-end; gap: 12px;
  pointer-events: none;
}
#action-stack { display: flex; gap: 8px; pointer-events: auto; flex-wrap: wrap; justify-content: flex-end; }
.hold-btn {
  pointer-events: auto;
  display: grid; place-items: center; gap: 2px;
  min-width: 92px; height: 68px; padding: 0 16px;
  border-radius: 18px; cursor: pointer;
  border: 1px solid rgba(255, 196, 140, 0.35);
  background: rgba(46, 30, 22, 0.82);
  font-weight: 700; font-size: 15px;
  touch-action: none;
  transition: transform 0.08s ease, background 0.15s ease;
}
.hold-btn .hold-key { font-size: 10px; font-weight: 500; opacity: 0.6; letter-spacing: 0.08em; text-transform: uppercase; }
.hold-btn.held { background: rgba(255, 138, 36, 0.45); transform: scale(0.96); border-color: var(--ember-hot); }
.hold-btn.primary { background: rgba(120, 58, 20, 0.85); }
.hold-btn:disabled { opacity: 0.35; cursor: default; }
#turn-btn { min-width: 110px; }
#turn-btn.spinning .hold-key { opacity: 1; color: var(--good); }

/* ---- Modal ------------------------------------------------------------ */
.modal {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(10, 6, 4, 0.55);
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(460px, 100%);
  max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 18px;
  border-radius: 18px;
  background: #241812; border: 1px solid var(--panel-edge);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.modal-card h2 { margin: 0 0 6px; font-size: 22px; color: var(--ember-hot); }
.modal-card p { margin: 6px 0; color: var(--ink-dim); line-height: 1.45; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.btn {
  border-radius: 10px; padding: 9px 16px; cursor: pointer;
  border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, 0.06);
}
.btn.primary { background: var(--ember); color: #2a1206; border-color: var(--ember); font-weight: 700; }
.stars { font-size: 26px; letter-spacing: 3px; color: var(--ember-hot); margin: 4px 0; }
.stars .off { color: rgba(255, 255, 255, 0.18); }
.score-rows { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 10px 0; font-size: 14px; }
.score-rows .ok { color: var(--good); }
.score-rows .meh { color: var(--warn); }
.score-rows .bad { color: var(--bad); }
.how { margin: 8px 0 0; padding-left: 18px; color: var(--ink-dim); font-size: 14px; line-height: 1.5; }
.how b { color: var(--ink); }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0; font-size: 14px; }
.setting-row select { font: inherit; padding: 6px 8px; border-radius: 8px; background: #33241b; color: var(--ink); border: 1px solid var(--panel-edge); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 10px; }
.gallery-item { padding: 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); font-size: 12px; }
.gallery-item canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 8px; background: radial-gradient(circle at 50% 70%, #3a2418, #1a120e); }
.gallery-item .gi-name { font-weight: 600; margin-top: 4px; font-size: 13px; }
.gallery-item .gi-meta { color: var(--ink-dim); }
.empty { color: var(--ink-dim); font-size: 14px; }
.color-pick { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.color-pick button { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.color-pick button.on { border-color: var(--ink); }

/* ---- Start menu (laid out like Bunny Hop Adventures' title screen) ---- */
#start-menu {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: calc(22px + env(safe-area-inset-top, 0px)) 18px calc(22px + var(--safe-bottom));
  background: radial-gradient(circle at 50% 45%, rgba(26, 18, 14, 0.15), rgba(10, 6, 4, 0.62) 75%);
  overflow: hidden auto;
  transition: opacity 0.4s ease;
}
#start-menu[hidden] { display: none; }
#start-title {
  margin: 0 0 18px; text-align: center;
  font-size: clamp(42px, 9vw, 86px); line-height: 1.02; font-weight: 800;
  color: var(--ember-hot);
  text-shadow: 0 0 28px rgba(255, 138, 36, 0.55), 0 4px 18px rgba(0, 0, 0, 0.5);
}
#start-subtitle {
  display: block; margin-top: 8px;
  font-size: clamp(16px, 3vw, 24px); font-weight: 600;
  letter-spacing: 0.32em; text-indent: 0.32em; text-transform: uppercase;
  color: var(--ink); opacity: 0.78;
}
.menu-btn {
  position: relative;
  width: min(420px, calc(100vw - 56px));
  margin-top: 12px; padding: 15px 24px;
  border: 0; border-radius: 30px; cursor: pointer;
  font-size: 20px; font-weight: 600; color: #fff;
  background: #66758f; box-shadow: 0 4px 15px rgba(70, 85, 112, 0.38);
  transition: transform 0.2s, filter 0.2s;
}
.menu-btn:hover { filter: brightness(1.08); }
#single-btn { background: #e8641a; box-shadow: 0 4px 15px rgba(232, 100, 26, 0.42); }
#two-player-btn { background: #a06bff; box-shadow: 0 4px 15px rgba(160, 107, 255, 0.36); }
#load-game-btn { background: #46bd8c; box-shadow: 0 4px 15px rgba(70, 189, 140, 0.34); }
#choose-character-btn { background: #5aa7ff; box-shadow: 0 4px 15px rgba(90, 167, 255, 0.34); }
#start-settings-menu { display: none; flex-direction: column; align-items: center; }
#start-settings-menu h2 { margin: 0 0 6px; font-size: clamp(30px, 6vw, 52px); text-shadow: 0 4px 18px rgba(0, 0, 0, 0.35); }
#start-menu.settings-open #start-title,
#start-menu.settings-open > .start-main-option { display: none; }
#start-menu.settings-open #start-settings-menu { display: flex; }
#start-menu .start-menu-selected {
  transform: scale(1.06);
  outline: 3px solid #fff4a8; outline-offset: 4px;
  filter: brightness(1.12);
}
#start-menu .start-menu-selected::before {
  content: "🐰";
  position: absolute; right: calc(100% + 14px); top: 50%;
  font-size: 30px; line-height: 1;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.55));
  animation: start-menu-bunny-hop 700ms ease-in-out infinite alternate;
}
@keyframes start-menu-bunny-hop {
  from { transform: translateY(-48%) rotate(-5deg); }
  to { transform: translateY(-70%) rotate(5deg); }
}

/* Nothing of the workshop HUD shows until a game is under way. */
body:not(.in-game) #topbar,
body:not(.in-game) #order-card,
body:not(.in-game) #meters,
body:not(.in-game) #shelf-card,
body:not(.in-game) #bruno,
body:not(.in-game) #stations,
body:not(.in-game) #controls { display: none !important; }

/* ---- 2 Player scoreboard ---------------------------------------------- */
#duel-badge {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--panel-edge);
  font-size: 13px; font-weight: 600; pointer-events: none;
}
#duel-badge[hidden] { display: none; }
#duel-badge .duel-player { opacity: 0.55; }
#duel-badge .duel-player b { color: var(--ember-hot); margin-left: 3px; }
#duel-badge .duel-player.on { opacity: 1; color: var(--ink); text-shadow: 0 0 10px rgba(255, 138, 36, 0.8); }
#duel-badge .duel-round { color: var(--ink-dim); font-weight: 500; }

/* ---- Toasts (Bunny Hop's game-notification stack) -------------------- */
#toast-stack {
  position: fixed; top: calc(22px + env(safe-area-inset-top, 0px)); left: 50%; z-index: 60;
  transform: translateX(-50%);
  width: max-content; max-width: min(440px, calc(100vw - 32px));
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 14px 20px;
  border: 1px solid rgba(255, 208, 91, 0.85); border-radius: 12px;
  background: rgba(30, 18, 12, 0.96); color: #fff1cf;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.42);
  font: 700 15px/1.35 system-ui, sans-serif; text-align: center;
  opacity: 0; transform: translateY(-18px);
  transition: opacity 240ms ease, transform 240ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

/* ---- Controller hints ------------------------------------------------- */
.pad-glyph {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  font-size: 10px; font-weight: 800; letter-spacing: 0; color: #111;
  background: #d8dde3;
}
.pad-glyph.pad-a { background: #6fcf5a; }
.pad-glyph.pad-b { background: #ff6b5b; }
.pad-glyph.pad-x { background: #4aa3ff; }
.pad-glyph.pad-y { background: #ffd23f; }
body:not(.gamepad-connected) .pad-glyph { display: none; }
.control-table .pad-glyph { display: inline-grid !important; }
body.gamepad-connected .hold-key .kb { display: none; }
.hold-btn .hold-key .pad-glyph { opacity: 1; }
.modal-card .pad-focus { outline: 3px solid #fff4a8; outline-offset: 3px; }

/* ---- Menus inside the modal ------------------------------------------- */
.menu-list { display: grid; gap: 8px; margin-top: 12px; }
.menu-list .btn { width: 100%; padding: 11px 16px; font-size: 15px; }
.control-table { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 14px; margin: 12px 0; font-size: 13px; }
.control-table .head { color: var(--ink-dim); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }
.control-table kbd { font: inherit; padding: 1px 6px; border-radius: 5px; background: rgba(255, 255, 255, 0.1); }
.duel-scores { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.duel-scores > div { padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); text-align: center; }
.duel-scores .winner { box-shadow: inset 0 0 0 2px var(--ember-hot); }
.duel-scores .who { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-dim); }
.duel-scores .stars { font-size: 20px; }

/* Choose Your Character sits to one side so the bunny shows beside it. */
.modal.side { place-items: center start; background: linear-gradient(90deg, rgba(10, 6, 4, 0.6), transparent 70%); }
.modal.side .modal-card { width: min(400px, 100%); }
.char-tabs { display: flex; gap: 6px; margin: 10px 0 4px; }
.char-tabs .btn { flex: 1; }
.char-tabs .btn.on { background: rgba(255, 138, 36, 0.28); border-color: var(--ember); }
.char-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.char-btn {
  display: grid; justify-items: center; gap: 4px;
  padding: 8px 4px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, 0.05);
  font-size: 12px;
}
.char-btn.on { border-color: var(--ember-hot); background: rgba(255, 138, 36, 0.2); }
.char-swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); }

/* ---- Small screens ---------------------------------------------------- */
@media (max-width: 640px) {
  #topbar { padding: 10px 12px; }
  .brand { font-size: 16px; }
  #order-card, #meters { top: 52px; padding: 8px 10px; }
  #order-card { left: 10px; width: calc(50vw - 15px); }
  #meters { right: 10px; width: calc(50vw - 15px); gap: 6px; }
  .order-name { font-size: 15px; }
  .order-brief { font-size: 12px; }
  .shape-readout { display: none; }
  #stations { bottom: calc(92px + var(--safe-bottom)); }
  .station-btn { padding: 7px 10px; font-size: 12px; }
  .station-btn .key { display: none; }
  #bruno { bottom: calc(140px + var(--safe-bottom)); font-size: 13px; }
  #shelf-card { top: auto; bottom: calc(140px + var(--safe-bottom)); padding: 8px 10px; }
  #controls { left: 10px; right: 10px; bottom: calc(10px + var(--safe-bottom)); }
  #controls { gap: 6px; }
  #action-stack { flex-wrap: nowrap; gap: 6px; }
  .hold-btn { min-width: 0; width: 64px; height: 64px; padding: 0 4px; font-size: 13px; }
  .hold-btn .hold-key { display: none; }
  #turn-btn { min-width: 0; width: 70px; }
  #action-stack .hold-btn:only-child, #action-stack .hold-btn.primary { width: auto; min-width: 84px; padding: 0 12px; }
  #start-menu .menu-btn { width: min(292px, calc(100vw - 86px)); padding: 12px 14px; margin-top: 8px; font-size: 18px; }
  #start-menu .start-menu-selected { transform: scale(1.025); outline-offset: 3px; }
  #start-menu .start-menu-selected::before { right: calc(100% + 8px); font-size: 24px; }
  #toast-stack { top: calc(10px + env(safe-area-inset-top, 0px)); max-width: min(330px, calc(100vw - 34px)); }
  .toast { padding: 10px 14px; font-size: 13px; }
  #duel-badge { gap: 6px; padding: 4px 9px; font-size: 12px; }
  #duel-badge .duel-round { display: none; }
  .modal.side { place-items: end center; background: linear-gradient(0deg, rgba(10, 6, 4, 0.6), transparent 70%); }
  .modal.side .modal-card { max-height: 58vh; }
}
