:root {
  --bg: #1c2321; --panel: #262e2b; --panel2: #303a36; --line: #414d48;
  --ink: #edf0ea; --dim: #a5b0a8; --accent: #e0a84a; --danger: #d9634f;
  --felt: #2b4a3f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
#app { height: 100%; }
a { color: var(--accent); }
h1, h2, h3 { font-weight: 600; margin: 0 0 .5em; line-height: 1.2; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; min-height: 40px; cursor: pointer; touch-action: manipulation; }
button:hover { border-color: var(--dim); }
button.primary { background: var(--accent); color: #231a08; border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { background: #1a201e; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; min-height: 40px; width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; margin-bottom: 12px; color: var(--dim); font-size: 13px; }
label > input, label > select { margin-top: 4px; color: var(--ink); font-size: 15px; }
.error { color: var(--danger); min-height: 1.4em; margin: 6px 0; }
.dim { color: var(--dim); }

/* Pages */
.page { max-width: 780px; margin: 0 auto; padding: 32px 20px 60px; }
.brand { font-size: 28px; font-weight: 700; letter-spacing: .02em; margin-bottom: 4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin: 16px 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.seat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 8px 0 14px; }
.seat-choice { display: flex; align-items: center; gap: 8px; text-align: left; }
.seat-choice.on { border-color: var(--accent); background: #3a3524; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 1px solid #0006; }

/* Table */
.table-wrap { position: fixed; inset: 0; display: flex; }
.stage-box { position: relative; flex: 1; min-width: 0; background: var(--felt); overflow: hidden; }
.stage { position: absolute; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; outline: none; }
.toolbar { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 5; max-width: calc(100% - 20px); }
.toolbar button { background: #1c2321e6; min-width: 44px; min-height: 44px; padding: 6px 10px; }
.toolbar button.on { border-color: var(--accent); color: var(--accent); }
.conn { position: absolute; top: 62px; left: 10px; background: var(--danger); color: #fff; padding: 4px 10px; border-radius: 6px; z-index: 5; }
.toast { position: absolute; bottom: 180px; left: 50%; transform: translateX(-50%); background: #000c; padding: 8px 14px; border-radius: 8px; z-index: 8; max-width: 80%; pointer-events: none; }

/* Side panel */
.side { width: 310px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
.side.hidden { display: none; }
.seats { padding: 8px 10px; border-bottom: 1px solid var(--line); max-height: 34%; overflow-y: auto; }
.seat-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; }
.seat-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-row.off .name { color: var(--dim); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; min-height: 44px; color: var(--dim); }
.tabs button.on { color: var(--ink); box-shadow: inset 0 -2px var(--accent); }
.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.feed { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 10px; font-size: 14px; overflow-wrap: anywhere; }
.feed .line { margin-bottom: 4px; }
.feed .who { font-weight: 600; }
.feed .time { color: var(--dim); font-size: 12px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.feed .priv { color: var(--accent); }
.compose { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.compose input { flex: 1; min-width: 100px; width: auto; }
.compose select { width: auto; max-width: 100%; flex: 1 1 100%; }
.notes { flex: 1; resize: none; border: 0; border-radius: 0; background: transparent; padding: 10px; min-height: 0; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; padding: 4px 10px; color: var(--dim); margin: 0; }
.check input { width: auto; min-height: 0; margin: 0; }

/* Menus and overlays */
.menu { position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px; z-index: 30; min-width: 190px; max-height: 90vh; overflow-y: auto; box-shadow: 0 8px 26px #0009; }
.menu button { display: flex; justify-content: space-between; gap: 18px; width: 100%; border: 0; background: transparent; text-align: left; min-height: 44px; padding: 8px 12px; }
.menu button:hover, .menu button:focus-visible { background: var(--panel2); }
.menu kbd { color: var(--dim); font: inherit; font-size: 12px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.overlay { position: fixed; inset: 0; background: #000a; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; max-width: 640px; width: 100%; max-height: 92vh; overflow-y: auto; }
.lobby { position: absolute; inset: 0; z-index: 10; background: #151a18f2; overflow-y: auto; }
.linkbox { display: flex; gap: 6px; margin-bottom: 8px; }
.linkbox input { flex: 1; font-size: 13px; width: auto; }
.reveal { position: fixed; inset: 0; z-index: 15; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: #0008; }
.reveal canvas { max-width: 80vw; max-height: 70vh; border-radius: 10px; box-shadow: 0 8px 40px #000; }
.search-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.search-grid button { padding: 0; background: none; border: 2px solid transparent; }
.search-grid button:hover { border-color: var(--accent); }
.search-grid canvas { width: 100%; display: block; border-radius: 6px; }
.qr { display: block; margin: 10px auto; max-width: 240px; width: 100%; image-rendering: pixelated; background: #fff; }

/* Test play */
.test-bar { position: absolute; top: 62px; left: 10px; z-index: 6; display: flex; gap: 10px; align-items: center; background: #1c2321e6; border: 1px solid var(--accent); border-radius: 8px; padding: 6px 10px; }
.test-bar select { width: auto; }

/* Editor */
a.button { display: inline-flex; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; min-height: 40px; color: var(--ink); text-decoration: none; }
.editor { position: fixed; inset: 0; display: flex; flex-direction: column; }
.ed-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.ed-head select { width: auto; }
.ed-title { font-size: 17px; }
.spacer { flex: 1; }
.ed-error { margin: 0; padding: 0 14px; min-height: 0; }
.ed-error:empty { display: none; }
.ed-tabs { background: var(--panel); overflow-x: auto; }
.ed-tabs button { flex: 1 0 auto; padding: 8px 14px; }
.ed-content { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.ed-page { max-width: 820px; width: 100%; margin: 0 auto; padding: 8px 16px 40px; }
.ed-page.wide { max-width: none; }
.ed-split { flex: 1; min-height: 0; display: flex; }
.ed-canvas { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ed-canvas .stage { position: relative; inset: auto; flex: 1; min-height: 0; background: var(--felt); }
.ed-canvas .stage.drawing { cursor: crosshair; }
.ed-tools { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.ed-tools select { width: auto; }
.ed-tools button { padding: 6px 10px; }
.side-form { width: 340px; flex: none; overflow-y: auto; padding: 10px 14px 30px; background: var(--panel); border-left: 1px solid var(--line); }
.ed-three { flex: 1; min-height: 0; display: grid; grid-template-columns: 220px minmax(320px, 1fr) minmax(240px, 380px); }
.ed-list { display: flex; flex-direction: column; gap: 6px; padding: 10px; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); }
.ed-list button { text-align: left; }
.ed-list button.on { border-color: var(--accent); }
.ed-list button.add { color: var(--dim); }
.ed-form { padding: 10px 16px 40px; overflow-y: auto; }
.ed-preview { display: flex; gap: 14px; padding: 14px; flex-wrap: wrap; align-items: flex-start; overflow: auto; }
.ed-preview canvas { max-width: 100%; display: block; border-radius: 8px; margin-top: 4px; }
.inspector h3 { margin-top: 8px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair:has(> :nth-child(3)) { grid-template-columns: 1fr 1fr 1fr; }
.quad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.group { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 10px 0; }
.group summary { cursor: pointer; font-weight: 600; min-height: 28px; }
.group > button { margin: 4px 6px 4px 0; }
.color-field { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.color-field label { flex: 1; margin: 0; }
.swatch { width: 44px; flex: none; padding: 2px; }
.check { padding: 4px 0; margin-bottom: 6px; }
.actions { margin-top: 14px; }
.link { background: none; border: 0; color: var(--accent); padding: 4px 0; min-height: 32px; text-align: left; }
.list.compact li { padding: 2px 0; border: 0; }
label > textarea { margin-top: 4px; color: var(--ink); font-size: 15px; }
.face-row { display: grid; grid-template-columns: 70px 1fr 1fr auto; gap: 6px; align-items: end; }
.seat-edit { display: grid; grid-template-columns: 1.4fr 1.4fr 1fr 80px 80px 80px auto; gap: 8px; align-items: end; border-top: 1px solid var(--line); padding-top: 8px; }
.step-edit { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.step-edit label { flex: 1; min-width: 130px; }
.tabs-inline { margin-bottom: 12px; }
.tabs-inline button.on { border-color: var(--accent); color: var(--accent); }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.asset-grid figure { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.asset-grid img { width: 100%; height: 110px; object-fit: contain; background: #0003; }
.asset-grid .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.font-sample { height: 110px; display: flex; align-items: center; justify-content: center; font-size: 42px; }
.sheet-wrap { overflow: auto; max-height: 56vh; margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; }
.sheet { border-collapse: collapse; width: 100%; }
.sheet th { position: sticky; top: 0; background: var(--panel2); text-align: left; padding: 6px 8px; font-weight: 600; z-index: 1; white-space: nowrap; }
.sheet td { padding: 2px; border-top: 1px solid var(--line); }
.sheet tr.on td { background: #3a3524; }
.sheet input, .sheet textarea, .sheet select { min-width: 90px; border-radius: 4px; }
.sheet textarea { min-width: 240px; min-height: 40px; resize: vertical; }

@media (max-width: 900px) {
  .ed-split { flex-direction: column; }
  .side-form { width: auto; flex: 0 0 45%; border-left: 0; border-top: 1px solid var(--line); }
  .ed-three { grid-template-columns: 1fr; grid-auto-rows: min-content; overflow-y: auto; }
  .seat-edit { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 800px) {
  .side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 9; width: min(320px, 85vw); box-shadow: -4px 0 20px #0008; }
}
