/* The Dugout — big text, high contrast, readable in direct sun. */
:root {
  --bg: #f4f1e8;
  --surface: #ffffff;
  --surface-2: #ebe6d8;
  --ink: #111111;
  --ink-2: #3d3d3d;
  --line: #c9c2ae;
  --brand: #0f3d2e;
  --brand-ink: #ffffff;
  --accent: #c8102e;
  --good: #1d6b3a;
  --warn: #9a5b00;
  --warn-bg: #fff1d6;
  --bad: #b00020;
  --bad-bg: #ffe3e6;
  --focus: #1f5fd1;
  --radius: 14px;
  --fs: 19px;
  font-size: var(--fs);
  color-scheme: light;
}
:root[data-size="xl"] { --fs: 22px; }
:root[data-size="normal"] { --fs: 17px; }

:root[data-theme="dark"] {
  --bg: #0d1412;
  --surface: #17211e;
  --surface-2: #22302b;
  --ink: #f5f5f0;
  --ink-2: #c8cec9;
  --line: #3a4a44;
  --brand: #1d6b4f;
  --brand-ink: #ffffff;
  --accent: #ff5a6e;
  --good: #5fd18b;
  --warn: #ffbf47;
  --warn-bg: #3a2c0f;
  --bad: #ff6b7d;
  --bad-bg: #3d1419;
  --focus: #7aa7ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.35;
  min-height: 100vh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--brand); color: var(--brand-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; }
.team-name { font-weight: 700; opacity: .9; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }

/* Bottom tabs */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 2px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none; border: 0; padding: 10px 4px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .85rem; font-weight: 700; color: var(--ink-2); cursor: pointer;
  min-height: 64px;
}
.tabs .ti { font-size: 1.45rem; line-height: 1; }
.tabs button.on { color: var(--brand); box-shadow: inset 0 4px 0 var(--brand); }
:root[data-theme="dark"] .tabs button.on { color: var(--good); box-shadow: inset 0 4px 0 var(--good); }

/* Layout */
.view { max-width: 760px; margin: 0 auto; padding: 16px; outline: none; }
h1 { font-size: 1.5rem; margin: 4px 0 12px; }
h2 { font-size: 1.2rem; margin: 22px 0 10px; }
h3 { font-size: 1.05rem; margin: 16px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { text-align: center; }

.card {
  background: var(--surface); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.card + .card { margin-top: 12px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 18px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.big { min-height: 64px; font-size: 1.15rem; width: 100%; }
.btn.block { width: 100%; }
.btn.icon { min-width: 52px; padding: 8px; font-size: 1.2rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }

/* Forms */
label.field { display: block; font-weight: 700; margin: 12px 0 6px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; min-height: 52px; padding: 10px 12px;
  border: 2px solid var(--line); border-radius: 12px; background: var(--surface);
}
textarea { min-height: 80px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 52px; font-weight: 600; cursor: pointer; }
.check input { width: 28px; height: 28px; accent-color: var(--brand); flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; min-width: 52px; padding: 6px 12px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer;
}
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* Segmented control */
.seg { display: flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; min-height: 50px; border: 0; background: var(--surface); font-weight: 700; cursor: pointer; }
.seg button + button { border-left: 2px solid var(--line); }
.seg button.on { background: var(--brand); color: var(--brand-ink); }

/* Player list */
.plist { list-style: none; margin: 0; padding: 0; }
.plist li {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 12px;
  padding: 8px 10px; margin-bottom: 8px; min-height: 60px;
}
.plist li.out { opacity: .5; }
.num {
  flex: none; min-width: 46px; height: 46px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 800;
  background: var(--surface-2); padding: 0 6px;
}
.pname { font-weight: 800; font-size: 1.05rem; }
.pmeta { font-size: .82rem; color: var(--ink-2); }
.here-toggle {
  flex: none; min-width: 96px; min-height: 48px; border-radius: 10px; font-weight: 800; cursor: pointer;
  border: 2px solid var(--good); background: var(--surface); color: var(--good);
}
.here-toggle.on { background: var(--good); color: #fff; }
:root[data-theme="dark"] .here-toggle.on { color: #0d1412; }

.order-num { flex: none; width: 34px; text-align: center; font-weight: 900; font-size: 1.2rem; }

/* Notices */
.notice { border-radius: 12px; padding: 10px 12px; font-weight: 600; margin: 8px 0; border: 2px solid; }
.notice.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--ink); }
.notice.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--ink); }
.notice.good { border-color: var(--good); }
.notice ul { margin: 4px 0 0; padding-left: 20px; }

/* Defense grid */
.inning-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
.inning-tabs button {
  flex: none; min-width: 52px; min-height: 52px; border-radius: 12px; font-weight: 800; cursor: pointer;
  border: 2px solid var(--line); background: var(--surface);
}
.inning-tabs button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.inning-tabs button.has-warn { border-color: var(--warn); }
.pos-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.pos-row { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center; }
.pos-tag { font-weight: 900; text-align: center; background: var(--surface-2); border-radius: 10px; padding: 12px 4px; }
.pos-row select.dup { border-color: var(--bad); background: var(--bad-bg); }
.bench { margin-top: 10px; }

/* Field diagram */
.field-wrap { width: 100%; max-width: 520px; margin: 0 auto; }
.field-wrap svg { width: 100%; height: auto; display: block; }

/* Game board */
.scoreboard {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: stretch;
  background: var(--brand); color: var(--brand-ink); border-radius: var(--radius); padding: 12px;
}
.sb-team { text-align: center; }
.sb-team .lbl { font-size: .8rem; font-weight: 700; opacity: .85; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-team .runs { font-size: 3rem; font-weight: 900; line-height: 1; margin: 4px 0; font-variant-numeric: tabular-nums; }
.sb-team .adj { display: flex; justify-content: center; gap: 6px; }
.sb-team .adj button { min-width: 48px; min-height: 44px; border-radius: 10px; border: 2px solid rgba(255,255,255,.5); background: rgba(255,255,255,.12); color: #fff; font-weight: 900; font-size: 1.2rem; cursor: pointer; }
.sb-mid { text-align: center; display: flex; flex-direction: column; justify-content: center; min-width: 88px; }
.sb-mid .inn { font-size: 1.6rem; font-weight: 900; }
.sb-mid .half { font-weight: 700; font-size: .9rem; opacity: .9; }

.status-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.stat { background: var(--surface); border: 2px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.stat .lbl { font-size: .75rem; font-weight: 800; text-transform: uppercase; color: var(--ink-2); letter-spacing: .04em; }
.stat .val { font-size: 1.6rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat.warn { border-color: var(--warn); background: var(--warn-bg); }
.stat.bad { border-color: var(--bad); background: var(--bad-bg); }
.outs-dots { display: flex; justify-content: center; gap: 6px; margin-top: 4px; }
.outs-dots span { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--ink); }
.outs-dots span.on { background: var(--accent); border-color: var(--accent); }

.hitters { margin-top: 12px; display: grid; gap: 8px; }
.hitter { display: flex; align-items: center; gap: 12px; border-radius: var(--radius); padding: 12px 14px; border: 2px solid var(--line); background: var(--surface); }
.hitter .slot { font-size: .78rem; font-weight: 900; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); width: 74px; flex: none; }
.hitter .who { font-weight: 900; font-size: 1.25rem; }
.hitter .who .n { color: var(--ink-2); font-weight: 800; margin-right: 6px; }
.hitter.up { border-color: var(--accent); border-width: 3px; }
.hitter.up .who { font-size: 1.8rem; }
.hitter .tag { margin-left: auto; font-size: .75rem; font-weight: 800; padding: 4px 8px; border-radius: 999px; background: var(--warn-bg); border: 2px solid var(--warn); white-space: nowrap; }

.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.big-actions .wide { grid-column: 1 / -1; }

.log { list-style: none; padding: 0; margin: 0; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--line); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg); color: var(--ink); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .modal { align-items: center; } .modal-card { border-radius: 18px; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--ink); color: var(--bg); font-weight: 700; padding: 12px 18px; border-radius: 12px;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

.empty { text-align: center; padding: 28px 12px; color: var(--ink-2); }
.empty .big { font-size: 2.4rem; }

.lock-badge { display: inline-block; font-size: .78rem; font-weight: 800; padding: 3px 10px; border-radius: 999px; border: 2px solid var(--warn); background: var(--warn-bg); }
.ok-badge { display: inline-block; font-size: .78rem; font-weight: 800; padding: 3px 10px; border-radius: 999px; border: 2px solid var(--good); color: var(--good); }

/* Print */
.print-area { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; font-size: 12pt; }
  .topbar, .tabs, .view, .modal, .toast { display: none !important; }
  .print-area { display: block; padding: 0.3in; }
  .print-area h1 { font-size: 20pt; margin: 0 0 4pt; }
  .print-area .sub { margin: 0 0 12pt; font-size: 11pt; }
  .print-area table { width: 100%; border-collapse: collapse; margin-bottom: 14pt; }
  .print-area th, .print-area td { border: 1px solid #000; padding: 5pt 6pt; text-align: left; font-size: 11pt; }
  .print-area th { background: #e8e8e8; }
  .print-area td.c, .print-area th.c { text-align: center; }
  .print-area .page-break { page-break-before: always; }
}
