:root {
  --bg: #0f172a; --panel: #111c33; --panel2: #18243f; --line: #24324f; --text: #e5e7eb; --muted: #94a3b8;
  --pri: #2563eb; --gold: #fbbf24; --red: #dc2626; --green: #16a34a;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
a { color: inherit; }
h1 { font-size: 24px; margin: 0 0 12px; } h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
kbd { font: 10px/1 monospace; opacity: .55; border: 1px solid currentColor; border-radius: 3px; padding: 2px 3px; margin-left: 4px; vertical-align: middle; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: #0b1222; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 17px; text-decoration: none; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { background: none; border: 0; color: var(--muted); padding: 8px 12px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--panel2); color: #fff; }
.sync { font-size: 18px; } .sync.ok { color: var(--green); } .sync.busy { color: var(--gold); } .sync.err { color: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.wrap { max-width: 1100px; margin: 0 auto; padding: 18px 16px; } .wrap.narrow { max-width: 760px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.row { display: flex; align-items: center; } .between { justify-content: space-between; } .gap { gap: 8px; } .wrapx { flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; } .span2 { grid-column: span 2; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.chk { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
input, textarea, select { width: 100%; background: #0b1222; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font: inherit; margin-top: 4px; }
input[type=checkbox] { width: 18px; height: 18px; margin: 0; }
input[type=color] { height: 40px; padding: 3px; }
input[type=file] { font-size: 12px; }
textarea { font-family: ui-monospace, monospace; font-size: 14px; }
.logo-prev { max-height: 60px; margin-top: 4px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { filter: brightness(1.2); }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.ghost { background: transparent; } .btn.danger { color: #f87171; }
.btn.sm { padding: 5px 9px; font-size: 13px; } .btn.big { width: 100%; padding: 13px; font-size: 17px; }

/* Home */
.login { display: flex; justify-content: center; padding: 60px 16px; }
.login .card { width: 100%; max-width: 360px; text-align: center; }
.pin { font-size: 26px; text-align: center; letter-spacing: 8px; margin: 10px 0 12px; }
.err { color: #f87171; margin-bottom: 10px; }
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.game .gtitle { font-weight: 600; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; }
.game .gscore { font-size: 24px; display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.game .row { margin-top: 10px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--panel2); color: var(--muted); font-weight: 500; white-space: nowrap; }
.tag.live { background: var(--red); color: #fff; } .tag.final { background: var(--gold); color: #111; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 5px; font-weight: 700; font-size: 13px; letter-spacing: 1px; }
.empty { text-align: center; padding: 40px; color: var(--muted); }

/* Control */
.tab { display: none; } .tab.on { display: block; }
.cgrid { display: grid; grid-template-columns: 380px 1fr; gap: 14px; padding: 14px; max-width: 1400px; margin: 0 auto; }
.sb { display: flex; gap: 12px; padding: 10px; }
.sb-teams { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.sb-team { display: flex; align-items: center; background: var(--tc); color: var(--tt); border-radius: 8px; padding: 8px 10px; position: relative; }
.sb-team.bat { box-shadow: inset 5px 0 0 var(--gold); }
.sb-name { flex: 1; font-weight: 700; font-size: 18px; letter-spacing: 1px; display: flex; align-items: center; gap: 6px; }
.sb-name img { height: 24px; }
.sb-r { font-size: 30px; font-weight: 800; min-width: 40px; text-align: right; }
.sb-he { font-size: 11px; opacity: .8; margin-left: 8px; width: 54px; white-space: pre; }
.sb-mid { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 120px; }
.sb-inning { font-size: 20px; font-weight: 700; color: var(--gold); }
.diamond { width: 110px; cursor: pointer; }
.diamond .base { fill: #0b1222; stroke: #64748b; stroke-width: 2.5; transition: fill .2s; }
.diamond .base:hover { stroke: #fff; }
.diamond .base.on { fill: var(--gold); stroke: var(--gold); }
.sb-count { display: flex; gap: 10px; align-items: center; font-size: 20px; font-weight: 700; }
.outs { display: inline-flex; gap: 4px; }
.outs i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #64748b; display: inline-block; }
.outs i.on { background: var(--red); border-color: var(--red); }

.who-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.who-row:last-child { border: 0; }
.who-row .lbl { width: 50px; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.who-row .val { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.who-row .mini { display: flex; gap: 4px; }

table.line { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 6px; }
table.line th, table.line td { text-align: center; padding: 5px 2px; border-bottom: 1px solid var(--line); }
table.line th { color: var(--muted); font-weight: 500; } table.line th.cur { color: var(--gold); }
table.line td.ed { cursor: pointer; } table.line td.ed:hover { background: var(--panel2); }
table.line td.tot { font-weight: 800; color: var(--gold); }
table.line td.tn { text-align: left; }

.group { margin-bottom: 12px; }
.glabel { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 6px; }
.btns { display: grid; gap: 8px; }
.b3 { grid-template-columns: repeat(3, 1fr); } .b4 { grid-template-columns: repeat(4, 1fr); } .b6 { grid-template-columns: repeat(6, 1fr); }
.btns.small .btn { padding: 8px 4px; font-size: 13px; white-space: normal; text-align: center; }
.act { border: 0; border-radius: 10px; padding: 14px 6px; font: 600 16px/1.15 system-ui, sans-serif; color: #fff; cursor: pointer; transition: transform .06s, filter .1s; user-select: none; -webkit-tap-highlight-color: transparent; }
.act:active { transform: scale(.96); }
.act:hover { filter: brightness(1.15); }
.act.ball { background: #16a34a; padding: 22px 6px; font-size: 20px; }
.act.strike { background: #dc2626; padding: 22px 6px; font-size: 20px; }
.act.foul { background: #ea580c; padding: 22px 6px; font-size: 20px; }
.act.hit { background: #2563eb; } .act.hr { background: #7c3aed; }
.act.safe { background: #0e7490; } .act.out { background: #475569; } .act.run { background: #a16207; }
.flash { animation: fl .35s; }
@keyframes fl { 0% { box-shadow: 0 0 0 0 rgba(251,191,36,.9); } 100% { box-shadow: 0 0 0 10px rgba(251,191,36,0); } }
.undo { width: 100%; padding: 14px; border-radius: 10px; border: 2px dashed var(--line); background: transparent; color: var(--text); font: 600 16px system-ui, sans-serif; cursor: pointer; }
.undo:disabled { opacity: .4; cursor: default; }
.is-final .act { opacity: .45; }

.log { margin: 0; padding-left: 0; list-style: none; max-height: 70vh; overflow: auto; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.quick { margin-top: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #f8fafc; color: #0f172a; padding: 10px 18px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; }
.toast.on { opacity: 1; transform: translateX(-50%); }

@media (max-width: 900px) {
  .cgrid { grid-template-columns: 1fr; padding: 10px; }
  .b6 { grid-template-columns: repeat(3, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  kbd { display: none; }
}
@media (max-width: 480px) { .b4 { grid-template-columns: repeat(2, 1fr); } .tabs button { padding: 8px 8px; } }
