:root {
  --crimson: #8b1528;
  --crimson-deep: #5c0c1a;
  --crimson-ink: #3a0811;
  --silver: #c5ccd4;
  --silver-bright: #e8eef4;
  --silver-metal: linear-gradient(145deg, #f4f7fa 0%, #c7ced6 42%, #9aa3ad 78%, #dde3ea 100%);
  --bg: #f3f1f2;
  --bg-2: #fffcfd;
  --bg-3: #f7f4f5;
  --ink: #1a1214;
  --muted: #5c5054;
  --gold: #8b1528;
  --gold-deep: #5c0c1a;
  --cream: #f6f1e6;
  --mine: #1f6b3a;
  --taken: #a52a3d;
  --locked: #5c5054;
  --damaged: #8b1528;
  --line: #d9d0d3;
  --shadow: 0 12px 28px rgba(58, 8, 17, 0.18);
  --map: #3a0811;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --topbar: 58px;
  --tabs: 58px;
  --namebar: 72px;
  --font: "Manrope", "Segoe UI", sans-serif;
  --display: "Libre Baskerville", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--bg); }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 8% -8%, rgba(165, 42, 61, 0.12), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(197, 204, 212, 0.35), transparent 50%),
    linear-gradient(180deg, #f7f4f5 0%, var(--bg) 45%, #ebe6e8 100%);
  -webkit-tap-highlight-color: transparent;
}
body.page-map {
  overflow: hidden;
  height: 100dvh;
}

a { color: var(--crimson); text-decoration: none; }
button, input, select { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--topbar);
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: linear-gradient(180deg, var(--crimson-deep) 0%, var(--crimson) 100%);
  color: var(--silver-bright);
  border-bottom: 1px solid rgba(232, 238, 244, 0.18);
  box-shadow: 0 8px 24px rgba(58, 8, 17, 0.28);
}
.topbar h1, .topbar .brand-kicker, .topbar .icon-btn { color: var(--silver-bright); }
.topbar .icon-btn { border-color: rgba(232, 238, 244, 0.35); background: rgba(255, 255, 255, 0.08); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-center { flex: 1; justify-content: center; text-align: center; }
.brand h1 { margin: 0; font-size: 1.05rem; letter-spacing: 0.01em; font-family: var(--display); color: #fff; }
.brand-kicker {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--silver);
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--silver-metal);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35);
}
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
  color: var(--ink);
}
.icon-btn:active { transform: scale(0.98); }

.service-tabs {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  position: sticky;
  top: calc(var(--topbar) + var(--safe-t));
  z-index: 19;
  background: rgba(255, 252, 253, 0.94);
}
.service-tab {
  flex: 1 0 148px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 48px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  text-decoration: none;
}
.service-tab.is-active {
  background: linear-gradient(180deg, var(--crimson) 0%, var(--crimson-deep) 100%);
  border-color: var(--crimson-deep);
  color: #fff;
}
.service-tab strong { font-size: 0.92rem; }
.service-tab span { font-size: 0.75rem; color: var(--crimson); }
.service-tab.is-active span { color: var(--silver); }

.menu-event {
  display: grid;
  gap: 8px;
  margin: 8px 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.menu-event p { margin: 0; font-weight: 700; }
.menu-event input, .menu-event button {
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font: inherit;
  padding: 8px 10px;
}
.menu-event button { background: var(--silver-metal); color: var(--crimson-ink); font-weight: 700; }

.cutoff-banner {
  margin: 0 12px 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f8e4e7;
  color: var(--crimson-ink);
  font-size: 0.9rem;
}

.map-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px 8px;
}
.jump-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.jump-chips button, .zoom-btns button {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--ink);
  white-space: nowrap;
}
.zoom-btns { display: flex; gap: 6px; flex-shrink: 0; }
.zoom-btns button { min-width: 40px; font-size: 1.2rem; }

.map-stage {
  position: relative;
  height: calc(100dvh - var(--topbar) - var(--tabs) - var(--namebar) - var(--safe-t) - var(--safe-b) - 92px);
  min-height: 360px;
  margin: 0 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background:
    linear-gradient(var(--map), var(--map)) padding-box,
    radial-gradient(circle at 50% 0, #6e1020, var(--crimson-ink) 70%);
  touch-action: none;
  user-select: none;
  overscroll-behavior: none;
}
.map-canvas {
  transform-origin: 0 0;
  will-change: transform;
}
.map-hint {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  margin: 0;
  text-align: center;
  font-size: 0.75rem;
  color: rgba(243,238,228,0.7);
  pointer-events: none;
  text-shadow: 0 1px 6px #000;
}

.sanctuary { display: block; max-width: none; }
.stage-plat { fill: #c5ccd4; }
.stage-label, .section-label, .back-label, .aisle-label, .row-letter {
  fill: #e8eef4;
  font-family: var(--font);
  font-weight: 700;
  text-anchor: middle;
}
.stage-label { font-size: 22px; letter-spacing: 3px; }
.section-label { font-size: 13px; letter-spacing: 2px; fill: #c5ccd4; }
.back-label { font-size: 14px; letter-spacing: 2px; fill: #9aa6b8; }
.aisle { fill: rgba(255,255,255,0.035); }
.aisle-label { font-size: 11px; fill: #8b97ab; letter-spacing: 2px; }
.row-letter { font-size: 16px; fill: #e8eef4; }

.media-zone { fill: rgba(197, 204, 212, 0.16); stroke: #c5ccd4; stroke-width: 2; pointer-events: none; }
.media-zone-label { fill: #c5ccd4; font-size: 12px; letter-spacing: 2px; font-weight: 700; text-anchor: middle; pointer-events: none; }
.seat { cursor: pointer; }
.seat-hit { fill: transparent; }
.seat-body {
  fill: #f6f1e6;
  stroke: #2b2118;
  stroke-width: 1.4;
}
.seat-id, .seat-name, .seat-reason {
  font-family: var(--font);
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  fill: #1b140e;
}
.seat-id { font-size: 11px; }
.seat-name { font-size: 10px; }
.seat-reason { font-size: 8px; }

.seat.is-taken .seat-body { fill: #a52a3d; }
.seat.is-taken .seat-id, .seat.is-taken .seat-name, .seat.is-taken .seat-reason { fill: #fff; }
.seat.is-mine .seat-body { fill: #1f6b3a; stroke: #0d3d31; stroke-width: 3; }
.seat.is-mine .seat-id, .seat.is-mine .seat-name, .seat.is-mine .seat-reason { fill: #fff; }
.seat.is-locked .seat-body { fill: #5d6b82; }
.seat.is-locked .seat-id, .seat.is-locked .seat-name, .seat.is-locked .seat-reason { fill: #f4efe4; }
.seat.is-damaged .seat-body { fill: url(#damagedPattern); stroke: #e25555; stroke-width: 2.4; }
.seat.is-damaged .seat-id, .seat.is-damaged .seat-name, .seat.is-damaged .seat-reason { fill: #ffd0d0; }
.seat.is-focus .seat-body { stroke: #fff6d2; stroke-width: 3.2; }
.seat.is-search .seat-body { stroke: #7ad7ff; stroke-width: 3; }

.name-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: grid;
  gap: 4px;
  padding: 8px 14px calc(10px + var(--safe-b));
  background: #fffcfd;
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(58, 8, 17, 0.08);
}
.name-bar label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--crimson);
}
.name-bar input, .stack-form input, .stack-form select, .login-form input, .search-sheet input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--ink);
}
body.is-usher .name-bar,
body.sheet-open .name-bar { display: none; }
body.sheet-open .map-hint { display: none; }

.seat-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
}
.seat-modal[hidden] { display: none; }
.seat-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 6, 10, 0.62);
}
.seat-dialog {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  max-height: min(86dvh, 760px);
  overflow: auto;
  padding: 16px 16px 20px;
  border-radius: 20px;
  background: #fffcfd;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.seat-dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}
.sheet-kicker {
  margin: 10px 0 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.sheet-seat {
  margin: 0 72px 4px 0;
  font-family: var(--display);
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--crimson-ink);
}
.sheet-name {
  margin: 0 48px 2px 0;
  font-size: clamp(2.6rem, 8vw, 3.4rem);
  font-weight: 700;
  line-height: 1.05;
  color: var(--ink);
}
.sheet-reason {
  margin: 0 0 8px;
  font-weight: 700;
}
.sheet-lock {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #eef1f5;
  color: #3a0811;
  font-weight: 600;
}
.seat-name-field {
  display: grid;
  gap: 6px;
  margin: 0 0 10px;
}
.seat-name-field input,
.staff-box input,
.staff-box select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
.sheet-meta { margin: 0 0 12px; color: var(--muted); font-size: 0.92rem; }
.mini-wrap {
  background: #f7f4f5;
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 14px;
}
.mini-caption {
  margin: 0 0 8px;
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}
.mini-map { display: grid; gap: 6px; }
.mini-row { display: flex; gap: 6px; align-items: stretch; }
.mini-row-letter {
  flex: 0 0 16px;
  align-self: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
}
.mini-aisle {
  flex: 0 0 22px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(180deg, rgba(139, 21, 40, 0.16) 0 6px, transparent 6px 12px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.mini-aisle span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--crimson);
}
.mini-cell {
  flex: 1 1 0;
  min-width: 0;
  min-height: 64px;
  border-radius: 12px;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  font-size: 0.72rem;
  text-align: center;
  text-decoration: none;
  color: inherit;
}
.mini-cell b { font-size: 1rem; }
.mini-cell span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mini-cell.is-focus {
  outline: 3px solid var(--crimson);
  outline-offset: 1px;
  box-shadow: 0 8px 16px rgba(58, 8, 17, 0.18);
}
.mini-cell.is-you {
  background: #1f6b3a;
  color: #fff;
  border-style: solid;
  border-color: #1f6b3a;
}
.mini-cell.is-open { background: #f6f1e6; color: #1b140e; border-style: solid; }
.mini-cell.is-taken { background: #a52a3d; color: #fff; border-style: solid; }
.mini-cell.is-locked { background: #5d6b82; color: #fff; border-style: solid; }
.mini-cell.is-damaged { background: #6a2424; color: #ffd0d0; border-style: solid; }
.mini-cell.is-empty { opacity: 0.55; }
.mini-back { margin: 8px 0 0; text-align: center; font-size: 0.72rem; color: #9aa6b8; letter-spacing: 0.12em; }
.sheet-actions { display: grid; gap: 8px; }
.sheet-actions.two { grid-template-columns: 1fr 1fr; }
.btn {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-3);
  color: var(--ink);
  padding: 0 14px;
}
.btn.primary { background: var(--silver-metal); color: var(--crimson-ink); border: 0; font-weight: 700; box-shadow: 0 4px 0 rgba(90, 98, 108, 0.35); }
.btn.danger { background: var(--crimson); color: #fff; }
.btn.ghost { background: transparent; }
.staff-box {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
}
.staff-box h3 { margin: 0; font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--crimson); }
.check { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 0.9rem; }

.menu-overlay, .search-overlay, .legend-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(26, 6, 10, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.menu-sheet, .search-sheet, .legend-sheet {
  width: 100%;
  background: #fffcfd;
  color: var(--ink);
  border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b));
  display: grid;
  gap: 10px;
}
.menu-sheet {
  position: absolute;
  top: calc(var(--topbar) + var(--safe-t) + 8px);
  right: 12px;
  left: auto;
  bottom: auto;
  width: min(320px, calc(100vw - 24px));
  max-height: min(70dvh, 520px);
  overflow: auto;
  margin: 0;
  transform: none;
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.menu-toggle {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  align-items: center;
}
.menu-toggle small { grid-column: 2; color: var(--muted); }
.menu-link, .menu-close, .search-sheet button, .legend-sheet button {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--ink);
  display: flex;
  align-items: center;
  padding: 0 14px;
}
.menu-user { margin: 0; color: var(--muted); }
.legend-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.legend-list li { display: flex; align-items: center; gap: 10px; }
.swatch { width: 28px; height: 20px; border-radius: 6px; display: inline-block; }
.swatch.open { background: #f6f1e6; }
.swatch.mine { background: #1f6b3a; }
.swatch.taken { background: #a52a3d; }
.swatch.locked { background: #5d6b82; }
.swatch.damaged { background: repeating-linear-gradient(45deg, #3a1515, #3a1515 4px, #e25555 4px, #e25555 6px); }
#search-results { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow: auto; }
#search-results li, #search-results a {
  display: block;
  min-height: 48px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.toasts {
  position: fixed;
  top: calc(12px + var(--safe-t));
  left: 12px;
  right: 12px;
  z-index: 50;
  display: grid;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #fffcfd;
  color: var(--crimson-ink);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.toast.lock { background: #1d2433; color: #d7e3ff; border-color: #7d8ba3; }
.toast.ok { background: #0e2e26; color: #b9ffe8; border-color: #2ec9a0; }

.login-page, .admin-page, .seat-page {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px calc(32px + var(--safe-b));
}
.lede, .hint { color: var(--muted); }
.login-form, .stack-form { display: grid; gap: 12px; }
.login-form label, .stack-form label { display: grid; gap: 6px; }
.form-error { background: #f8e4e7; color: var(--crimson); padding: 10px 12px; border-radius: 12px; }
.form-ok { background: #e2f3e8; color: var(--mine); padding: 10px 12px; border-radius: 12px; }
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
}
.user-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.user-list li { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.user-list span { display: block; color: var(--muted); font-size: 0.85rem; }
.back-link { display: inline-block; margin-bottom: 16px; }
.empty { color: var(--muted); }

.page-seat .seat-page { padding-top: 12px; }

@media (min-width: 860px) {
  .search-overlay, .legend-overlay {
    align-items: center;
  }
  .search-sheet, .legend-sheet {
    width: min(440px, calc(100vw - 32px));
    border-radius: 20px;
    max-height: 86vh;
    overflow: auto;
  }
  .map-stage { min-height: 520px; }
}
