:root {
  --bg: #0f1a14;
  --panel: #16241c;
  --panel2: #1f3327;
  --line: #2b4436;
  --text: #eef4ef;
  --muted: #9fb3a6;
  --accent: #f2c14e;
  --primary: #2f6fdb;
  --danger: #d64545;
  --def: #2f6fdb;
  --off: #d64545;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body {
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  height: 100vh; height: 100dvh; overflow: hidden; overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.spacer { flex: 1; }

header, footer, #stepsBar, #stepDetail {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel);
}
header { border-bottom: 1px solid var(--line); }
footer { border-top: 1px solid var(--line); flex-wrap: wrap; }
#stepsBar { border-top: 1px solid var(--line); }
#stepDetail { padding-top: 0; flex-wrap: wrap; }

button, select, input[type=text] {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; min-height: 40px; padding: 0 12px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: #4b6a58; }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--primary); border-color: var(--primary); font-weight: 600; }
button.accent { background: var(--accent); border-color: var(--accent); color: #1b1b1b; font-weight: 600; }
button.danger { color: #ffb3b3; }
button.toggle[aria-pressed=true] { background: #2a4a38; border-color: var(--accent); color: var(--accent); }
.pickers { display: flex; gap: 8px; min-width: 0; flex: 0 1 auto; }
.pickers select { min-width: 0; text-overflow: ellipsis; }
#groupSelect { max-width: 24vw; color: var(--accent); }
#playSelect { max-width: 34vw; font-weight: 600; }
#stepName { flex: 1 1 100px; min-width: 0; }
label.inline { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

main { position: relative; min-height: 0; background: #1c3323; }
#field { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }

#stepChips { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: thin; padding-bottom: 2px; }
.chip { display: flex; align-items: center; gap: 6px; flex: none; }
.chip b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--line); font-size: 12px; }
.chip.active { border-color: var(--accent); background: #2a4a38; }
.chip.active b { background: var(--accent); color: #1b1b1b; }

/* pieces */
.piece { cursor: grab; }
.piece.dragging { cursor: grabbing; }
.piece .hit { fill: transparent; }
.piece .body { stroke: #fff; stroke-width: 3; filter: url(#shadow); }
.piece.def .body { fill: var(--def); }
.piece.off .body { fill: var(--off); }
.piece.ball .body { fill: #fff; stroke: #c62828; stroke-width: 2.5; }
.piece text { fill: #fff; font-weight: 700; font-size: 20px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.piece.selected .body { stroke: var(--accent); stroke-width: 5; }
.piece.ball.selected .body { stroke: var(--accent); stroke-width: 4; }

.trail { fill: none; stroke-width: 3.5; stroke-dasharray: 10 7; stroke-linecap: round; opacity: .95; }
.trail.def { stroke: #9cc0ff; }
.trail.off { stroke: #ffa3a3; }
.trail.ball { stroke: #fff; stroke-dasharray: 3 7; }
.ghost { fill: none; stroke-width: 2.5; stroke-dasharray: 4 4; opacity: .7; }
.ghost.def { stroke: #9cc0ff; } .ghost.off { stroke: #ffa3a3; } .ghost.ball { stroke: #fff; }
.dot { opacity: .8; }
.dot.def { fill: #9cc0ff; } .dot.off { fill: #ffa3a3; } .dot.ball { fill: #fff; }

#status { position: absolute; left: 10px; top: 10px; right: 10px; pointer-events: none;
  font-size: 13px; color: #dfe9e2; text-shadow: 0 1px 2px #000; }
#toast { position: absolute; left: 50%; top: 34px; transform: translate(-50%, -10px); opacity: 0;
  background: rgba(10, 20, 14, .92); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px;
  transition: .25s; pointer-events: none; max-width: 90%; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  width: min(460px, 94vw); padding: 18px; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
dialog label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
dialog input[type=text] { width: 100%; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 14px 0; padding: 8px 12px 12px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
legend { color: var(--muted); font-size: 13px; padding: 0 4px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

@media (max-width: 560px) {
  header, footer, #stepsBar, #stepDetail { padding: 6px 8px; gap: 6px; }
  button, select, input[type=text] { padding: 0 9px; }
  label.inline .lbl { display: none; }
  footer { justify-content: center; }
  footer .spacer { flex-basis: 100%; height: 0; }
}

/* ---------- accounts & sync ---------- */
button.sync { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
button.sync i { width: 9px; height: 9px; border-radius: 50%; background: #5fbf75; flex: none; }
button.sync[data-state=saving] i { background: var(--accent); animation: pulse 1s infinite; }
button.sync[data-state=pending] i { background: var(--accent); }
button.sync[data-state=offline] i { background: #8a8f8c; }
button.sync[data-state=error] i { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
button.avatar { width: 40px; padding: 0; border-radius: 50%; font-weight: 700; background: #2a4a38; }

#authView { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% 30%, #23412e, var(--bg) 70%); overflow: auto; }
#authView[hidden] { display: none; }
body.locked > :not(#authView):not(script) { visibility: hidden; }
.card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; display: grid; gap: 12px; }
.card img { justify-self: center; border-radius: 14px; }
.card h1 { margin: 0; text-align: center; font-size: 22px; }
.card .hint { text-align: center; margin: 0; }
.card label, #pwForm label, .grid2 label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.card input, #pwForm input, .grid2 input, .grid2 select { width: 100%; }
input[type=password] { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; min-height: 40px; padding: 0 12px; }
.error { color: #ff9c9c; font-size: 13px; margin: 0; min-height: 1em; }
.error:empty { display: none; }
.notice { background: #233a2d; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px;
  margin: 12px 0 0; white-space: pre-line; user-select: text; }
.notice:empty { display: none; }
.stack { display: grid; gap: 8px; }
#pwForm { display: grid; gap: 10px; }
#pwForm h2 { margin: 0; }
dialog.wide { width: min(640px, 96vw); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.coach-list { display: grid; gap: 8px; max-height: 40vh; overflow: auto; }
.coach { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel2); }
.coach .who { flex: 1 1 180px; min-width: 0; }
.coach .who b { display: block; }
.coach .who small { color: var(--muted); }
.coach.inactive { opacity: .55; }
.coach button { min-height: 32px; font-size: 13px; padding: 0 9px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--line); color: var(--muted); }
.badge.admin { background: #4a3d16; color: var(--accent); }
@media (max-width: 560px) { button.sync span { display: none; } }

.narrow { display: none; }
@media (max-width: 560px) {
  .wide { display: none; }
  .narrow { display: inline; }
  header button { padding: 0 11px; }
  header { flex-wrap: wrap; }
  .pickers { flex: 1 1 100%; }
  .pickers select { flex: 1 1 0; width: 0; max-width: none; }
  #groupSelect { flex-grow: 0.8; }
  header > button { flex: none; }
}

#groupForm { display: grid; gap: 10px; }
#groupForm h2 { margin: 0; }
#groupForm label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
#groupForm input { width: 100%; }
#playDialog .grid2 select { width: 100%; }
