:root {
  color-scheme: dark;
  --bg: #071116;
  --surface: #0f1d23;
  --surface-2: #14262e;
  --line: #21343d;
  --text: #f7f4eb;
  --muted: #9caaa9;
  --waiting: #70a9e8;
  --gold: #e2b85f;
  --ready: #43d18d;
  --danger: #f07878;
  --input: #091419;
  --lane-background: linear-gradient(160deg, #14262e, #0b181e);
  --card-background: rgba(7, 17, 22, .7);
  --count-background: rgba(255, 255, 255, .055);
  --watermark-opacity: .04;
  --screen-inset: 2vmin;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #edf2f4;
  --line: #cdd9de;
  --text: #17252c;
  --muted: #51636b;
  --waiting: #185b9e;
  --gold: #855700;
  --ready: #137d4d;
  --danger: #b52c32;
  --input: #f5f7f8;
  --lane-background: linear-gradient(160deg, #ffffff, #f6f9fa);
  --card-background: #edf2f4;
  --count-background: rgba(23, 37, 44, .06);
  --watermark-opacity: .03;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--bg); }
html[data-paired="true"], html[data-paired="true"] body { height: 100%; overflow: hidden; }

body {
  min-height: 100vh;
  color: var(--text);
  font-family: 'Outfit', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
[hidden] { display: none !important; }

.pair-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(12px, 2vmin, 36px);
  background:
    radial-gradient(circle at 15% 5%, rgba(67, 209, 141, .12), transparent 34%),
    radial-gradient(circle at 85% 92%, rgba(226, 184, 95, .12), transparent 34%),
    var(--bg);
}

.pair-card {
  width: min(1050px, 100%);
  padding: clamp(18px, 3vmin, 44px);
  border: 1px solid var(--line);
  border-radius: 32px;
  background: var(--surface);
  box-shadow: 0 32px 100px rgba(0, 0, 0, .42);
  text-align: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  color: #10171a;
  background: linear-gradient(135deg, #e2b85f, #f2d38e);
  font-size: 26px;
  font-weight: 950;
}

.eyebrow, .lane-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: clamp(13px, 1.2vw, 19px);
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.pair-card h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1;
  letter-spacing: -.04em;
}

.pair-copy {
  max-width: 610px;
  margin: 12px auto 18px;
  color: var(--muted);
  font-size: clamp(14px, 1.5vw, 21px);
  line-height: 1.35;
}
.pair-qr-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: center; gap: 24px; }
.pair-qr-panel { display: grid; justify-items: center; gap: 8px; }
#pair-qr { display: block; width: min(300px, 40vh, 100%); height: auto; background: white; border-radius: 12px; image-rendering: pixelated; }
#pair-qr-status { font-size: 13px; color: var(--muted); margin: 0; }
#pair-qr-retry { padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.pair-steps { text-align: left; font-size: clamp(13px, 1.4vw, 20px); line-height: 1.4; }
.pair-steps ol { padding-left: 20px; }
.pair-steps li { margin: 8px 0; }
.pair-steps p { color: var(--muted); }
.pair-screen-label strong { display: inline-block; color: var(--gold); font-size: 1.5em; letter-spacing: .12em; }
#pair-code-fallback { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
#pair-code-title { margin: 0; color: var(--text); font-size: 16px; line-height: 1.3; }
#pair-code-help { margin: 6px 0 10px; font-size: 12px; line-height: 1.4; }

#pair-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, .7fr); gap: 8px; align-items: center; }
#pair-form label { grid-column: 1 / -1; color: var(--text); font-size: 13px; font-weight: 750; }

#pair-code {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  outline: none;
  color: var(--text);
  background: var(--input);
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(20px, 2.4vw, 28px);
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

#pair-code:focus { border-color: var(--gold); box-shadow: 0 0 0 5px rgba(226, 184, 95, .12); }

#pair-button {
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  color: #10171a;
  background: linear-gradient(135deg, #e2b85f, #f2d38e);
  font-size: clamp(13px, 1.5vw, 18px);
  font-weight: 900;
  cursor: pointer;
}

#pair-button:disabled { opacity: .55; cursor: wait; }
.error { margin: 16px 0 0; color: var(--danger); font-weight: 750; }
.privacy-note { margin: 12px 0 0; color: var(--muted); font-size: 11px; }

.board-view {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  padding: max(8px, var(--screen-inset));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(10px, 1.5vmin, 22px);
  overflow: hidden;
  position: relative;
  isolation: isolate;
}

.theme-control { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.theme-control select { min-height: 44px; padding: 8px 12px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.theme-control select:focus-visible { outline: 3px solid var(--waiting); outline-offset: 3px; }
.theme-help { margin: 0; color: var(--muted); font-size: clamp(12px, 1vw, 16px); line-height: 1.5; }
.business-watermark { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(440px, 55vw); height: min(440px, 55vh); object-fit: contain; opacity: var(--watermark-opacity); pointer-events: none; user-select: none; z-index: 0; }
.board-view[data-screen-mode="qr"] .business-watermark, .board-view[data-screen-mode="image"] .business-watermark { display: none; }
.board-view:not([data-screen-mode="orders"]) { grid-template-rows: auto minmax(0, 1fr); }
.menu-view, .image-view {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: clamp(14px, 1.8vmin, 24px);
  padding: clamp(12px, 1.5vmin, 24px);
  /* Children are measured inside this frame. Keep the existing outer TV
     safe-area control independent from this small content inset. */
}
.menu-view { min-height: 0; display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
.menu-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(12px, 1.5vw, 24px); overflow: hidden; }
.menu-column { min-width: 0; min-height: 0; }
.menu-category { margin: 0; padding: 8px 0 10px; font-size: 1em; line-height: 1.3; color: var(--gold); border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-card { min-width: 0; overflow: hidden; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.menu-photo { display: block; flex: 0 0 42px; width: 42px; height: 42px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.menu-photo-blank { background: transparent; }
.menu-item-copy { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: start; }
.menu-item-copy h3 { margin: 0; font-size: 1em; line-height: 1.25; font-weight: 650; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.menu-price { margin: 0; font-size: .95em; line-height: 1.3; color: var(--ready); font-weight: 850; white-space: nowrap; }
.menu-unavailable { grid-column: 1 / -1; color: var(--muted); font-size: 11px; line-height: 1.1; font-weight: 750; }
.mode-empty { color: var(--muted); font-size: clamp(18px, 2vw, 28px); text-align: center; margin: auto; max-width: 640px; line-height: 1.5; }
.qr-view { min-height: 0; display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: clamp(16px, 3vw, 50px); overflow: hidden; }
.qr-copy h2 { margin: 12px 0 24px; font-size: clamp(36px, 4.5vw, 76px); line-height: 1.05; letter-spacing: -.04em; }
.qr-copy > p:not(.eyebrow), .qr-copy li { color: var(--muted); font-size: clamp(17px, 1.6vw, 25px); line-height: 1.5; }
.qr-copy ol { padding-left: 26px; }
.qr-copy li { margin: 10px 0; }
.qr-note { color: var(--text) !important; font-weight: 800; }
.qr-code-panel { display: grid; justify-items: center; gap: 18px; }
#store-qr { width: min(420px, 100%, 62vh); height: auto; aspect-ratio: 1; background: #fff; border-radius: 12px; image-rendering: pixelated; }
#store-link { color: var(--text); overflow-wrap: anywhere; text-align: center; font-size: clamp(14px, 1.2vw, 20px); max-width: 100%; }

.board-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-width: 0; position: relative; z-index: 4; }
.business-heading { flex: 1; min-width: 0; }
.board-header h1 { margin: 0; font-size: clamp(23px, 3vw, 52px); line-height: 1.1; letter-spacing: -.035em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.theme-help { margin-top: 8px; font-size: clamp(10px, 1vw, 14px); }
.header-actions { display: flex; align-items: center; gap: clamp(6px, 1vw, 16px); }
.local-controls > summary { list-style: none; cursor: pointer; padding: 10px; font-size: 22px; border-radius: 12px; border: 1px solid var(--line); }
.local-controls > summary::-webkit-details-marker { display: none; }
.local-controls-panel { position: absolute; right: 0; top: 100%; width: min(340px, 90vw); display: grid; gap: 14px; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 15px 45px #0004; }
.local-controls-panel p { margin: 0; font-size: 14px; color: var(--muted); }
.local-controls select:disabled { opacity: .6; }
.image-view { min-width: 0; min-height: 0; display: grid; place-items: center; overflow: hidden; }
#custom-display-image { display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; }

.connection {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: clamp(12px, 1vw, 17px);
  font-weight: 750;
}

.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.connection.live .connection-dot { background: var(--ready); box-shadow: 0 0 16px rgba(67, 209, 141, .75); }
.connection.offline .connection-dot { background: var(--danger); }
#clock { min-width: 94px; text-align: center; font-size: clamp(20px, 2vw, 34px); font-weight: 850; }

.icon-button {
  width: clamp(42px, 3.4vw, 58px);
  height: clamp(42px, 3.4vw, 58px);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  background: var(--surface);
  cursor: pointer;
  font-size: clamp(19px, 1.8vw, 28px);
}

.lanes { min-height: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(12px, 1.4vw, 24px); }

.lane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: clamp(16px, 1.5vw, 28px);
  border: 1px solid var(--line);
  border-radius: clamp(24px, 2.4vw, 40px);
  background: var(--lane-background);
  overflow: hidden;
}

.lane > header { display: flex; align-items: center; justify-content: space-between; margin-bottom: clamp(12px, 1.4vw, 22px); }
.lane h2 { margin: 0; font-size: clamp(22px, 3vw, 48px); line-height: 1; letter-spacing: -.04em; }
.waiting-lane h2, .waiting-lane .count { color: var(--waiting); }
.preparing-lane h2, .preparing-lane .count { color: var(--gold); }
.ready-lane { border-color: rgba(67, 209, 141, .38); box-shadow: inset 0 0 70px rgba(67, 209, 141, .04); }
.ready-lane h2, .ready-lane .count { color: var(--ready); }

.count {
  min-width: clamp(34px, 4.4vw, 58px);
  height: clamp(34px, 4.4vw, 58px);
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--count-background);
  font-size: clamp(22px, 2vw, 34px);
  font-weight: 950;
}

.lane-body {
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.order-grid {
  flex: 1;
  min-height: 0;
  align-content: start;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr));
  gap: clamp(9px, .9vw, 15px);
  overflow: hidden;
}

.order-card {
  min-height: clamp(74px, 6vw, 104px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: clamp(13px, 1.1vw, 20px);
  border: 1px solid var(--line);
  border-radius: clamp(18px, 1.5vw, 26px);
  background: var(--card-background);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(27px, 2.5vw, 46px);
  font-weight: 950;
  letter-spacing: .035em;
  white-space: nowrap;
}

.order-card::after {
  color: var(--muted);
  font-family: 'Outfit', ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(9px, .72vw, 13px);
  font-weight: 900;
  letter-spacing: .11em;
}

.waiting-lane .order-card { border-color: rgba(112, 169, 232, .35); background: rgba(112, 169, 232, .08); }
.waiting-lane .order-card::after { content: "WAITING"; color: var(--waiting); }
.preparing-lane .order-card::after { content: "MAKING"; color: var(--gold); }

.ready-lane .order-card {
  border-color: rgba(67, 209, 141, .65);
  color: #071b13;
  background: linear-gradient(135deg, #49db96, #79ebaf);
  box-shadow: 0 16px 44px rgba(67, 209, 141, .15);
}
.ready-lane .order-card::after { content: "READY"; color: #0a5134; }

.empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); text-align: center; font-size: clamp(16px, 1.35vw, 24px); }
.page-status { flex: 0 0 auto; margin: 10px 0 0; color: var(--muted); text-align: center; font-size: clamp(10px, .72vw, 13px); font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.waiting-lane .page-status { color: var(--waiting); }
.preparing-lane .page-status { color: var(--gold); }
.ready-lane .page-status { color: var(--ready); }
.board-footer { min-height: 24px; max-height: 54px; overflow: hidden; display: flex; align-items: center; justify-content: space-between; gap: 20px; color: var(--muted); font-size: clamp(11px, 1.1vw, 19px); }
.board-footer > p { margin: 0 0 0 auto; }
.collected { display: flex; align-items: center; gap: 14px; }
.collected > span { font-weight: 750; }
#collected-orders { display: flex; flex-wrap: wrap; gap: 8px; }
#collected-orders span { padding: 6px 11px; border-radius: 9px; background: var(--surface); text-decoration: line-through; }

.board-view[data-orientation="portrait"] .lanes { grid-template-columns: 1fr; grid-template-rows: repeat(3, minmax(0, 1fr)); }
.board-view[data-orientation="portrait"] .lane { padding: 12px 16px; border-radius: 22px; }
.board-view[data-orientation="portrait"] .lane > header { margin-bottom: 8px; }
.board-view[data-orientation="portrait"] .lane-kicker { display: none; }
.board-view[data-orientation="portrait"] .order-grid { grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); }
.board-view[data-orientation="portrait"] .qr-view { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 12px; }
.board-view[data-orientation="portrait"] .qr-copy h2 { font-size: 34px; margin: 0 0 8px; }
.board-view[data-orientation="portrait"] .qr-copy > p:not(.eyebrow), .board-view[data-orientation="portrait"] .qr-copy li { font-size: 15px; margin: 3px 0; line-height: 1.3; }
.board-view[data-orientation="portrait"] .qr-copy ol { margin: 8px 0; }
.board-view[data-orientation="portrait"] #store-qr { max-height: 39vh; width: min(360px, 76vw, 39vh); }
@media (max-height: 700px) {
  .board-view[data-orientation="portrait"] .lane { padding: 6px 10px; border-radius: 14px; }
  .board-view[data-orientation="portrait"] .lane > header { margin-bottom: 4px; }
  .board-view[data-orientation="portrait"] .lane h2 { font-size: 18px; }
  .board-view[data-orientation="portrait"] .count { min-width: 22px; height: 22px; font-size: 16px; }
  .board-view[data-orientation="portrait"] .order-card { min-height: 34px; padding: 4px 10px; font-size: 22px; border-radius: 9px; }
  .board-view[data-orientation="portrait"] .page-status { margin-top: 4px; font-size: 9px; }
  .board-view[data-orientation="portrait"] .qr-copy ol { display: none; }
  .board-view[data-orientation="portrait"] .qr-copy h2 { font-size: 24px; }
  .board-view[data-orientation="portrait"] #store-qr { max-height: 36vh; width: min(360px, 76vw, 36vh); }
}

@media (max-width: 1050px) {
  #clock { display: none; }
  .connection { padding: 8px; font-size: 11px; }
  .lane-kicker { font-size: 10px; letter-spacing: .05em; }
  .lane { padding: 12px; }
  .order-card::after { display: none; }
  .qr-copy h2 { font-size: clamp(27px, 4vw, 44px); margin: 0 0 14px; }
  .qr-copy > p:not(.eyebrow), .qr-copy li { font-size: 16px; }
}
@media (max-width: 600px) {
  .connection { display: none; }
  .board-header h1 { font-size: 22px; }
  .theme-help { font-size: 10px; }
  .eyebrow { font-size: 10px; }
  .pair-qr-layout { grid-template-columns: 1fr; gap: 8px; }
  .pair-steps { font-size: 14px; }
  #pair-form { grid-template-columns: 1fr; }
  #pair-qr { width: min(260px, 50vw); }
}
@media (max-height: 700px) and (orientation: landscape) {
  .pair-card .brand-mark { display: none; }
  .pair-card { padding: 16px 22px; }
  .pair-card h1 { font-size: 32px; }
  .pair-card > .eyebrow { font-size: 10px; }
  .pair-copy { font-size: 14px; margin: 8px auto 12px; }
  .pair-steps { font-size: 13px; }
  .pair-steps li { margin: 5px 0; }
  .pair-steps ol { margin: 8px 0; }
  .pair-steps > p { margin: 8px 0; }
  #pair-code-fallback { margin-top: 10px; padding-top: 10px; }
}

@media (forced-colors: active), (prefers-contrast: more) {
  .business-watermark { display: none !important; }
}

@media (prefers-reduced-motion: no-preference) {
  .ready-lane .order-card.new-ready { animation: ready-pop .7s ease-out; }
  @keyframes ready-pop {
    0% { opacity: .25; transform: scale(.88); }
    65% { transform: scale(1.035); }
    100% { opacity: 1; transform: scale(1); }
  }
}
