/* Deliberately single-theme: "night pitch under floodlights" is the whole point of
   this identity, not one option among two — it always renders dark, regardless of
   the viewer's OS/browser preference. No prefers-color-scheme, no light variant.
   Same tokens as the validated Phase 0 prototype (prototype-alert-flow.html). */
:root {
  --bg: #0B1220;
  --surface: #121B2E;
  --surface-2: #1A2740;
  --ink: #F2F4F8;
  --ink-muted: #98A2B8;
  --ink-faint: #64708A;
  --line: #24314D;
  --accent: #E4A93F;
  --accent-soft: #3A2E12;
  --accent-ink: #F3D79B;
  --success: #4FB67B;
  --success-soft: #15301F;
  --warning: #E08A5B;
  --warning-soft: #3A2013;
  --error: #E5877E;
  --error-soft: #3A1613;
  --shadow: rgba(0, 0, 0, 0.5);
  --glow-1: rgba(228, 169, 63, 0.16);
  --glow-2: rgba(90, 130, 200, 0.13);
  --dot: rgba(242, 244, 248, 0.06);
  --accent-glow: rgba(228, 169, 63, 0.32);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    radial-gradient(640px circle at 14% -8%, var(--glow-1), transparent 60%),
    radial-gradient(520px circle at 102% 18%, var(--glow-2), transparent 55%),
    radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: auto, auto, 22px 22px;
  background-repeat: no-repeat, no-repeat, repeat;
  background-attachment: fixed, fixed, fixed;
  color: var(--ink);
  font-family: "Public Sans", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

::selection { background: var(--accent-soft); color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
button { font-family: inherit; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }

.page {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- brand ---- */
.brand-bar { display: flex; align-items: center; gap: 0.55rem; padding: 1.3rem 1.4rem 0; }
.brand-bar svg { width: 24px; height: 24px; flex: none; }
.brand-word { font-family: "Manrope", sans-serif; font-weight: 800; font-size: 1.1rem; letter-spacing: -0.01em; }
.brand-word .rule { color: var(--ink); }
.brand-word .trigger { color: var(--accent); }

/* ---- landing / auth ---- */
.hero { padding: 2.5rem 1.4rem 1.5rem; text-align: center; }
.hero h1 {
  font-family: "Manrope", sans-serif; font-weight: 800; font-size: 1.5rem;
  margin: 1.2rem 0 0.5rem; letter-spacing: -0.01em;
}
.hero p { color: var(--ink-muted); margin: 0; font-size: 0.95rem; }
.how-it-works {
  display: flex; flex-direction: column; gap: 0.6rem;
  margin: 1.6rem 1.4rem; padding: 1rem 1.1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.how-step { display: flex; align-items: baseline; gap: 0.6rem; font-size: 0.88rem; color: var(--ink-muted); }
.how-step b { color: var(--ink); font-family: "JetBrains Mono", monospace; font-size: 0.78rem; }
.alert-sample {
  margin: 0 1.4rem 1.6rem; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 0.8rem 0.9rem; font-size: 0.85rem; text-align: left;
}
.alert-sample .who { color: var(--ink-faint); font-size: 0.72rem; margin-bottom: 0.35rem; }
.disclaimer {
  margin: 0 1.4rem 1.8rem; color: var(--ink-faint); font-size: 0.78rem; text-align: center;
  line-height: 1.5;
}

.auth-card { margin: 0 1.4rem 2rem; }
.auth-tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; }
.auth-tab {
  flex: 1; border: 1px solid var(--line); background: var(--surface); color: var(--ink-muted);
  padding: 0.6rem; border-radius: 10px; font-weight: 700; font-size: 0.85rem; cursor: pointer;
}
.auth-tab[data-active="true"] { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent); }
.field-row { margin-top: 0.7rem; }
.field-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--ink-muted); margin-bottom: 0.35rem; }
.text-input, textarea.text-input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 0.65rem 0.75rem; font-size: 0.94rem; background: var(--surface); color: var(--ink);
  font-family: "Public Sans", sans-serif; resize: vertical;
}
.text-input:focus { border-color: var(--accent); }
.field-error { color: var(--error); font-size: 0.78rem; margin: 0.3rem 0 0; }
.field-note { color: var(--ink-faint); font-size: 0.78rem; margin: 0.3rem 0 0; }
.auth-msg {
  border-radius: 10px; padding: 0.7rem 0.85rem; font-size: 0.85rem; margin-top: 0.8rem;
}
.auth-msg[data-kind="error"] { background: var(--error-soft); color: var(--error); }
.auth-msg[data-kind="success"] { background: var(--success-soft); color: var(--success); }
.auth-link {
  background: none; border: none; color: var(--accent); font-weight: 600; font-size: 0.82rem;
  cursor: pointer; padding: 0.5rem 0 0; text-align: left;
}

/* ---- shared header / body ---- */
.scr-head {
  padding: 1.4rem 1.4rem 0.9rem; border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem;
}
.scr-head h1 { font-family: "Manrope", sans-serif; font-weight: 800; font-size: 1.35rem; margin: 0 0 0.2rem; letter-spacing: -0.01em; }
.scr-sub { margin: 0; color: var(--ink-muted); font-size: 0.9rem; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-muted);
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; line-height: 1; cursor: pointer; flex: none;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.scr-body { padding: 1.1rem 1.4rem 1.4rem; flex: 1; }

/* ---- tab bar ---- */
.tab-bar {
  display: flex; border-top: 1px solid var(--line); background: var(--surface);
  position: sticky; bottom: 0;
}
.tab-btn {
  flex: 1; border: none; background: none; color: var(--ink-faint);
  padding: 0.85rem 0.5rem 0.7rem; font-size: 0.78rem; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem;
}
.tab-btn svg { width: 20px; height: 20px; }
.tab-btn[data-active="true"] { color: var(--accent); }

/* ---- rule list ---- */
.new-rule-btn {
  width: 100%; border: none; background: var(--accent); color: #fff; font-weight: 700;
  font-size: 0.96rem; padding: 0.85rem 1rem; border-radius: 12px; cursor: pointer;
  margin-bottom: 1.1rem; box-shadow: 0 10px 22px -8px var(--accent-glow);
}
.new-rule-btn:hover { filter: brightness(1.06); }
.rule-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.rule-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 0.95rem 1rem;
  background: var(--surface); box-shadow: 0 1px 2px var(--shadow);
}
.rule-card[data-enabled="false"] { opacity: 0.58; }
.rc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; margin-bottom: 0.5rem; }
.rc-name { font-weight: 700; font-size: 0.98rem; }
.rc-controls { display: flex; align-items: center; gap: 0.4rem; flex: none; }
.switch {
  width: 38px; height: 22px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line);
  position: relative; cursor: pointer; flex: none;
}
.switch[data-on="true"] { background: var(--success); border-color: var(--success); }
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform 0.15s ease;
}
.switch[data-on="true"]::after { transform: translateX(16px); }
.rc-icon-btn { background: none; border: none; color: var(--ink-faint); cursor: pointer; padding: 0.3rem; display: flex; align-items: center; }
.rc-icon-btn svg { width: 15px; height: 15px; }
.rc-icon-btn:hover { color: var(--ink); }
.rc-icon-btn.danger:hover { color: var(--error); }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.5rem; }
.chip { font-size: 0.72rem; font-weight: 600; background: var(--surface-2); color: var(--ink-muted); padding: 0.2rem 0.55rem; border-radius: 20px; }
.chip.score { font-family: "JetBrains Mono", monospace; color: var(--accent-ink); background: var(--accent-soft); }
.chip.live { background: var(--error-soft); color: var(--error); }
.rc-rule { margin: 0; color: var(--ink-muted); font-size: 0.85rem; }
.empty-state { text-align: center; padding: 2rem 0.5rem; }
.empty-hint { color: var(--ink-faint); font-size: 0.85rem; margin: 0 0 1.2rem; }
.example-btn {
  display: block; width: 100%; text-align: left; border: 1px dashed var(--line); background: var(--surface);
  color: var(--ink); border-radius: 12px; padding: 0.75rem 0.9rem; margin-bottom: 0.6rem;
  font-size: 0.85rem; cursor: pointer;
}
.example-btn:hover { border-color: var(--accent); }
.example-btn b { display: block; margin-bottom: 0.15rem; }
.example-btn span { color: var(--ink-muted); font-size: 0.8rem; }

/* ---- settings ---- */
.settings-section { margin-bottom: 1.6rem; }
.settings-section h2 { font-family: "Manrope", sans-serif; font-weight: 800; font-size: 1rem; margin: 0 0 0.7rem; }
.settings-row {
  border: 1px solid var(--line); border-radius: 12px; padding: 0.85rem 0.95rem; background: var(--surface);
  margin-bottom: 0.6rem;
}
.settings-row p { margin: 0; font-size: 0.85rem; color: var(--ink-muted); }
.status-pill {
  display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; font-weight: 700;
  padding: 0.2rem 0.55rem; border-radius: 20px; margin-bottom: 0.5rem;
}
.status-pill[data-connected="true"] { background: var(--success-soft); color: var(--success); }
.status-pill[data-connected="false"] { background: var(--warning-soft); color: var(--warning); }

/* ---- controls / wizard (shared with rule form) ---- */
.progress { display: flex; gap: 5px; padding: 0 1.4rem; margin-top: 0.9rem; }
.progress i { flex: 1; height: 4px; border-radius: 3px; background: var(--surface-2); }
.progress i[data-done="true"] { background: var(--accent); }
.wiz-body { padding: 0 1.4rem 1.2rem; flex: 1; }
.step-head { display: flex; align-items: flex-start; gap: 0.85rem; margin: 1.15rem 0 1.15rem; }
.step-icon {
  width: 42px; height: 42px; border-radius: 13px; flex: none; background: var(--accent-soft); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
}
.step-icon svg { width: 21px; height: 21px; }
.step-text { flex: 1; padding-top: 0.1rem; }
.step-eyebrow {
  font-family: "JetBrains Mono", monospace; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-faint); display: block; margin-bottom: 0.2rem;
}
.wiz-body h2 { font-family: "Manrope", sans-serif; font-weight: 800; font-size: 1.2rem; margin: 0 0 0.3rem; letter-spacing: -0.01em; }
.wiz-sub { margin: 0; color: var(--ink-muted); font-size: 0.88rem; }

input.ctrl {
  appearance: none; -webkit-appearance: none; width: 20px; height: 20px; flex: none;
  border: 1.6px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; position: relative;
}
input.ctrl[type="radio"] { border-radius: 50%; }
input.ctrl:checked { background: var(--accent); border-color: var(--accent); }
input.ctrl[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 9px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
input.ctrl[type="radio"]:checked::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; border-radius: 50%;
  background: #fff; transform: translate(-50%, -50%);
}

.opt-row {
  display: flex; align-items: center; gap: 0.7rem; border: 1px solid var(--line); border-radius: 12px;
  padding: 0.7rem 0.85rem; margin-bottom: 0.55rem; cursor: pointer;
}
.opt-row:hover { border-color: var(--accent); }
.opt-row[data-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.opt-text { display: flex; flex-direction: column; gap: 0.1rem; }
.opt-title { font-weight: 600; font-size: 0.92rem; }

.mode-card { border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem 0.9rem; margin-bottom: 0.6rem; cursor: pointer; }
.mode-card[data-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.mode-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.15rem; }
.mode-title { font-weight: 700; font-size: 0.92rem; }
.mode-desc { margin: 0; font-size: 0.83rem; color: var(--ink-muted); padding-left: 1.75rem; }

.num-input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 0.65rem 0.75rem;
  font-size: 0.98rem; background: var(--surface); color: var(--ink); font-family: "JetBrains Mono", monospace;
}
.num-input:focus { border-color: var(--accent); }

.score-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-bottom: 0.9rem; }
.score-opt {
  position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 0.65rem 0.5rem;
  text-align: center; cursor: pointer;
}
.score-opt[data-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.score-opt[data-checked="true"]::after {
  content: ""; position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.score-opt input { display: none; }
.score-val { font-family: "JetBrains Mono", monospace; font-weight: 700; font-size: 0.98rem; display: block; }

.adv-toggle {
  background: none; border: none; color: var(--accent); font-weight: 600; font-size: 0.85rem;
  padding: 0.3rem 0; cursor: pointer; display: flex; align-items: center; gap: 0.3rem;
}
.adv-panel { border: 1px dashed var(--line); border-radius: 12px; padding: 0.8rem 0.9rem; margin-top: 0.6rem; }
.adv-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.adv-label { font-size: 0.88rem; font-weight: 600; }
.adv-note { margin: 0.45rem 0 0; font-size: 0.8rem; color: var(--ink-muted); }
.adv-warn {
  margin: 0.6rem 0 0; padding: 0.55rem 0.7rem; border-radius: 8px; font-size: 0.8rem; line-height: 1.45;
  background: var(--accent-soft); color: var(--accent-ink);
}
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem; margin-top: 0.8rem;
  padding: 0.25rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
}
.seg-btn {
  border: none; background: none; color: var(--ink-muted); font-weight: 600; font-size: 0.84rem;
  padding: 0.5rem 0.4rem; border-radius: 7px; cursor: pointer;
}
.seg-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); box-shadow: inset 0 0 0 1px var(--accent); }
.minute-readout {
  margin-top: 0.8rem; text-align: center; font-family: "JetBrains Mono", monospace;
  font-size: 1.7rem; font-weight: 700; color: var(--accent); line-height: 1.1;
}
.minute-range {
  --fill: 0%;
  -webkit-appearance: none; appearance: none; width: 100%; height: 8px; margin: 0.7rem 0 0;
  border-radius: 999px; cursor: pointer; outline-offset: 4px;
  background: linear-gradient(to right, var(--accent) 0 var(--fill), #3A4A6B var(--fill) 100%);
}
.minute-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--ink); border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.minute-range::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink); border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.minute-range::-moz-range-track { background: transparent; }
.minute-ticks {
  display: flex; justify-content: space-between; margin-top: 0.35rem;
  font-family: "JetBrains Mono", monospace; font-size: 0.72rem; color: var(--ink-muted);
}

.char-count { text-align: right; font-size: 0.72rem; color: var(--ink-faint); margin-top: 0.2rem; }
.preview-box {
  background: var(--accent-soft); color: var(--accent-ink); border-radius: 12px; padding: 0.8rem 0.9rem;
  margin-top: 1.1rem; font-size: 0.88rem; line-height: 1.5;
}
.preview-label { font-weight: 700; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; display: block; margin-bottom: 0.3rem; }

.wiz-foot { display: flex; gap: 0.6rem; padding: 0.9rem 1.4rem 1.3rem; border-top: 1px solid var(--line); }
.btn {
  flex: 1; border-radius: 12px; padding: 0.75rem 1rem; font-weight: 700; font-size: 0.92rem;
  cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; flex: 2; box-shadow: 0 8px 18px -6px var(--accent-glow); }
.btn.primary:disabled { background: var(--surface-2); border-color: var(--line); color: var(--ink-faint); cursor: not-allowed; box-shadow: none; }
.btn:not(.primary):hover { background: var(--surface-2); }
.btn.primary:not(:disabled):hover { filter: brightness(1.06); }
.btn.full { flex: none; width: 100%; }

.success-scr { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 2rem; gap: 0.6rem; }
.success-badge {
  width: 56px; height: 56px; border-radius: 50%; background: var(--success-soft); color: var(--success);
  display: flex; align-items: center; justify-content: center; margin-bottom: 0.4rem;
}
.success-badge svg { width: 26px; height: 26px; }
.success-scr h2 { font-family: "Manrope", sans-serif; font-size: 1.15rem; margin: 0; }
.success-scr p { color: var(--ink-muted); font-size: 0.88rem; margin: 0; max-width: 26ch; }
.success-scr .btn { flex: none; min-width: 200px; margin-top: 1.2rem; }

.loading-hint { color: var(--ink-faint); font-size: 0.85rem; text-align: center; padding: 2rem 0.5rem; }

.tg-open { display: block; text-align: center; text-decoration: none; margin-top: 0.7rem; }
.tg-waiting { margin: 0.6rem 0 0; font-size: 0.84rem; color: var(--accent-ink); }
.tg-waiting::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.5rem;
  background: var(--accent); vertical-align: middle; animation: tg-pulse 1.2s ease-in-out infinite;
}
@keyframes tg-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tg-waiting::before { animation: none; } }
.pw-title { font-family: "Manrope", sans-serif; font-size: 1.15rem; margin: 0 0 0.3rem; }
.app-notice { margin: 0.9rem 1.4rem 0; }
