:root {
  --ink: #f4ead6;
  --ink-dim: #c9bda6;
  --panel: rgba(28, 25, 22, 0.82);
  --panel-solid: #1e1b18;
  --edge: rgba(226, 205, 165, 0.22);
  --brass: #c9a227;
  --brass-dim: #8c7320;
  --terracotta: #c25a3c;
  --mint: #8fd0a8;
  --glass: #bcd7de;
  --warn: #f0a04b;
  --danger: #e2604a;
  --radius: 14px;
  --tap: 44px;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #141210;
  color: var(--ink);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 480px;
  overflow: hidden;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene.dragging {
  cursor: grabbing;
}

/* Reserved, always-visible 3D stage. On desktop it is the full-bleed backdrop
   behind the side panels; on a narrow screen it becomes an in-flow band that
   keeps the scene clear of the stacked overlays. */
.stage-band {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: auto;
}
/* Overlays paint above the reserved stage band. */
.topbar,
.panel,
.tray,
.shelf,
.banner {
  position: relative;
  z-index: 1;
}

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: grid;
  grid-template-columns: minmax(200px, 240px) 1fr minmax(210px, 250px);
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 10px;
  grid-template-areas:
    'top top top'
    'instruments stage controls'
    'tray tray shelf';
}

.hud button,
.hud .chip,
.hud kbd,
.modal button {
  pointer-events: auto;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand .mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: radial-gradient(circle at 30% 25%, #e8d9a8, var(--brass) 55%, #6b551a);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  flex: none;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.brand-text span {
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--edge);
  font-size: 13px;
  font-weight: 600;
  margin-left: auto;
  white-space: nowrap;
}
.status-chip .led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 8px rgba(143, 208, 168, 0.7);
  flex: none;
}
.status-chip.is-warn .led {
  background: var(--warn);
  box-shadow: 0 0 8px rgba(240, 160, 75, 0.8);
}
.status-chip.is-bad .led {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(226, 96, 74, 0.8);
}
.status-chip.is-run .led {
  background: var(--brass);
  box-shadow: 0 0 10px rgba(201, 162, 39, 0.9);
  animation: pulse 0.9s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.view-tools {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.view-tools button {
  min-width: var(--tap);
  min-height: 36px;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--edge);
  border-radius: 10px;
  cursor: pointer;
}
.view-tools button:hover,
.view-tools button:focus-visible {
  background: rgba(201, 162, 39, 0.22);
  outline: 2px solid var(--brass);
  outline-offset: 1px;
}

.panel {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 10px 12px;
  backdrop-filter: blur(6px);
  align-self: start;
  max-height: 100%;
  overflow: auto;
}
.instruments {
  grid-area: instruments;
}
.controls {
  grid-area: controls;
}
.panel-title {
  margin: 0 0 8px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brass);
  font-weight: 700;
}

.gauge {
  margin-bottom: 10px;
}
.gauge-head,
.gauge-foot {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}
.gauge-head b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.gauge-foot {
  margin-top: 4px;
}
.bar {
  position: relative;
  height: 12px;
  margin-top: 5px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--edge);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--brass));
  transition: width 0.16s linear;
}
.bar.over i {
  background: linear-gradient(90deg, var(--warn), var(--danger));
}
.bar .limit {
  position: absolute;
  top: -1px;
  bottom: -1px;
  left: 82%;
  width: 2px;
  background: rgba(226, 96, 74, 0.85);
}
.bar.vibe i {
  background: linear-gradient(90deg, #7fa8d8, var(--brass));
}

.readouts {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}
.readout {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 11px;
  color: var(--ink-dim);
  border-bottom: 1px dashed rgba(226, 205, 165, 0.14);
  padding-bottom: 4px;
}
.readout b {
  color: var(--ink);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.leds {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.mini-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3a352f;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6);
}
.mini-led.on {
  background: var(--mint);
  box-shadow: 0 0 8px rgba(143, 208, 168, 0.8);
}
.mini-led.warn {
  background: var(--warn);
  box-shadow: 0 0 8px rgba(240, 160, 75, 0.8);
}
.mini-led.bad {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(226, 96, 74, 0.8);
}

.dial {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.dial-key {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: var(--tap);
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--edge);
  border-radius: 10px;
  cursor: pointer;
}
.dial-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4a443c;
  flex: none;
}
.dial-key[aria-checked='true'] {
  color: #1b1a18;
  background: linear-gradient(180deg, #e3c766, var(--brass));
  border-color: #f0dda0;
}
.dial-key[aria-checked='true'] .dial-dot {
  background: #1b1a18;
}
.dial-key:hover,
.dial-key:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 1px;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.button-grid button {
  min-height: var(--tap);
  padding: 0 8px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--edge);
  border-radius: 10px;
  cursor: pointer;
}
.button-grid button.wide {
  grid-column: span 2;
}
.button-grid button:hover,
.button-grid button:focus-visible {
  background: rgba(201, 162, 39, 0.22);
  outline: 2px solid var(--brass);
  outline-offset: 1px;
}
.button-grid button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}
.button-grid button.active {
  background: linear-gradient(180deg, #e3c766, var(--brass));
  color: #1b1a18;
  border-color: #f0dda0;
}
#pulseBtn.active {
  background: linear-gradient(180deg, #eaa06a, var(--terracotta));
  color: #1b1a18;
}

.banner {
  grid-area: stage;
  align-self: start;
  justify-self: center;
  max-width: 460px;
  margin-top: 4px;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(30, 27, 24, 0.94);
  border: 1px solid var(--warn);
  color: var(--ink);
  font-size: 13px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.banner.danger {
  border-color: var(--danger);
}
.banner.good {
  border-color: var(--mint);
}

.tray {
  grid-area: tray;
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 10px 12px;
  backdrop-filter: blur(6px);
  align-self: end;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 10px;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--edge);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover,
.chip:focus-visible {
  background: rgba(201, 162, 39, 0.22);
  outline: 2px solid var(--brass);
  outline-offset: 1px;
}
.chip .swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
  flex: none;
}
.tray-hint {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.35;
}

.shelf {
  grid-area: shelf;
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 10px 12px;
  backdrop-filter: blur(6px);
  align-self: end;
  max-height: 34vh;
  overflow: auto;
}
.shelf-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.shelf-head .panel-title {
  margin: 0;
}
.mini {
  min-height: 32px;
  padding: 0 10px;
  font: inherit;
  font-size: 11px;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--edge);
  border-radius: 8px;
  cursor: pointer;
  pointer-events: auto;
}
.shelf-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.empty-note {
  margin: 0;
  font-size: 12px;
  color: var(--ink-dim);
}
.drink-card {
  width: 118px;
  min-height: var(--tap);
  padding: 8px;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--edge);
  border-radius: 10px;
  cursor: pointer;
}
.drink-card:hover,
.drink-card:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 1px;
}
.drink-card .drink-swatch {
  height: 26px;
  border-radius: 6px;
  margin-bottom: 6px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.drink-card strong {
  display: block;
  font-size: 12px;
  line-height: 1.2;
}
.drink-card span {
  display: block;
  font-size: 10.5px;
  color: var(--ink-dim);
  margin-top: 2px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(226, 205, 165, 0.18);
  font-size: 11px;
  color: var(--ink-dim);
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.legend kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 4px;
  text-align: center;
  font-family: inherit;
  font-size: 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--edge);
  border-radius: 4px;
}
.legend .mouse {
  color: var(--ink);
}

.compass {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  flex: none;
}
.compass-ring {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--edge);
  background: rgba(20, 18, 16, 0.6);
  flex: none;
}
.compass-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 14px;
  margin-left: -1.5px;
  margin-top: -14px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--brass), rgba(201, 162, 39, 0.2));
  transform-origin: 50% 100%;
  transform: rotate(0deg);
}
.compass-n {
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 8px;
  color: var(--ink-dim);
}
.compass-label {
  font-size: 10px;
  color: var(--ink-dim);
  max-width: 74px;
  line-height: 1.15;
}

.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 9, 8, 0.66);
  pointer-events: auto;
  padding: 16px;
  z-index: 20;
}
.modal[hidden] {
  display: none;
}
.modal-card {
  position: relative;
  width: min(420px, 100%);
  max-height: 84dvh;
  overflow: auto;
  background: var(--panel-solid);
  border: 1px solid var(--edge);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  font-size: 20px;
  line-height: 1;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--edge);
  border-radius: 10px;
  cursor: pointer;
}
.modal-swatch {
  height: 54px;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}
.modal-card h2 {
  margin: 0 0 4px;
  font-size: 20px;
}
.modal-card h3 {
  margin: 14px 0 6px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--brass);
}
.modal-sub,
.recipe-notes {
  margin: 0;
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.45;
}
.recipe-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.6;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.modal-actions button {
  flex: 1 1 140px;
  min-height: var(--tap);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--edge);
  border-radius: 10px;
  cursor: pointer;
}
.modal-actions button:hover,
.modal-actions button:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 1px;
}

.toast {
  grid-area: stage;
  align-self: end;
  justify-self: center;
  margin-bottom: 4px;
  padding: 8px 16px;
  background: rgba(30, 27, 24, 0.95);
  border: 1px solid var(--brass);
  border-radius: 999px;
  font-size: 12.5px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  max-width: 100%;
  text-align: center;
  transform: translateY(10px);
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .hud {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto 1fr auto auto;
    grid-template-areas:
      'top top'
      'instruments controls'
      'stage stage'
      'tray tray'
      'shelf shelf';
  }
  .shelf {
    max-height: 26vh;
  }
}

@media (max-width: 620px) {
  .hud {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
    grid-template-areas: none;
    grid-template-columns: none;
    grid-template-rows: none;
    overflow-x: hidden;
    overflow-y: auto;
  }
  /* flex children must be allowed to shrink so inner scrollers handle the overflow */
  .hud {
    justify-content: flex-end;
  }
  .hud > * {
    min-width: 0;
    max-width: 100%;
  }
  /* the stage becomes an in-flow band between the top bar and the controls,
     so the blender is never hidden behind a stacked panel */
  .stage-band {
    position: relative;
    inset: auto;
    flex: 1 1 auto;
    min-height: 150px;
    order: 1;
  }
  .topbar {
    margin-bottom: 0;
  }
  .button-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .instruments .gauge.compact {
    display: none;
  }
  .panel,
  .tray,
  .shelf,
  .topbar,
  .banner {
    align-self: stretch;
  }
  .topbar {
    order: 0;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 8px;
  }
  .brand-text span {
    display: none;
  }
  .brand-text strong {
    font-size: 13.5px;
  }
  .status-chip {
    order: 2;
    margin-left: auto;
    font-size: 12px;
    padding: 5px 10px;
  }
  .compass {
    display: none;
  }
  .view-tools {
    order: 3;
    width: 100%;
    justify-content: space-between;
    gap: 3px;
  }
  .view-tools button {
    min-width: 0;
    flex: 1 1 auto;
    min-height: 44px;
    padding: 0 4px;
    font-size: 12px;
  }
  .banner {
    order: 2;
    font-size: 12px;
    padding: 8px 12px;
    margin-top: 0;
    max-width: 100%;
  }
  .panel {
    max-height: none;
    overflow: visible;
  }
  .instruments {
    order: 3;
    padding: 8px 10px;
  }
  .instruments .panel-title {
    display: none;
  }
  .readouts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    margin-bottom: 6px;
  }
  .readout {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    border-bottom: none;
    font-size: 10px;
  }
  .readout b {
    font-size: 12px;
  }
  .gauge {
    margin-bottom: 6px;
  }
  .leds {
    display: none;
  }
  .controls {
    order: 4;
    padding: 8px 10px;
  }
  .controls .panel-title {
    display: none;
  }
  .dial {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-bottom: 6px;
  }
  .dial-key {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 48px;
    padding: 4px 2px;
    font-size: 10.5px;
  }
  .button-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  .button-grid button {
    min-height: 44px;
    padding: 0 4px;
    font-size: 11px;
  }
  .legend {
    display: none;
  }
  .tray {
    order: 5;
    padding: 8px 10px;
  }
  .tray .panel-title {
    display: none;
  }
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    pointer-events: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .chip {
    flex: none;
  }
  .tray-hint {
    display: none;
  }
  .shelf {
    order: 6;
    padding: 8px 10px;
    max-height: 16vh;
    overflow-y: auto;
  }
  .shelf-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    pointer-events: auto;
    padding-bottom: 4px;
  }
  .drink-card {
    flex: none;
  }
  .toast {
    order: 7;
    margin-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-chip.is-run .led {
    animation: none;
  }
}
