/* ElScoreKam styles. Plain CSS, no CDN: the app must load on a court with bad signal. */
:root {
  --bg: #070b14;
  --text: #f4f7ff;
  --muted: #93a0bd;
  --line: #2a3552;
  --surface: #141d33;
  --radius: 22px;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: clamp(1rem, 2.4vmin, 1.5rem); }
#matchInfo { color: var(--muted); font-weight: 700; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn {
  min-height: 46px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-family: inherit; font-weight: 700; font-size: 1rem; cursor: pointer;
}
.btn:hover { background: #1b2646; }
.btn:active { transform: scale(.97); }
.btn:focus-visible, .name:focus-visible { outline: 3px solid #ffd24a; outline-offset: 2px; }
.btn.icon { min-width: 46px; padding: 0 12px; }
#conn { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; font-weight: 700; }
#conn i { width: 10px; height: 10px; border-radius: 50%; background: #6b7690; }
#conn[data-s="on"] i { background: #35d07f; box-shadow: 0 0 8px #35d07f; }
#conn[data-s="retry"] i { background: #ffb020; }
#conn[data-s="badkey"] i { background: #ff4d4d; }
#conn[data-s="badkey"] { color: #ff8a8a; }

/* ---------- board ---------- */
.board { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-height: 0; }
@media (orientation: portrait) and (max-width: 900px) {
  .board { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}
.team {
  --c: #888;
  position: relative; min-height: 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: clamp(10px, 2vh, 22px);
  border-radius: var(--radius);
  border: 6px solid color-mix(in srgb, var(--c) 40%, #0b1020);
  background: radial-gradient(120% 90% at 50% 0%,
    color-mix(in srgb, var(--c) 38%, #0b1020),
    color-mix(in srgb, var(--c) 12%, #070b14));
  transition: border-color .2s, box-shadow .2s;
}
.team.serving {
  border-color: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 50%, transparent),
              0 0 44px color-mix(in srgb, var(--c) 55%, transparent);
}
.team.won { border-color: #ffd24a; box-shadow: 0 0 50px rgba(255, 210, 74, .45); }
.head { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.name {
  width: 100%; min-width: 0; text-align: center;
  background: transparent; border: 0; color: inherit; border-radius: 10px;
  font-family: inherit; font-weight: 800; font-size: clamp(1.5rem, 5vmin, 3.4rem); line-height: 1.1;
  text-transform: uppercase; letter-spacing: .04em;
}
.role { color: rgba(255,255,255,.65); font-weight: 700; letter-spacing: .2em; font-size: clamp(.75rem, 1.8vmin, 1rem); }
.sets { display: flex; align-items: center; gap: 8px; margin-top: 6px;
        color: rgba(255,255,255,.7); font-weight: 800; letter-spacing: .14em; font-size: clamp(.8rem, 2vmin, 1.1rem); }
.pip { width: clamp(16px, 3.4vmin, 30px); aspect-ratio: 1; border-radius: 50%; border: 3px solid rgba(255,255,255,.55); }
.pip.on { background: #fff; border-color: #fff; }
.score {
  font-weight: 900; line-height: .85; font-variant-numeric: tabular-nums;
  font-size: min(38vh, 28vw);
  text-shadow: 0 6px 30px rgba(0,0,0,.4);
}
@media (orientation: portrait) and (max-width: 900px) {
  .board { grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .team { padding: 8px; border-width: 4px; overflow: hidden; }
  .score { font-size: min(14vh, 36vw); }
  .role { display: none; }
  .head { gap: 0; }
  .sets { margin-top: 2px; }
  .chip { min-height: 36px; padding: 0 12px; }
  .adj .btn { min-height: 46px; }
  .btn { min-height: 40px; padding: 0 12px; }
  .btn.icon { min-width: 40px; }
}
.score.bump { animation: bump .25s ease-out; }
@keyframes bump { 40% { transform: scale(1.1); } }
@media (prefers-reduced-motion: reduce) { .score.bump { animation: none; } }
.meta { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 2px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.28); color: #fff; font-family: inherit; font-weight: 800; letter-spacing: .08em;
  font-size: clamp(.85rem, 2.2vmin, 1.2rem); cursor: pointer;
}
.chip.serve-on { background: #fff; color: #10172b; border-color: #fff; }
.chip.dim { opacity: .55; }
.adj { display: flex; gap: 12px; width: 100%; justify-content: center; }
.adj .btn { min-height: clamp(56px, 9vh, 84px); font-size: clamp(1.3rem, 3.4vmin, 2.2rem); border-radius: 18px; }
.adj .minus { flex: 1; max-width: 160px; }
.adj .plus { flex: 2; max-width: 320px; background: rgba(255,255,255,.92); color: #0b1020; border-color: #fff; }
.adj .plus:hover { background: #fff; }

/* ---------- history ---------- */
.history { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-height: 36px; color: var(--muted); font-weight: 700; }
.hist { padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 2px solid var(--line); color: var(--text); }

/* ---------- overlay / toast ---------- */
#overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
           background: rgba(4, 8, 16, .6); backdrop-filter: blur(3px); }
#overlay[hidden] { display: none; }
.card { width: min(640px, 100%); text-align: center; padding: clamp(18px, 4vmin, 40px);
        border-radius: 28px; background: #101830; border: 2px solid var(--line); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.ov-title { font-weight: 900; font-size: clamp(1.6rem, 5vmin, 3rem); text-transform: uppercase; letter-spacing: .03em; }
.ov-score { font-weight: 900; font-size: clamp(2.4rem, 9vmin, 5.5rem); margin: 10px 0; font-variant-numeric: tabular-nums; }
.ov-sub { color: var(--muted); font-weight: 700; margin-bottom: 18px; }
.ov-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.ov-actions .btn { min-height: 64px; font-size: 1.3rem; padding: 0 28px; }
.btn.primary { background: #fff; color: #0b1020; border-color: #fff; }
.btn.primary:hover { background: #e8eefc; }
.ov-hint { margin-top: 16px; color: var(--muted); font-size: .9rem; }

#toast { position: fixed; left: 50%; bottom: 70px; transform: translate(-50%, 20px); opacity: 0; z-index: 30; pointer-events: none;
         padding: 12px 20px; border-radius: 999px; background: #fff; color: #0b1020; font-weight: 800;
         transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- dialogs ---------- */
dialog { margin: auto; width: min(600px, 94vw); max-height: 92dvh; overflow: auto;
         background: #101830; color: var(--text); border: 1px solid var(--line); border-radius: 22px; padding: 22px;
         -webkit-user-select: text; user-select: text; }
dialog::backdrop { background: rgba(0, 0, 0, .65); }
dialog h2 { font-size: 1.4rem; margin-bottom: 14px; }
dialog h3 { font-size: 1rem; margin: 18px 0 8px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
label.f { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: .9rem; color: var(--muted); }
label.chk { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 8px 0; }
label.chk input { width: 22px; height: 22px; }
input[type=text], input[type=number], select {
  min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: #0a1124; color: var(--text);
  font-family: inherit; font-size: 1rem; padding: 0 12px;
}
input[type=color] { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; background: #0a1124; padding: 4px; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
td, th { text-align: start; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
kbd { padding: 2px 8px; border-radius: 6px; background: #0a1124; border: 1px solid var(--line); font-family: ui-monospace, Menlo, monospace; font-weight: 700; }
code { font-family: ui-monospace, Menlo, monospace; font-size: .88rem; color: #bcd0ff; }
.note { color: var(--muted); font-size: .9rem; line-height: 1.4; margin-bottom: 8px; }
.keyrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; font-weight: 700; }
.keyrow .btn { min-width: min(190px, 50%); }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ---------- view-only screens (?view) ---------- */
body.viewer .adj, body.viewer #btnUndo, body.viewer #btnSwap, body.viewer #btnSettings, body.viewer .ov-actions, body.viewer .ov-hint { display: none; }
body.viewer .chip, body.viewer .name { pointer-events: none; }

/* ---------- new-match setup screen ---------- */
#setup { position: fixed; inset: 0; z-index: 40; overflow: auto; background: var(--bg);
         padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
#setup[hidden] { display: none; }
.setup-card { width: min(720px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.setup-card h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); font-weight: 900; display: flex; align-items: center; gap: 10px; }
.setup-card h1 small { font-size: .9rem; color: var(--muted); font-weight: 700; }
.setup-card h3 { font-size: .85rem; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; margin-top: 6px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg label { flex: 1; min-width: 120px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; padding: 0 14px;
            border-radius: 16px; border: 2px solid var(--line); background: var(--surface); font-weight: 800; font-size: 1.05rem; cursor: pointer; }
.seg input:checked + span { background: #fff; color: #0b1020; border-color: #fff; }
.seg input:focus-visible + span { outline: 3px solid #ffd24a; outline-offset: 2px; }
.seg input:disabled + span { opacity: .45; cursor: not-allowed; }
.team-row { display: grid; grid-template-columns: minmax(0, 1fr) 56px; gap: 8px; min-width: 0; }
.team-row input[type=color] { min-height: 44px; }
#btnStart { min-height: 64px; font-size: 1.3rem; margin-top: 6px; }

/* ---------- point log ---------- */
.log { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }
.log li { display: grid; grid-template-columns: 5.5em 1fr auto; gap: 10px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.log time { color: var(--muted); }
.log .via { color: var(--muted); font-size: .85rem; }
.log .after { font-weight: 800; }
.log li.undo { color: #ffb020; }
.log-empty { color: var(--muted); padding: 12px 0; }
.team-row input[type=text] { width: 100%; min-width: 0; }
@media (max-width: 520px) { #setup .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .actions .btn > span { display: none; } .actions { gap: 6px; } }
.sport-fields { display: flex; flex-direction: column; gap: 12px; }
.sport-fields[hidden] { display: none; }

/* ---------- padel board extras ---------- */
.games { display: none; font-weight: 900; letter-spacing: .08em; color: rgba(255,255,255,.85);
         font-size: clamp(1rem, 3.4vmin, 2rem); font-variant-numeric: tabular-nums; }
body.padel .games { display: block; }
.games b { font-size: 1.6em; color: #fff; margin-inline-start: 6px; }
.adj .minus[hidden] { display: none; }
.badge { display: inline-block; margin-inline-start: 8px; padding: 2px 10px; border-radius: 999px; background: #ffd24a; color: #0b1020;
         font-weight: 900; letter-spacing: .04em; }
