:root {
  --green: #12352c;
  --green-deep: #0c261f;
  --green-lift: #1b4a3d;
  --gilt: #e2b95a;
  --gilt-pale: #f3dc9d;
  --chalk: #f2efe2;
  --chalk-dim: #c6c9bc;
  --slate: #232f2e;
  --slate-deep: #1a2423;
  --line: rgba(242, 239, 226, 0.2);
  --good: #86dba8;
  --mid: #e8c469;
  --bad: #ff9a85;
  --serif: "Big Caslon", "Hoefler Text", Georgia, serif;
  --sans: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--slate-deep);
  color: var(--chalk);
  font: 15px/1.42 var(--sans);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, p { margin: 0; }
h1 { font: 700 26px/1 var(--serif); color: var(--gilt-pale); }
h2 { font: 700 19px/1.2 var(--serif); color: var(--gilt-pale); }
h3 { font: 600 14px/1.3 var(--sans); color: var(--chalk); margin-top: 12px; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button {
  font: 600 14px/1.15 var(--sans);
  color: var(--green-deep);
  background: var(--gilt);
  border: 0;
  border-radius: 4px;
  padding: 9px 13px;
  min-height: 42px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--gilt-pale); }
button:disabled { background: #455450; color: #c6c9bc; cursor: default; }
button.quiet { background: transparent; color: var(--chalk); box-shadow: inset 0 0 0 1px var(--line); }
button.quiet:hover:not(:disabled) { background: rgba(242, 239, 226, 0.1); }
button.primary { font-size: 16px; min-height: 48px; padding: 12px 20px; }
:focus-visible { outline: 3px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 6px #0b0f0e; }
canvas:focus-visible { outline: 2px solid var(--gilt); outline-offset: -2px; box-shadow: none; }
.small { font-size: 13px; color: var(--chalk-dim); }
strong, output, .num { font-variant-numeric: tabular-nums; }

/* ---- Frame ---- */
#app {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "top top"
    "stage guests"
    "manage guests"
    "books guests";
}
.top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 14px;
  background: var(--green);
  border-bottom: 2px solid var(--gilt);
}
.brand { display: flex; align-items: center; gap: 14px; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }
.till { display: flex; gap: 18px; flex-wrap: wrap; }
.till p { display: grid; line-height: 1.1; }
.till span { font-size: 12px; color: var(--chalk-dim); }
.till strong { font-size: 18px; color: var(--chalk); }

/* ---- Stage ---- */
.stage { grid-area: stage; position: relative; min-height: 0; background: #070b0f; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; }
.overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.links { position: absolute; inset: 0; width: 100%; height: 100%; }
.chips { position: absolute; inset: 0; }
.plan { position: absolute; inset: 0; }
.plan canvas { width: 100%; height: 100%; display: block; touch-action: none; }

.chip {
  position: absolute;
  left: 0;
  top: 0;
  margin-left: -20px;
  margin-top: -24px;
  height: 22px;
  min-width: 26px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 4px;
  border-radius: 11px 11px 11px 3px;
  background: rgba(16, 24, 22, 0.88);
  border-bottom: 2px solid var(--group, transparent);
  white-space: nowrap;
  font: 700 11px/1 var(--sans);
  color: var(--chalk);
  will-change: transform;
}
.chip-face { width: 16px; height: 16px; flex: none; }
.chip-face circle:first-child, .big-face circle:first-child { fill: var(--face); }
.chip-face .eye, .big-face .eye { fill: #1a1512; }
.chip-face .mouth, .big-face .mouth { fill: none; stroke: #1a1512; stroke-width: 1.8; stroke-linecap: round; }
.mood-good { --face: var(--good); }
.mood-mid { --face: var(--mid); }
.mood-bad { --face: var(--bad); }
.chip-glass {
  position: relative;
  width: 10px;
  height: 16px;
  flex: none;
  border: 1.5px solid #f7f4ea;
  border-top: 0;
  border-radius: 0 0 2px 2px;
  background: rgba(255, 255, 255, 0.1);
  clip-path: polygon(0 0, 100% 0, 88% 100%, 12% 100%);
}
.chip-glass i { position: absolute; left: 0; right: 0; bottom: 0; background: #e7ad33; }
.chip-glass[data-drink="stout"] i { background: #a8603b; border-top: 2px solid #f8eccb; }
.chip-glass[data-drink="ale"] i { background: #d0701e; }
.chip-glass[data-drink="cider"] i { background: #e8d067; }
.chip-tag:empty { display: none; }
.chip-name { display: none; }
.chip.selected, .chip.near, .chip.hover { z-index: 3; }
.chip.selected .chip-name, .chip.near .chip-name, .chip.hover .chip-name { display: inline; }
.chip.outside { background: rgba(19, 44, 62, 0.92); }
.chip.selected { background: #f6efd8; color: #17231f; box-shadow: 0 0 0 2px var(--gilt); z-index: 4; }
.chip.selected .chip-glass { border-color: #17231f; }
.chips.narrow .chip { transform-origin: left bottom; }
.mgr-tag {
  position: absolute;
  left: 0;
  top: 0;
  margin-left: -16px;
  margin-top: -18px;
  padding: 2px 6px;
  font: 800 11px/1.2 var(--sans);
  background: var(--gilt);
  color: var(--green-deep);
  border-radius: 3px;
}
.staff-tag {
  position: absolute;
  left: 0;
  top: 0;
  margin-left: -14px;
  margin-top: -15px;
  padding: 1px 5px;
  font: 700 10px/1.25 var(--sans);
  color: #17231f;
  background: #efe9d8;
  border-radius: 2px;
}
.bubble {
  position: absolute;
  left: 0;
  top: 0;
  width: max-content;
  max-width: min(320px, calc(100% - 16px));
  padding: 8px 11px 9px;
  border-radius: 14px;
  background: #fbf6e6;
  color: #17231f;
  font: 14px/1.3 var(--sans);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 5;
}
.bubble strong { display: block; font: 700 12px/1.2 var(--sans); color: #48604f; margin-bottom: 1px; }
.bubble::after {
  content: "";
  position: absolute;
  bottom: -9px;
  left: var(--tail, 50%);
  width: 14px;
  height: 14px;
  margin-left: -7px;
  background: #fbf6e6;
  transform: rotate(45deg);
  border-radius: 0 0 4px 0;
}
.ticker {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  max-width: 620px;
  width: fit-content;
  padding: 7px 11px;
  border-radius: 4px;
  background: rgba(12, 20, 18, 0.84);
  font-size: 14px;
  pointer-events: none;
}
.stage-actions { position: absolute; right: 10px; top: 10px; display: flex; gap: 8px; align-items: flex-start; }
.stage-actions button.quiet { background: rgba(12, 20, 18, 0.72); }
.talk { position: absolute; right: 10px; bottom: 10px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5); }
.stick {
  position: absolute;
  width: 92px;
  height: 92px;
  margin: -46px 0 0 -46px;
  border-radius: 50%;
  background: rgba(242, 239, 226, 0.12);
  box-shadow: inset 0 0 0 2px rgba(242, 239, 226, 0.5);
  pointer-events: none;
}
.stick i { position: absolute; left: 50%; top: 50%; width: 38px; height: 38px; margin: -19px; border-radius: 50%; background: rgba(242, 239, 226, 0.75); }
.paused-note {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  padding: 6px 12px;
  background: var(--gilt);
  color: var(--green-deep);
  font-weight: 700;
  border-radius: 4px;
  white-space: nowrap;
}
.welcome {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  background: linear-gradient(rgba(7, 12, 14, 0.2), rgba(7, 12, 14, 0.62));
}
.welcome-card {
  max-width: 520px;
  padding: 20px 24px 22px;
  background: rgba(17, 33, 29, 0.95);
  border-top: 3px solid var(--gilt);
  display: grid;
  gap: 10px;
  max-height: 100%;
  overflow: auto;
}
.welcome-card h2 { font-size: 27px; line-height: 1.08; }
.welcome-card ul { display: grid; gap: 5px; }
.welcome-card li { padding-left: 14px; position: relative; }
.welcome-card li::before { content: ""; position: absolute; left: 0; top: 0.62em; width: 6px; height: 6px; background: var(--gilt); transform: rotate(45deg); }
.welcome-card .primary { justify-self: start; margin-top: 4px; }
.hint { font-size: 14px; color: var(--gilt-pale); }

/* ---- Panels ---- */
.tabs { display: none; }
.panel { background: var(--slate); min-height: 0; }
.guests {
  grid-area: guests;
  overflow-y: auto;
  padding: 12px 14px 18px;
  border-left: 2px solid var(--gilt);
  display: block;
}
.guests h2 { margin-top: 12px; }
.guests #roster > h2:first-child { margin-top: 0; }
#room { margin: 4px 0 8px; }
.guest-list { display: grid; gap: 2px; }
.guest-row button {
  width: 100%;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 12px;
  gap: 8px;
  align-items: center;
  padding: 5px 7px;
  min-height: 44px;
  text-align: left;
  background: rgba(255, 255, 255, 0.045);
  color: var(--chalk);
  font-weight: 400;
}
.guest-row button:hover { background: rgba(255, 255, 255, 0.11) !important; }
.guest-row.selected button { background: #f6efd8; color: #17231f; }
.guest-row .who { font-weight: 700; }
.guest-row .what { display: block; font-size: 13px; color: var(--chalk-dim); line-height: 1.2; }
.guest-row.selected .what { color: #35443e; }
.guest-row .sw { width: 8px; height: 8px; display: inline-block; border-radius: 50%; margin-left: 5px; vertical-align: 1px; }
.guest-row .tag { font-size: 12px; font-weight: 400; color: var(--chalk-dim); }
.guest-row.selected .tag { color: #35443e; }
.guest-row svg { width: 20px; height: 20px; }
.guest-row svg circle:first-child { fill: var(--face); }
.guest-row svg .eye { fill: #1a1512; }
.guest-row svg .mouth { fill: none; stroke: #1a1512; stroke-width: 1.8; stroke-linecap: round; }
.mini-glass, .big-glass {
  position: relative;
  display: block;
  border: 1.5px solid currentColor;
  border-top: 0;
  background: rgba(255, 255, 255, 0.08);
  clip-path: polygon(0 0, 100% 0, 86% 100%, 14% 100%);
}
.mini-glass { width: 12px; height: 22px; }
.mini-glass i, .big-glass i { position: absolute; left: 0; right: 0; bottom: 0; background: #e7ad33; }
.mini-glass[data-drink="stout"] i, .big-glass[data-drink="stout"] i { background: #8a4a2b; border-top: 2px solid #f8eccb; }
.mini-glass[data-drink="ale"] i, .big-glass[data-drink="ale"] i { background: #d0701e; }
.mini-glass[data-drink="cider"] i, .big-glass[data-drink="cider"] i { background: #e8d067; }
.mini-glass.none { visibility: hidden; }
.past .guest-row button { min-height: 40px; }
details { margin-top: 10px; }
summary { cursor: pointer; font-size: 14px; min-height: 28px; }
.events { display: grid; gap: 5px; margin-top: 5px; font-size: 13px; color: var(--chalk-dim); }
.events li { display: grid; grid-template-columns: 34px 1fr; gap: 5px; }
.events time { font-variant-numeric: tabular-nums; opacity: 0.8; }
.events .invite, .events .arrive { color: var(--gilt-pale); }

/* Inspection card */
.card { display: grid; gap: 8px; }
.card-head { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto auto; gap: 9px; align-items: center; }
.big-face { width: 42px; height: 42px; }
.card-title h2 { margin: 0; font-size: 22px; }
.card-title p { font-size: 13px; color: var(--chalk-dim); }
.big-glass { width: 22px; height: 42px; color: #fbf6e6; }
.doing { font-size: 14px; }
.thought {
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px 14px 14px 3px;
  background: #fbf6e6;
  color: #17231f;
  font: 16px/1.3 var(--serif);
}
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.factors { display: grid; gap: 6px; }
.factors li { display: grid; grid-template-columns: minmax(0, 1fr) 50px; column-gap: 8px; font-size: 13px; }
.factors .f-name { font-weight: 700; }
.factors .pts { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 15px; }
.factors .pos .pts, .factors li.pos .pts { color: var(--good); }
.factors li.neg .pts { color: var(--bad); }
.factors .f-detail { grid-column: 1 / -1; color: var(--chalk-dim); line-height: 1.25; }
.company { display: grid; gap: 4px; font-size: 14px; }
.company button { font-weight: 500; min-height: 36px; padding: 6px 9px; text-align: left; background: rgba(255, 255, 255, 0.07); color: var(--chalk); width: 100%; }

.manage {
  grid-area: manage;
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr 1.15fr;
  gap: 16px;
  padding: 10px 14px;
  border-top: 2px solid var(--gilt);
}
.control { min-width: 0; display: grid; gap: 5px; align-content: start; }
.control label, .label { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 14px; }
.control output { color: var(--gilt-pale); font-weight: 700; }
.control .small { font-size: 12.5px; line-height: 1.25; }
input[type="range"] { width: 100%; height: 34px; accent-color: var(--gilt); margin: 0; }
input[type="range"]:disabled { opacity: 0.5; }
.segmented { display: flex; gap: 2px; }
.segmented button { flex: 1; background: rgba(255, 255, 255, 0.08); color: var(--chalk); }
.segmented button[aria-pressed="true"] { background: var(--gilt); color: var(--green-deep); }
.segmented button:disabled { color: #9ca49c; }
.segmented button[aria-pressed="true"]:disabled { background: #807a5a; color: #101a18; }
.control > button { width: 100%; }

.books {
  grid-area: books;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  padding: 0 14px 8px;
}
.charts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.charts figure { margin: 0; }
.charts figcaption { display: flex; flex-wrap: wrap; gap: 3px 6px; justify-content: space-between; font-size: 13px; color: var(--chalk-dim); }
.charts figcaption strong { color: var(--chalk); font-size: 14px; }
.charts .alt { width: 100%; font-size: 12px; }
.charts svg { width: 100%; height: 44px; display: block; color: var(--chalk-dim); }
.ledger-live { display: none; }
.ledger-live dl, #ledger { margin: 8px 0; display: grid; gap: 1px; }
.ledger-live dl div, #ledger div { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--line); }
dd { margin: 0; font-variant-numeric: tabular-nums; }
.total { font-weight: 800; }
.sim-note { margin-top: 10px; }

/* ---- Dialogs ---- */
dialog {
  border: 0;
  padding: 0;
  width: min(460px, calc(100vw - 20px));
  max-height: calc(100dvh - 20px);
  background: #f6efd8;
  color: #17231f;
  border-radius: 4px;
  overflow: auto;
}
dialog::backdrop { background: rgba(5, 12, 10, 0.72); }
.receipt { padding: 20px; display: grid; gap: 10px; }
.receipt h2 { font-size: 26px; color: var(--green); }
.receipt h3 { color: var(--green); font-size: 15px; }
.receipt .small { color: #3f4c45; }
.receipt ul { display: grid; gap: 5px; }
.receipt #ledger div { border-bottom: 1px solid rgba(23, 35, 31, 0.2); }
.receipt button { background: var(--green); color: var(--chalk); }
.receipt button:hover:not(:disabled) { background: var(--green-lift); }
.receipt button:not(.primary) { background: transparent; color: var(--green); box-shadow: inset 0 0 0 1.5px var(--green); }
.receipt :focus-visible { outline: 3px solid #111; box-shadow: 0 0 0 6px #fff; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.stories { font-size: 14px; }
.stories li { padding-left: 12px; border-left: 3px solid var(--gilt); }
.rules { font-size: 14px; }
#rules { width: min(600px, calc(100vw - 20px)); }

/* ---- Wide desktop keeps everything visible, shorter windows drop chart height ---- */
@media (max-height: 760px) and (min-width: 901px) {
  .manage { padding: 7px 14px; gap: 12px; }
  .control .small { display: none; }
  .charts svg { height: 28px; }
}

/* ---- Tablet and phone: one column with tabs under the pub ---- */
@media (max-width: 900px) {
  #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(220px, 44dvh) auto minmax(0, 1fr);
    grid-template-areas: "top" "stage" "tabs" "panel";
  }
  .top { flex-wrap: wrap; padding: 5px 8px; gap: 3px 6px; }
  h1 { font-size: 18px; }
  .brand { gap: 6px; }
  .brand button { min-height: 34px; padding: 5px 6px; font-size: 12px; }
  .top-actions { gap: 4px; }
  .top-actions button { min-height: 34px; padding: 5px 7px; font-size: 12px; }
  .till { order: 3; width: 100%; gap: 12px; justify-content: space-between; flex-wrap: nowrap; }
  .till span { font-size: 11px; }
  .till strong { font-size: 15px; }
  .till .wide { display: grid; }
  .tabs {
    grid-area: tabs;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--green);
    border-top: 2px solid var(--gilt);
  }
  .tabs button { background: transparent; color: var(--chalk); min-height: 44px; border-radius: 0; }
  .tabs button[aria-pressed="true"] { background: var(--slate); color: var(--gilt-pale); box-shadow: inset 0 3px 0 var(--gilt); }
  .panel { grid-area: panel; overflow-y: auto; padding: 10px 12px 16px; border: 0; display: none; }
  .panel.active { display: block; }
  .manage.active { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .books.active { display: grid; gap: 14px; }
  .charts { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .charts svg { height: 56px; }
  .ledger-live { display: block; }
  .stage-actions { top: 5px; right: 5px; }
  .stage-actions button { min-height: 34px; padding: 5px 8px; font-size: 12px; }
  .talk { right: 6px; bottom: 44px; min-height: 40px; padding: 7px 11px; font-size: 13px; }
  .ticker { left: 6px; right: 6px; bottom: 6px; font-size: 12.5px; padding: 4px 7px; width: auto; max-height: 3.2em; overflow: hidden; }
  .welcome { position: fixed; inset: 72px 0 0; z-index: 10; padding: 0; place-items: start stretch; background: rgba(9, 18, 16, 0.9); }
  .welcome-card { max-width: none; width: 100%; max-height: 100%; padding: 12px 14px 16px; gap: 7px; font-size: 14px; }
  .welcome-card h2 { font-size: 22px; }
  .bubble { font-size: 13px; padding: 6px 9px 7px; max-width: min(250px, calc(100% - 12px)); }
  .chip { height: 16px; min-width: 18px; font-size: 9.5px; padding: 1px 2px; gap: 1px; margin-left: -11px; margin-top: -17px; border-radius: 8px 8px 8px 2px; }
  .chip-face { width: 11px; height: 11px; }
  .chip-glass { width: 7px; height: 11px; border-width: 1px; }
  .sim-note { margin-top: 10px; }
}

/* Very short embeds: the pub stays usable, and panels scroll */
@media (max-width: 900px) and (max-height: 620px) {
  #app { grid-template-rows: auto minmax(170px, 38dvh) auto minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
