/* Crowd Counter — PPG-Studio
   Calm, minimal, mobile-first. Works on iPhone Safari + Android Chrome. */

:root {
  --bg: #101418;
  --bg-elev: #19202a;
  --bg-elev-2: #222b37;
  --text: #eef2f6;
  --text-dim: #9aa7b4;
  --line: #2b3542;
  --accent: #6ea8fe;
  --plus: #3fb57a;
  --plus-press: #349466;
  --minus: #c4705a;
  --minus-press: #a85b48;
  --warn: #e0a84b;
  --danger: #e5604d;
  --radius: 18px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Prevent accidental text selection / long-press callouts while tapping fast */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* State colors applied to <body> */
body.state-warn { --bg: #1b1710; }
body.state-full { --bg: #1e1210; }
body { transition: background-color .4s ease; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #06121f;
  padding: 10px 14px;
  border-radius: 0 0 10px 0;
  z-index: 100;
  font-weight: 600;
}
.skip-link:focus { left: 0; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
}

.venue-name {
  font-size: 1.15rem;
  font-weight: 650;
  margin: 0;
  line-height: 1.2;
  max-width: 60vw;
  overflow-wrap: break-word;
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 4px;
  font-size: .8rem;
  color: var(--text-dim);
}
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
  flex: none;
}
.status.online .status-dot { background: var(--plus); box-shadow: 0 0 0 3px rgba(63,181,122,.18); }
.status.offline .status-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(224,168,75,.18); }
.status.local .status-dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(110,168,254,.18); }

.topbar-right { display: flex; gap: 8px; flex: none; }

.pill {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 42px;
  min-width: 42px;
  padding: 0 14px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pill:active { background: var(--bg-elev-2); }
.icon-btn { padding: 0; }

/* ---------- Counter main ---------- */
.counter {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(18px, 4vh, 36px);
  padding: 10px calc(18px + var(--safe-right)) 10px calc(18px + var(--safe-left));
  min-height: 0;
}

.count-display { text-align: center; }

.count-label {
  margin: 0;
  color: var(--text-dim);
  font-size: 1rem;
  letter-spacing: .02em;
}

.count-value {
  margin: 2px 0 4px;
  font-size: clamp(5rem, 28vw, 11rem);
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.capacity-line {
  margin: 0;
  color: var(--text-dim);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.capacity-bar {
  margin: 14px auto 0;
  max-width: 420px;
  height: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.capacity-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--plus);
  border-radius: 999px;
  transition: width .35s ease, background-color .35s ease;
}
body.state-warn .capacity-bar-fill { background: var(--warn); }
body.state-full .capacity-bar-fill { background: var(--danger); }

.elapsed {
  margin: 10px 0 0;
  color: var(--text-dim);
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
  min-height: 1em;
}

.alert-banner {
  margin: 14px auto 0;
  max-width: 460px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 1rem;
}
body.state-warn .alert-banner { background: rgba(224,168,75,.16); color: #f1cf8e; border: 1px solid rgba(224,168,75,.35); }
body.state-full .alert-banner { background: rgba(229,96,77,.18); color: #f3a394; border: 1px solid rgba(229,96,77,.4); }

/* ---------- Controls ---------- */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.count-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: #06121f;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: clamp(18px, 5vh, 34px) 10px;
  font-weight: 700;
  touch-action: manipulation;
  transition: transform .06s ease, filter .12s ease;
}
.count-btn-sign { font-size: clamp(2.4rem, 11vw, 3.4rem); line-height: 1; font-weight: 400; }
.count-btn-label { font-size: 1rem; letter-spacing: .02em; }

.count-btn.plus { background: var(--plus); }
.count-btn.plus:active { background: var(--plus-press); transform: scale(.97); }
.count-btn.minus { background: var(--minus); }
.count-btn.minus:active { background: var(--minus-press); transform: scale(.97); }
.count-btn:disabled { opacity: .45; cursor: not-allowed; }
.count-btn.flash { filter: brightness(1.25); }

/* ---------- Totals ---------- */
.totals {
  display: flex;
  gap: 12px;
  justify-content: center;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.total-chip {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}
.total-num { display: block; font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.total-cap { display: block; font-size: .78rem; color: var(--text-dim); margin-top: 2px; }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  color: var(--text-dim);
  font-size: .75rem;
  padding: 10px 16px calc(12px + var(--safe-bottom));
}

/* ---------- Overlays / sheets ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4,8,12,.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.overlay[hidden] { display: none; }

.sheet {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 520px;
  padding: 18px calc(18px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(18px + var(--safe-left));
  animation: sheet-up .22s ease;
}
.sheet.small {
  border-radius: 20px;
  margin: auto 16px;
  padding: 22px;
  animation: pop .18s ease;
}
.overlay:has(.sheet.small) { align-items: center; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
@keyframes pop { from { transform: scale(.96); opacity: .6; } to { transform: scale(1); opacity: 1; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 1.2rem; }
.sheet.small h2 { margin: 0 0 8px; font-size: 1.15rem; }
.sheet.small p { margin: 0 0 18px; color: var(--text-dim); line-height: 1.45; }

.sheet-body { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--text-dim); }
.field input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.05rem;
  padding: 13px 14px;
  width: 100%;
  -webkit-user-select: text;
  user-select: text;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.hint { color: var(--text-dim); font-size: .78rem; font-weight: 400; }

.toggle-field { display: flex; align-items: center; gap: 10px; font-size: .95rem; color: var(--text); }
.toggle-field input { width: 22px; height: 22px; accent-color: var(--accent); }

.settings-note { margin: 0; font-size: .78rem; color: var(--text-dim); }

.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  min-height: 50px;
  font-size: 1rem;
  font-weight: 650;
  cursor: pointer;
  padding: 0 16px;
}
.btn:active { filter: brightness(1.1); }
.btn.primary { background: var(--accent); color: #06121f; border-color: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(229,96,77,.5); }
.sheet.small .btn.danger { background: var(--danger); color: #fff; border-color: transparent; }

/* Events sheet */
.current-event {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}
.current-event-label { margin: 0; font-size: .78rem; color: var(--text-dim); }
.current-event-name { margin: 2px 0 12px; font-size: 1.15rem; font-weight: 650; overflow-wrap: break-word; }
.current-event .btn { width: 100%; }
.shareHint, .current-event .hint { display: block; margin-top: 8px; min-height: 1em; }

.new-event { display: flex; flex-direction: column; gap: 12px; }

.history-label { margin: 0 0 4px; font-size: .78rem; color: var(--text-dim); }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 38vh; overflow-y: auto; }
.history-item {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.history-link { display: block; color: var(--accent); font-weight: 600; text-decoration: none; overflow-wrap: break-word; }
.history-link:active { opacity: .7; }
.history-meta { display: block; margin-top: 2px; font-size: .75rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }

@media (min-width: 620px) {
  .sheet { border-radius: 20px; margin-bottom: 24px; }
  .overlay { align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media (prefers-contrast: more) {
  :root { --line: #4a5a6b; --text-dim: #c3ced9; }
}
