/*
 * Hydra Dragons scouting: "liquid glass" theme.
 * Real blur (backdrop-filter) is used only on the floating bars, sheets and toasts. Cards are translucent
 * gradients over a soft background, which looks the same and keeps low-end phones from stuttering.
 * Falls back to solid surfaces when blur is unsupported or the device asks for reduced transparency.
 */
:root {
  color-scheme: dark;
  --base: #070b10;
  --text: #f3f7fa;
  --muted: #b3c2cb;
  --accent: #2ee6b6;
  --accent-2: #12b08b;
  --accent-ink: #03231b;
  --red: #ff5a5f;
  --blue: #4c8dff;
  --warn: #ffc14d;
  --bad: #ff7070;
  --glass: linear-gradient(150deg, rgba(255, 255, 255, .15), rgba(255, 255, 255, .05) 60%, rgba(255, 255, 255, .08));
  --glass-strong: linear-gradient(150deg, rgba(40, 52, 62, .72), rgba(18, 26, 33, .62));
  --glass-line: rgba(255, 255, 255, .2);
  --glass-hi: inset 0 1px 0 rgba(255, 255, 255, .38), inset 0 -1px 0 rgba(255, 255, 255, .06);
  --glass-shadow: 0 12px 34px rgba(0, 0, 0, .38);
  --well: rgba(0, 0, 0, .3);
  --chip: rgba(255, 255, 255, .1);
  --ctl-line: rgba(255, 255, 255, .22);
  --blur: blur(26px) saturate(185%);
  --r-card: 22px;
  --r-ctl: 14px;
  --tap: 54px;
  --blob-a: rgba(46, 230, 182, .42);
  --blob-b: rgba(76, 141, 255, .40);
  --blob-c: rgba(190, 92, 255, .28);
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --base: #e9f0f4;
    --text: #0c1720;
    --muted: #43535d;
    --accent: #0fb48c;
    --accent-2: #0a8f70;
    --accent-ink: #ffffff;
    --red: #e23b41;
    --blue: #2f6fe0;
    --warn: #9a6000;
    --bad: #c62828;
    --glass: linear-gradient(150deg, rgba(255, 255, 255, .82), rgba(255, 255, 255, .5) 60%, rgba(255, 255, 255, .64));
    --glass-strong: linear-gradient(150deg, rgba(255, 255, 255, .8), rgba(245, 249, 251, .66));
    --glass-line: rgba(255, 255, 255, .95);
    --glass-hi: inset 0 1px 0 rgba(255, 255, 255, 1), inset 0 -1px 0 rgba(0, 0, 0, .04);
    --glass-shadow: 0 12px 30px rgba(20, 45, 65, .14);
    --well: rgba(255, 255, 255, .78);
    --chip: linear-gradient(180deg, rgba(255, 255, 255, .95), rgba(232, 240, 244, .9));
    --ctl-line: rgba(20, 50, 70, .2);
    --blob-a: rgba(46, 230, 182, .45);
    --blob-b: rgba(120, 170, 255, .45);
    --blob-c: rgba(255, 160, 200, .35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--base);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  padding: 0 0 calc(104px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
button, a.btn { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
input, textarea, select { font: inherit; }
[hidden] { display: none !important; }

/* soft color field behind the glass; tints red or blue for the robot being scouted */
.bg {
  position: fixed; inset: -15%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(38% 32% at 18% 12%, var(--blob-a), transparent 70%),
    radial-gradient(42% 36% at 88% 30%, var(--blob-b), transparent 70%),
    radial-gradient(40% 36% at 30% 82%, var(--blob-c), transparent 70%),
    radial-gradient(30% 26% at 80% 88%, var(--blob-a), transparent 70%);
  transition: filter .5s;
}
body.alliance-red { --blob-b: rgba(255, 90, 95, .42); --blob-c: rgba(255, 120, 90, .26); }
body.alliance-blue { --blob-a: rgba(76, 141, 255, .45); --blob-c: rgba(90, 120, 255, .30); }

/* ---------- glass primitives ---------- */
.glass, .modal-card, .toast, .update-banner {
  background: var(--glass-strong);
  border: 1px solid var(--glass-line);
  box-shadow: var(--glass-hi), var(--glass-shadow);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.field, .group, .qr-panel .msgs:not(:empty), .histbtn, .sugg {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  box-shadow: var(--glass-hi), 0 6px 20px rgba(0, 0, 0, .18);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --glass-strong: linear-gradient(150deg, #1d2730, #141c22); }
}
@media (prefers-reduced-transparency: reduce) {
  :root { --glass: #18222a; --glass-strong: #18222a; --blur: none; }
  .bg { display: none; }
}
@media (prefers-reduced-transparency: reduce) and (prefers-color-scheme: light) {
  :root { --glass: #ffffff; --glass-strong: #ffffff; }
}

/* ---------- header ---------- */
.topbar {
  position: sticky; top: calc(8px + env(safe-area-inset-top)); z-index: 30;
  margin: calc(8px + env(safe-area-inset-top)) 10px 0;
  border-radius: var(--r-card);
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 14px;
}
body.alliance-red .topbar { background: linear-gradient(150deg, rgba(255, 90, 95, .42), rgba(120, 30, 40, .4)); border-color: rgba(255, 140, 140, .6); }
body.alliance-blue .topbar { background: linear-gradient(150deg, rgba(76, 141, 255, .45), rgba(25, 50, 120, .42)); border-color: rgba(140, 180, 255, .6); }
@media (prefers-color-scheme: light) {
  body.alliance-red .topbar { background: linear-gradient(150deg, rgba(255, 200, 200, .9), rgba(255, 170, 170, .7)); }
  body.alliance-blue .topbar { background: linear-gradient(150deg, rgba(200, 220, 255, .9), rgba(165, 195, 255, .7)); }
}
.status-btn { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 2px 0; display: flex; flex-direction: column; cursor: pointer; }
.status { font-weight: 800; font-size: 19px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-line { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-line.needs { color: var(--warn); font-weight: 700; }
.icon-btn {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%;
  background: var(--chip); border: 1px solid var(--ctl-line); box-shadow: var(--glass-hi);
  font-size: 22px; line-height: 1; font-weight: 800;
}

/* ---------- bottom dock with a sliding glass lens ---------- */
.dock {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(560px, calc(100% - 20px));
  border-radius: 999px; padding: 6px;
}
.tabs { position: relative; display: grid; grid-template-columns: repeat(var(--n, 5), 1fr); }
.tab-lens {
  position: absolute; top: 0; bottom: 0; left: 0;
  width: calc(100% / var(--n, 5));
  transform: translateX(calc(var(--i, 0) * 100%));
  border-radius: 999px;
  background: linear-gradient(160deg, rgba(255, 255, 255, .34), rgba(255, 255, 255, .1));
  border: 1px solid rgba(255, 255, 255, .45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 4px 14px rgba(0, 0, 0, .25);
  transition: transform .42s cubic-bezier(.3, 1.35, .45, 1);
}
@media (prefers-color-scheme: light) { .tab-lens { background: linear-gradient(160deg, #fff, rgba(255, 255, 255, .7)); border-color: #fff; } }
.tab {
  position: relative; z-index: 1; min-height: 48px; background: none; border: 0; border-radius: 999px;
  font-weight: 700; font-size: 15px; color: var(--muted);
}
.tab.active { color: var(--text); }
body.modal-open .dock { display: none; }

/* ---------- panels + fields ---------- */
.panel { padding: 14px 12px 8px; max-width: 900px; margin: 0 auto; }
.hint { margin: 2px 4px 12px; color: var(--muted); font-size: 14px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { position: relative; border-radius: var(--r-card); padding: 12px; min-width: 0; scroll-margin-top: 110px; }
.field.text, .field.number, .field.team, .field.radio, .field.multi, .field.bool, .field.wide, .field.path, .group { grid-column: 1 / -1; }
@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  .field.bool { grid-column: auto; }
}
.label { display: block; font-weight: 700; font-size: 15px; margin: 0 2px 8px; }
.help { margin: 8px 2px 0; color: var(--muted); font-size: 13px; }
.warnfield .label, .warnfield .tlabel { color: var(--warn); }

input[type=text], textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px; border-radius: var(--r-ctl);
  border: 1px solid var(--ctl-line); background: var(--well); color: var(--text); font-size: 20px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .18);
}
textarea { font-size: 16px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 3px solid rgba(46, 230, 182, .55); outline-offset: 1px; }
.charcount { display: block; text-align: right; color: var(--muted); font-size: 12px; margin-top: 4px; }
.field.big input[type=text] { font-size: 30px; font-weight: 800; text-align: center; letter-spacing: .02em; }

.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 8px; }
.step {
  border-radius: var(--r-ctl); border: 1px solid var(--ctl-line); background: var(--chip); box-shadow: var(--glass-hi);
  font-size: 30px; font-weight: 800; min-height: 60px;
}

.teamhint { margin-top: 8px; font-size: 17px; font-weight: 700; text-align: center; min-height: 1.4em; }
.teamhint.bad { color: var(--bad); }

/* automatic event line in setup */
.event-box { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; padding: 10px 12px; border-radius: var(--r-ctl); background: var(--well); }
.event-line { flex: 1 1 200px; margin: 0; font-size: 13px; color: var(--muted); }

/* pit helper: teams at the event not pit-scouted yet */
.remaining { margin: 12px 12px 0; border-radius: var(--r-card); padding: 0 12px; max-width: 900px; background: var(--glass); border: 1px solid var(--glass-line); box-shadow: var(--glass-hi); }
@media (min-width: 924px) { .remaining { margin: 12px auto 0; } }
.remaining summary { color: var(--muted); font-size: 14px; padding: 12px 2px; cursor: pointer; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 12px; }
.chip { border-radius: 999px; padding: 8px 12px; font-size: 14px; font-weight: 700; cursor: pointer; background: var(--chip); border: 1px solid var(--ctl-line); }

/* team number suggestions (event teams + teams this phone has entered) */
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; justify-content: center; }
.sugg {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 76px; min-height: 48px;
  padding: 6px 12px; border-radius: var(--r-ctl); cursor: pointer; line-height: 1.1;
}
.sugg .sn { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.sugg .sname { font-size: 11px; color: var(--muted); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* counter tile: tap anywhere = +1 */
.field.counter { padding: 0; display: flex; flex-direction: column; }
.counter .inc {
  flex: 1; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 6px;
  min-height: 132px; width: 100%; padding: 12px 14px 12px; text-align: left;
  background: none; border: 0; border-radius: var(--r-card); cursor: pointer; user-select: none; -webkit-user-select: none;
}
.counter .clabel { font-weight: 700; font-size: 15px; line-height: 1.2; padding-right: 4px; }
.counter .val { align-self: flex-end; font-size: 46px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.counter .dec {
  position: absolute; left: 10px; bottom: 10px; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--ctl-line); background: var(--chip); box-shadow: var(--glass-hi);
  font-size: 24px; font-weight: 800; color: var(--muted); line-height: 1;
}
.field.counter.has { background: linear-gradient(150deg, rgba(46, 230, 182, .3), rgba(46, 230, 182, .08) 70%); border-color: rgba(46, 230, 182, .55); }
.field.counter.bump { animation: bump .28s ease-out; }
@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(.965); box-shadow: var(--glass-hi), 0 0 0 4px rgba(46, 230, 182, .35); }
  100% { transform: scale(1); }
}

/* switch (bool) */
.toggle {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  background: none; border: 0; padding: 2px 0; min-height: 44px; font-weight: 700; cursor: pointer;
}
.toggle .tlabel { flex: 1; order: 1; }
.toggle .box {
  order: 2; flex: 0 0 58px; height: 34px; border-radius: 999px; position: relative;
  background: rgba(127, 140, 150, .35); border: 1px solid var(--ctl-line); box-shadow: inset 0 2px 5px rgba(0, 0, 0, .22);
  transition: background .2s;
}
.toggle .box::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(180deg, #fff, #e8eef2); box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  transition: transform .28s cubic-bezier(.3, 1.4, .5, 1);
}
.toggle[aria-pressed=true] .box { background: linear-gradient(180deg, var(--accent), var(--accent-2)); }
.toggle[aria-pressed=true] .box::after { transform: translateX(24px); }

/* segmented choices */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg.wrap { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.opt {
  min-height: var(--tap); border-radius: var(--r-ctl); border: 1px solid var(--ctl-line); background: var(--chip);
  box-shadow: var(--glass-hi); font-weight: 700; padding: 6px 8px; line-height: 1.15; cursor: pointer;
}
.opt.on, .planner-seg .btn.on {
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: rgba(255, 255, 255, .5);
  color: var(--accent-ink); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 4px 14px rgba(46, 230, 182, .35);
}
.field[data-code=pos] .opt:nth-child(-n+2).on { background: linear-gradient(180deg, #ff7378, #d93c42); color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 4px 14px rgba(255, 90, 95, .4); }
.field[data-code=pos] .opt:nth-child(n+3).on { background: linear-gradient(180deg, #6aa2ff, #2f6fe0); color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 4px 14px rgba(76, 141, 255, .4); }

/* folded groups ("Anything go wrong?") */
.group { border-radius: var(--r-card); padding: 0; }
.group > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px;
  border-radius: var(--r-card); min-height: var(--tap);
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::after { content: "\203A"; margin-left: auto; font-size: 24px; line-height: 1; color: var(--muted); transition: transform .2s; }
.group[open] > summary::after { transform: rotate(90deg); }
.group-title { font-weight: 800; }
.group-hint { color: var(--muted); font-size: 13px; flex-basis: 100%; order: 3; }
.group-badge { color: var(--warn); font-weight: 800; font-size: 13px; }
.group > .grid, .group > .review, .group > .btn { margin: 0 10px 10px; }
.group .field { background: rgba(255, 255, 255, .06); box-shadow: none; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  min-height: var(--tap); padding: 10px 18px; border-radius: 999px; border: 1px solid var(--ctl-line);
  background: var(--chip); box-shadow: var(--glass-hi); font-weight: 750; cursor: pointer; color: var(--text);
}
.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: var(--accent-ink); border-color: rgba(255, 255, 255, .45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55), 0 8px 22px rgba(46, 230, 182, .35);
}
.btn.ghost { background: transparent; box-shadow: none; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 40px; padding: 6px 14px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.btn:active, .opt:active, .step:active, .icon-btn:active { transform: scale(.97); }
.wide-btn { width: 100%; }
.panel-nav { margin-top: 14px; }
.path-open { width: 100%; }

/* QR */
.qr-panel { text-align: center; }
.qr-wrap { display: flex; justify-content: center; padding: 6px 0; }
canvas.qr { image-rendering: pixelated; border-radius: 18px; max-width: 100%; height: auto; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }
.qr-caption { color: var(--muted); font-size: 14px; margin: 6px 0 4px; }
.msgs { text-align: left; border-radius: var(--r-card); }
.msgs:not(:empty) { padding: 10px; margin-bottom: 10px; }
.msgs .btn { margin-top: 4px; }
.msg { margin: 0 0 8px; padding: 10px 12px; border-radius: var(--r-ctl); font-weight: 700; }
.msg.err { background: rgba(255, 90, 95, .18); color: var(--bad); }
.msg.warn { background: rgba(255, 193, 77, .16); color: var(--warn); }
.review-group { margin-top: 12px; text-align: left; }
.review { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.review dt { color: var(--muted); }
.review dd { margin: 0; font-weight: 700; word-break: break-word; }

/* sheets (setup, menu, saved QR) */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .35); padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); overflow-y: auto;
  animation: fade .2s ease-out;
}
.modal-card {
  width: 100%; max-width: 560px; max-height: calc(100vh - 30px); overflow-y: auto;
  border-radius: 28px; padding: 14px 14px 16px; animation: rise .32s cubic-bezier(.2, 1.2, .4, 1);
}
@media (min-width: 700px) { .modal { align-items: center; } }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.modal-head h2 { font-size: 20px; margin: 0 4px; }
.close-x { width: 42px; height: 42px; min-height: 42px; padding: 0; border-radius: 50%; background: var(--chip); }
.modal-body .grid { margin-top: 8px; }
.modal-body > .wide-btn { margin-top: 12px; }
.modal-body .msg { margin-top: 10px; }
.menu-links { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 6px 0 10px; }
.modal-body > a.wide-btn { margin-top: 8px; }
.menu-title { font-size: 15px; margin: 18px 4px 2px; }
.history { list-style: none; padding: 0; margin: 8px 0; max-height: 40vh; overflow-y: auto; display: grid; gap: 6px; }
.history .empty { color: var(--muted); padding: 8px 4px; }
.histbtn { width: 100%; display: flex; justify-content: space-between; gap: 8px; padding: 12px 14px; border-radius: var(--r-ctl); text-align: left; cursor: pointer; }
.histbtn .ht { color: var(--muted); font-size: 13px; white-space: nowrap; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.tools .btn { min-height: 48px; padding: 8px 10px; font-size: 14px; }


/* toast, banner, footer */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translateX(-50%) translateY(140px); padding: 10px 18px; border-radius: 999px; font-weight: 750;
  transition: transform .3s cubic-bezier(.3, 1.3, .5, 1);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.update-banner {
  position: fixed; left: 10px; right: 10px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 70;
  max-width: 560px; margin: 0 auto; display: flex; gap: 10px; align-items: center; justify-content: space-between;
  border-radius: 20px; padding: 10px 10px 10px 16px; font-weight: 750;
}
.foot { text-align: center; color: var(--muted); font-size: 12px; margin: 16px 12px 0; }
.foot.offline.ok { color: var(--accent); }
.foot.offline.warn { color: var(--warn); }

/* auto path planner */
.planner-wrap { display: flex; justify-content: center; margin: 4px 0 8px; }
.planner-canvas { touch-action: none; border-radius: 16px; display: block; max-width: 100%; cursor: crosshair; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); }
.planner-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.planner-seg { display: flex; flex-wrap: wrap; gap: 4px; }
.planner-scrub { flex: 1 1 120px; min-width: 100px; accent-color: var(--accent); }
.planner-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; white-space: nowrap; }
.planner-sel { padding: 8px; border-radius: var(--r-ctl); background: var(--well); }
.planner-sel-label { font-weight: 800; min-width: 56px; padding-left: 4px; }
.planner-warn .msg { margin: 8px 0 0; font-size: 14px; }

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