:root {
  color-scheme: dark;
  --body: #09111d;
  --halo: #163644;
  --warning: #f4d471;
  --track-on: #63edbd;
  --track-off: #ff88a0;
  --stripe: #762f48;
  --shadow: #0409145c;
}
:root[data-theme=light] {
  color-scheme: light;
  --body: #eaf0f7;
  --halo: #d8ede7;
  --warning: #775100;
  --track-on: #42bc99;
  --track-off: #e3859b;
  --stripe: #9e415c;
  --shadow: #30476212;
}
@media (prefers-color-scheme: light) {
  :root[data-theme=auto] {
    color-scheme: light;
    --body: #eaf0f7;
    --halo: #d8ede7;
  }
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(ellipse 75% 370px at 50% 0, var(--halo), transparent), var(--body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, .rail-scroll:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}
h1:focus { outline: none; }
h2 { font-size: 15px; letter-spacing: -.01em; }

.app {
  --pad: clamp(14px, 4.6vw, 27px);
  max-width: 640px;
  margin-inline: auto;
  padding:
    calc(19px + max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)))
    calc(var(--pad) + max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px)))
    calc(18px + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)))
    calc(var(--pad) + max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px)));
}
.masthead, .identity, .card-top, .date-line, .date-line time, .screen-back,
.timeline-heading, .rail-nav, .app-footer {
  display: flex;
  align-items: center;
}
.masthead, .card-top, .date-line, .timeline-heading, .app-footer { justify-content: space-between; }
.masthead {
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--edge);
}
.identity { gap: 10px; font-size: 17px; font-weight: 750; line-height: 1.03; }
.identity small {
  display: block;
  margin-top: 5px;
  color: var(--soft);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.brand-icon, .card-icon, .state-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 39px;
  height: 39px;
  border-radius: 11px;
  color: var(--tone, var(--on));
  background: var(--well);
}
.brand-icon {
  border: 1px solid color-mix(in srgb, var(--on) 44%, var(--edge));
  background: color-mix(in srgb, var(--on) 9%, var(--well));
}
.demo-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--surface);
  color: var(--blue);
  font-size: 12px;
  font-weight: 680;
}
.demo-badge::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}
.screen-back {
  min-height: 44px;
  gap: 4px;
  margin-top: 7px;
  margin-left: -5px;
  padding: 0 7px 0 2px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--blue);
  font-size: 13px;
  font-weight: 650;
}
.page-heading { margin-block: 23px 20px; }
.screen-back:not([hidden]) + main .page-heading { margin-top: 4px; }
.page-heading h1 {
  font-size: clamp(30px, 9vw, 46px);
  line-height: 1.11;
  letter-spacing: -.045em;
}
.page-heading p { margin-top: 7px; color: var(--soft); font-size: 14px; }
.day-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--edge);
  border-radius: 13px;
  background: var(--well);
}
.day-picker button, .theme-grid button {
  min-width: 0;
  min-height: 44px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--soft);
  font-size: 14px;
  font-weight: 650;
  transition: background-color .17s, color .17s, border-color .17s;
}
.day-picker button[aria-pressed=true], .theme-grid button[aria-pressed=true] {
  border-color: var(--edge);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 2px 5px var(--shadow);
}
.date-line {
  flex-wrap: wrap;
  gap: 4px 8px;
  min-height: 26px;
  margin-block: 10px;
  color: var(--soft);
  font-size: 12px;
}
.date-line time { gap: 6px; }
.date-line svg { color: var(--blue); }
.queue-pill {
  display: inline-block;
  padding: 3px 7px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  background: var(--well);
  color: var(--blue);
  font-size: 11px;
  font-weight: 675;
}
.confirmed, .tool { --tone: var(--blue); }
.alert { --tone: var(--alert); }
.warning { --tone: var(--warning); --tint: color-mix(in srgb, var(--warning) 10%, var(--surface)); }
.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.menu-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  padding: clamp(10px, 3.4vw, 17px);
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 5px 14px var(--shadow);
  text-align: left;
  transition: border-color .16s, transform .16s;
}
.menu-card.place {
  min-height: 153px;
  border-color: var(--tone);
  border-color: color-mix(in srgb, var(--tone) 48%, var(--edge));
  background: var(--tint, var(--surface));
  background: linear-gradient(140deg, color-mix(in srgb, var(--tone) 11%, var(--surface)), var(--surface) 90%);
}
.menu-card.tool { min-height: 111px; }
.card-top { gap: 5px; margin-bottom: 9px; color: var(--tone); }
.card-icon { width: 34px; height: 34px; border-radius: 9px; }
.place .card-icon, .state-icon { background: color-mix(in srgb, var(--tone) 11%, var(--well)); }
.menu-card strong { font-size: clamp(14px, 4.23vw, 21px); font-weight: 760; letter-spacing: -.025em; }
.menu-card small { margin-top: 4px; color: var(--soft); font-size: 12px; }
.card-desc { margin-top: 4px; color: var(--tone); font-size: 12px; font-weight: 690; }
.status-dot {
  align-self: flex-start;
  width: 7px;
  height: 7px;
  margin: 5px 1px 0 0;
  border-radius: 50%;
  background: var(--tone);
  box-shadow: 0 0 10px color-mix(in srgb, var(--tone) 57%, transparent);
}
.menu-card:active { transform: translateY(1px); }
@media (hover: hover) {
  .menu-card:hover { border-color: var(--tone); }
  .queue-row:hover { border-color: var(--blue); }
}

.state-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 68px;
  padding: 11px;
  border: 1px solid var(--edge);
  border-color: color-mix(in srgb, var(--tone) 44%, var(--edge));
  border-radius: 14px;
  background: var(--tint, var(--surface));
  background: color-mix(in srgb, var(--tone) 8%, var(--surface));
}
.state-panel h2 { color: var(--tone); font-size: 15px; }
.state-panel p { margin-top: 2px; color: var(--soft); font-size: 13px; }
.timeline, .totals-section, .settings-section { margin-top: 17px; }
.timeline-heading { min-height: 44px; gap: 4px; }
.timeline-heading h2 { font-size: 14px; }
.rail-nav { flex: none; gap: 3px; color: var(--soft); font-size: 11px; font-variant-numeric: tabular-nums; }
.rail-nav button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: var(--surface);
  color: var(--blue);
}
.rail-scroll {
  position: relative;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--edge) transparent;
  border-radius: 8px;
}
.intervals {
  display: flex;
  gap: 7px;
  min-width: 100%;
  margin: 0;
  padding: 8px 2px 7px;
  list-style: none;
}
.interval {
  flex: 1 0 61px;
  max-width: 108px;
  min-width: 0;
  scroll-snap-align: start;
  text-align: center;
}
.tile-face {
  position: relative;
  display: grid;
  place-items: center;
  height: 66px;
  border: 1px solid var(--edge);
  border-color: color-mix(in srgb, var(--tone) 32%, var(--edge));
  border-radius: 11px;
  background: var(--tint);
  color: var(--tone);
}
.tile-face svg { margin-top: 7px; }
.tile-now, .tile-revised { position: absolute; top: 4px; font-size: 9px; }
.tile-now { visibility: hidden; left: 0; right: 0; font-weight: 800; letter-spacing: .075em; text-transform: uppercase; }
.tile-revised { right: 4px; }
.revised { color: var(--warning); }
.interval.active .tile-face {
  border-color: var(--tone);
  box-shadow: 0 0 9px color-mix(in srgb, var(--tone) 37%, transparent);
}
.interval.active .tile-now { visibility: visible; }
.interval.active .tile-revised { top: auto; bottom: 3px; }
.tile-time {
  display: block;
  margin-top: 5px;
  color: var(--soft);
  font: 12px/1.26 ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}
.tile-time span { display: block; }
.legend { gap: 5px 12px; margin-top: 7px; font-size: 11px; }
.legend i { flex: none; }
.legend b { font-size: 13px; }
.totals-section h2, .settings-section h2 { margin-bottom: 8px; }
.totals-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.total {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: var(--surface);
}
.total span { color: var(--soft); font-size: 12px; }
.total strong { color: var(--tone); font-size: 19px; font-variant-numeric: tabular-nums; }

.overview {
  --row-pad: 9px;
  --row-gap: 7px;
  --queue-width: 33px;
  --arrow-width: 14px;
  --axis-start: calc(1px + var(--row-pad) + var(--queue-width) + var(--row-gap));
  --axis-end: calc(1px + var(--row-pad) + var(--arrow-width) + var(--row-gap));
}
.overview .legend { margin: 3px 0 11px; }
.legend .now-key i { width: 2px; height: 10px; border: 0; border-radius: 1px; background: var(--blue); }
.overview-scale {
  display: grid;
  grid-template-columns: var(--axis-start) minmax(0, 1fr);
  padding-right: var(--axis-end);
  margin-bottom: 5px;
  color: var(--soft);
  font-size: 11px;
}
.overview-scale > span { padding-left: var(--row-pad); }
.overview-scale div { display: flex; justify-content: space-between; font-family: ui-monospace, monospace; }
.overview-rows { position: relative; display: grid; gap: 5px; }
.queue-row {
  display: grid;
  grid-template-columns: var(--queue-width) minmax(0, 1fr) var(--arrow-width);
  align-items: center;
  gap: var(--row-gap);
  width: 100%;
  min-height: 44px;
  padding: 4px var(--row-pad);
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
  transition: border-color .16s;
}
.queue-row > strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.queue-summary { display: grid; gap: 3px; min-width: 0; }
.overview-track { display: flex; height: 8px; overflow: hidden; border-radius: 3px; background: var(--well); }
.overview-track .segment { flex-basis: 0; }
.segment.on { background: var(--track-on); }
.segment.off { background: repeating-linear-gradient(135deg, var(--track-off) 0 4px, var(--stripe) 4px 6px); }
.segment.alert { background: repeating-linear-gradient(135deg, var(--edge) 0 4px, var(--well) 4px 7px); }
.segment.unknown { background: var(--edge); }
.segment.corrected { box-shadow: inset 0 -2px var(--warning); }
.queue-status { color: var(--tone); font-size: 10px; line-height: 1.2; }
.queue-status b { margin-left: 2px; }
.queue-arrow { color: var(--soft); }
.overview-marker {
  position: absolute;
  inset: 0 var(--axis-end) 0 var(--axis-start);
  pointer-events: none;
}
.overview-marker span {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--now);
  width: 1px;
  background: color-mix(in srgb, var(--blue) 75%, transparent);
  box-shadow: 0 0 4px var(--blue);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: var(--well);
}
.theme-grid button { display: flex; justify-content: center; align-items: center; gap: 5px; font-size: 12px; }
.theme-grid svg { color: var(--blue); }
.settings-section p, .notice { margin-top: 8px; color: var(--soft); font-size: 13px; }
.profiles { display: grid; gap: 6px; }
.profile-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border: 1px solid var(--edge);
  border-radius: 11px;
  background: var(--surface);
}
.profile-row .card-icon { --tone: var(--blue); }
.profile-row .queue-pill { margin-left: auto; }
.app-footer {
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: 20px;
  padding-top: 10px;
  border-top: 1px solid var(--edge);
  color: var(--soft);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.app-footer #refresh-live {
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 5px 9px;
  background: var(--surface);
  color: var(--blue);
  font: inherit;
  font-weight: 700;
}
.app-footer #refresh-live:active { transform: translateY(1px); }
@media (max-width: 350px) {
  .theme-grid button svg { display: none; }
}
