:root {
  --red: #db0011;
  --dark: #333333;
  --ink: #1d1d1f;
  --mute: #6b6b70;
  --line: #d9d9de;
  --bg: #f3f3f5;
  --panel: #ffffff;
  --green: #1a7f4b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
input { -webkit-user-select: text; user-select: text; font: inherit; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
#app { display: flex; flex-direction: column; height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.boot { margin: auto; color: var(--mute); }

/* header */
.top { display: flex; align-items: center; gap: 16px; background: var(--dark); color: #fff; padding: 10px 16px; flex: none; }
.top h1 { font-size: 20px; margin: 0; flex: 1; font-weight: 600; }
.logo { height: 34px; width: auto; display: block; }
.where { flex: 1; text-align: left; background: none; border: 0; color: #fff; padding: 2px 0; display: flex; flex-direction: column; min-width: 0; }
.where strong { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.where span { font-size: 13px; opacity: 0.75; }
.counts { display: flex; gap: 18px; font-size: 15px; white-space: nowrap; }
.counts b { font-size: 22px; font-variant-numeric: tabular-nums; margin-right: 4px; }

/* buttons */
.btn { border: 1px solid transparent; border-radius: 10px; padding: 12px 18px; font-size: 16px; font-weight: 600; background: #e7e7ea; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--red); color: #fff; }
.btn.primary:disabled { background: #c9c9ce; color: #fff; }
.btn.ghost { background: #fff; border-color: var(--line); }
.btn.light { background: #fff; color: var(--ink); }
.btn.danger { background: #fff; border-color: var(--red); color: var(--red); }
.btn.big { font-size: 20px; padding: 18px; width: 100%; }
.btn.tiny { padding: 6px 12px; font-size: 14px; }

/* feedback bar */
.bar { flex: none; display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 92px; border-bottom: 1px solid var(--line); background: var(--panel); }
.bar-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.bar-main strong { font-size: 30px; line-height: 1.1; letter-spacing: 0.01em; }
.bar-main span { font-size: 16px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar.idle strong { font-size: 22px; color: var(--mute); }
.bar.band-white { background: #fff; box-shadow: inset 0 0 0 4px var(--dark); }
.bar.band-red { background: var(--red); color: #fff; }
.bar.band-black { background: #111; color: #fff; }
.bar.away { background: #5c5c63; color: #fff; }
.bar-btn { font-size: 18px; padding: 16px 22px; background: rgba(255, 255, 255, 0.92); color: var(--ink); border-color: rgba(0, 0, 0, 0.25); }
.bar-btn.guest { min-width: 150px; }
.flash { animation: flash 0.35s ease-out; }
@keyframes flash { from { filter: brightness(1.6); } to { filter: none; } }
.alarm { background: #fff3cd; color: #5c4400; padding: 10px 16px; font-weight: 600; border-bottom: 1px solid #e6cf7a; }

/* tally */
.tally { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 10px 12px; }
.band { flex: 1; min-height: 0; display: flex; gap: 10px; }
.band-label { flex: none; width: 92px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.band-label strong { font-size: 18px; letter-spacing: 0.04em; }
.band-label span { font-size: 14px; }
.band-white .band-label { background: #fff; border: 2px solid var(--dark); }
.band-red .band-label { background: var(--red); color: #fff; }
.band-black .band-label { background: #111; color: #fff; }
.cards { flex: 1; min-width: 0; display: flex; gap: 10px; }
.card { flex: 1; min-width: 0; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; position: relative; }
.card:active { background: #e9f3ff; border-color: #2f6fd0; transform: scale(0.98); }
.card img { flex: 1 1 0; min-height: 0; max-width: 100%; max-height: 150px; object-fit: contain; border-radius: 8px; pointer-events: none; }
.card-name { font-size: 16px; font-weight: 600; text-align: center; line-height: 1.2; }
.card-count { font-size: 14px; color: var(--mute); font-variant-numeric: tabular-nums; }
.foot { flex: none; padding: 0 12px 12px; }
.away-btn { width: 100%; background: #fff; border: 2px solid #5c5c63; color: #3a3a40; font-size: 19px; padding: 16px; }

/* setup */
.setup { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 20px; max-width: 820px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.setup h2, .totals h2 { font-size: 18px; margin: 0 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: #fff; border: 2px solid var(--line); border-radius: 999px; padding: 12px 18px; font-size: 16px; font-weight: 600; }
.chip.on { background: var(--dark); border-color: var(--dark); color: #fff; }
.inline { display: flex; gap: 8px; margin-top: 10px; }
.inline input, .modal input { flex: 1; min-width: 0; border: 2px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 16px; background: #fff; }
.hint { color: var(--mute); font-size: 14px; margin: 8px 0 0; }
.setup-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.offline { flex: 1; margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; color: var(--mute); }
.offline .dot { width: 12px; height: 12px; border-radius: 50%; background: #b5b5ba; flex: none; }
.offline.ready { color: var(--green); }
.offline.ready .dot { background: var(--green); }
.offline.failed, .offline.unsupported { color: #9a5b00; }
.offline.failed .dot, .offline.unsupported .dot { background: #d98a00; }
.ver { color: var(--mute); font-size: 13px; }

/* totals */
.totals { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 2px; }
.tile b { font-size: 32px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 14px; color: var(--mute); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel h2 + table, .panel table + h2 { margin-top: 0; }
.panel table + h2 { margin-top: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: right; padding: 8px 6px; border-bottom: 1px solid #ececf0; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: 13px; color: var(--mute); font-weight: 600; }
.band-row th { font-weight: 700; background: #f6f6f8; }
.band-row.band-red th:first-child { box-shadow: inset 5px 0 0 var(--red); padding-left: 14px; }
.band-row.band-black th:first-child { box-shadow: inset 5px 0 0 #111; padding-left: 14px; }
.band-row.band-white th:first-child { box-shadow: inset 5px 0 0 #b9b9bf; padding-left: 14px; }
.recent td:nth-child(2) { text-align: left; }
.recent td:first-child { width: 80px; color: var(--mute); }
tr.gone td:nth-child(2) { text-decoration: line-through; color: var(--mute); }
.hour { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 4px 0; }
.hl { width: 48px; color: var(--mute); font-variant-numeric: tabular-nums; }
.track { flex: 1; height: 16px; background: #efeff2; border-radius: 4px; overflow: hidden; display: flex; gap: 2px; }
.track i { display: block; height: 100%; }
.track .in { background: var(--dark); }
.track .aw { background: #a9a9b0; }
.hv { width: 120px; text-align: right; font-variant-numeric: tabular-nums; }
.file-btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.file-btns .danger { margin-left: auto; }

/* modal */
.veil { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 10; }
.modal { background: #fff; border-radius: 16px; padding: 22px; width: min(560px, 100%); display: flex; flex-direction: column; gap: 14px; }
.modal h2 { margin: 0; font-size: 22px; }
.modal p { margin: 0; font-size: 16px; line-height: 1.45; }
.reasons { display: flex; flex-direction: column; gap: 10px; }
.reason { font-size: 19px; padding: 18px; text-align: left; background: #f1f1f4; }
.modal .file-btns { margin-top: 0; }

@media (max-width: 700px), (orientation: portrait) {
  .counts { flex-direction: column; gap: 0; font-size: 13px; }
  .counts b { font-size: 16px; }
  .band-label { width: 64px; }
  .band-label strong { font-size: 14px; }
  .card-name { font-size: 14px; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .cols { grid-template-columns: 1fr; }
  .bar-main strong { font-size: 24px; }
}
@media (max-width: 520px) {
  .logo { display: none; }
  .bar { flex-wrap: wrap; }
  .card-name { font-size: 12px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
