:root {
    --bg: #0a2015; --bg2: #0d2a1b; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #eefaf2; --muted: #a8c4b3; --accent: #3ddc84; --accent-ink: #04281a; --field: rgba(255,255,255,.08);
    --soft: rgba(61,220,132,.15); --err: #fca5a5; --out: #f87171; --out-ink: #2a0606; --x: #fbbf24; --x-ink: #2a1c02;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f1f7f3; --bg2: #e2efe6; --card: #fff; --line: #c7dacd; --ink: #0f2419; --muted: #4c6657;
            --accent: #15803d; --accent-ink: #fff; --field: #f2f8f4; --soft: #dcfce7; --err: #b91c1c; --out: #dc2626; --out-ink: #fff; --x: #b45309; --x-ink: #fff; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f1f7f3; --bg2: #e2efe6; --card: #fff; --line: #c7dacd; --ink: #0f2419; --muted: #4c6657;
            --accent: #15803d; --accent-ink: #fff; --field: #f2f8f4; --soft: #dcfce7; --err: #b91c1c; --out: #dc2626; --out-ink: #fff; --x: #b45309; --x-ink: #fff; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #0a2015; --bg2: #0d2a1b; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #eefaf2; --muted: #a8c4b3; --accent: #3ddc84; --accent-ink: #04281a; --field: rgba(255,255,255,.08);
    --soft: rgba(61,220,132,.15); --err: #fca5a5; --out: #f87171; --out-ink: #2a0606; --x: #fbbf24; --x-ink: #2a1c02;
    color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding: clamp(1rem,4vw,2.5rem) 1rem 5rem; display: flex; justify-content: center;
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
       background: linear-gradient(180deg, var(--bg), var(--bg2)) fixed; touch-action: manipulation; }
.app { width: min(540px, 100%); min-width: 0; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: clamp(1.5rem, 6vw, 1.9rem); line-height: 1.2; letter-spacing: -.02em; }
.sub { margin: .4rem 0 0; color: var(--muted); }
h2 { margin: 0 0 .6rem; font-size: 1.2rem; }
h3 { margin: 0 0 .4rem; font-size: 1.05rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label, .label { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); }
.label.tight { margin-top: .7rem; }
input[type=text] { width: 100%; min-width: 0; min-height: 48px; padding: .55rem .8rem; font: inherit; font-size: 1.05rem; color: var(--ink);
       background: var(--field); border: 1px solid var(--line); border-radius: 12px; }
input::placeholder { color: var(--muted); opacity: .8; }
input[aria-invalid="true"] { border-color: var(--err); }
input:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button { font: inherit; }
button:disabled { opacity: .45; cursor: default; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.seg button, .chip { min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 600; cursor: pointer; padding: .3rem .4rem; overflow-wrap: anywhere; line-height: 1.2; }
.seg button[aria-pressed="true"], .chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.four-seg { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .4rem; }
.hint { margin: .5rem 0; color: var(--muted); font-size: .92rem; }
.tight-hint { margin: .35rem 0 0; }
.field-err { margin: .3rem 0 0; color: var(--err); font-size: .9rem; font-weight: 600; }
.field-err:empty { display: none; }
.primary { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 52px; margin-top: .9rem; padding: .4rem .8rem; border: 0; border-radius: 12px;
           background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 1.05rem; cursor: pointer; text-align: center; }
.primary.alt { background: transparent; color: var(--ink); border: 1px solid var(--accent); }
.ghost { width: 100%; min-height: 46px; margin-top: .6rem; padding: .3rem .6rem; border-radius: 12px; border: 1px dashed var(--line); background: transparent; color: var(--ink); cursor: pointer; }
.ghost.danger { color: var(--err); }
.link { min-height: 40px; padding: 0 .2rem; border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; }
.small { min-height: 44px; padding: 0 .8rem; border-radius: 10px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font-size: .92rem; cursor: pointer; }
.muted { color: var(--muted); font-weight: 400; }

/* each team in its own bordered box */
.boxes { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; }
.tbox { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; padding: .2rem .9rem .9rem; background: var(--field); min-width: 0; }
.tbox input[type=text] { background: var(--card); }
.stepper { display: grid; grid-template-columns: 52px minmax(0, 5rem) 52px; gap: .4rem; align-items: center; }
.step { min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 1.4rem; font-weight: 700; cursor: pointer; }
.step-val { text-align: center; font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.names-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
.names-grid input[type=text] { min-height: 44px; font-size: 1rem; padding: .4rem .6rem; }
.rules-box { margin-top: 1.1rem; border: 1px solid var(--line); border-radius: 12px; padding: .8rem .9rem .9rem; }
.rules-box .label:first-of-type { margin-top: .4rem; }

/* scoreboard */
.board { text-align: center; }
.big-label { margin: 0; text-transform: uppercase; letter-spacing: .07em; font-size: .78rem; font-weight: 700; color: var(--muted); }
.score { margin: .2rem 0 0; font-size: clamp(1.25rem, 5.5vw, 1.6rem); line-height: 1.2; overflow-wrap: anywhere; }
.runs { display: block; font-size: clamp(2.8rem, 15vw, 3.8rem); font-weight: 800; letter-spacing: -.02em; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
.overs { margin: .2rem 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.chase { margin: .6rem 0 0; padding: .55rem .7rem; border-radius: 12px; background: var(--soft); font-weight: 800; font-size: 1.15rem; overflow-wrap: anywhere; }
.rates { margin: .4rem 0 0; color: var(--muted); font-size: .92rem; font-variant-numeric: tabular-nums; }
.at-crease { list-style: none; margin: .8rem 0 0; padding: 0; display: grid; gap: .3rem; text-align: left; }
.at-crease li { display: flex; justify-content: space-between; gap: .6rem; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--field); min-width: 0; }
.at-crease li.on-strike { border-color: var(--accent); }
.cname { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.cfig { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.bowling { margin: .4rem 0 0; color: var(--muted); font-size: .92rem; text-align: left; overflow-wrap: anywhere; }
.over-balls { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem; }
.ball { min-width: 2.4rem; height: 2.4rem; padding: 0 .4rem; display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; border: 1px solid var(--line); background: var(--field); font-weight: 700; font-size: .92rem; font-variant-numeric: tabular-nums; }
.ball.b4, .ball.b6 { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ball.w { background: var(--out); color: var(--out-ink); border-color: var(--out); }
.ball.x { border-color: var(--x); color: var(--x); }
.over-balls .empty { color: var(--muted); font-size: .92rem; min-height: 2.4rem; display: flex; align-items: center; }

/* the scoring buttons */
.pad-title { font-size: 1rem; color: var(--muted); margin-bottom: .5rem; }
.pad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .45rem; }
.pad button { min-height: 60px; padding: .2rem; border-radius: 14px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 800; cursor: pointer; line-height: 1.1; overflow-wrap: anywhere; }
.pad .run { font-size: 1.6rem; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.pad .run small { font-size: .72rem; font-weight: 600; color: var(--muted); }
.pad .four, .pad .six { border-color: var(--accent); }
.pad .ext { font-size: .98rem; color: var(--x); border-color: var(--x); }
.pad .out-btn { font-size: 1.1rem; background: var(--out); color: var(--out-ink); border-color: var(--out); }
.pad .undo { font-size: .98rem; border-style: dashed; }
.pad button[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: 1px; }
.small-pad button { min-height: 52px; }
.pad.how { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pad.how button { min-height: 50px; font-size: 1rem; font-weight: 700; color: var(--ink); border-color: var(--line); }
.sub-panel { margin-top: .8rem; padding: .8rem; border: 2px solid var(--x); border-radius: 14px; }
#out-panel { border-color: var(--out); }
.panel-q { margin: 0 0 .6rem; font-weight: 700; }
.out-save { background: var(--out); color: var(--out-ink); }
.more { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .5rem; }
.more summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; color: var(--muted); }
.more-body { padding-top: .2rem; }
.two-btn { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .4rem; }
.inline { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
#names-panel { margin-top: .8rem; }

/* choosing a batter or bowler */
.pick-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; }
.pick-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 56px; padding: .3rem .5rem; border-radius: 12px; border: 1px solid var(--accent); background: var(--field); color: var(--ink); cursor: pointer; min-width: 0; }
.pk-name { font-weight: 700; overflow-wrap: anywhere; text-align: center; }
.pick-btn small { color: var(--muted); font-size: .8rem; }
#pick details { margin-top: .7rem; }
#pick summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
#pick .pick-list .hint { grid-column: 1 / -1; }

/* innings break and result */
.result { text-align: center; }
.headline { margin: .2rem 0 0; font-size: clamp(1.5rem, 7vw, 2.1rem); font-weight: 800; line-height: 1.2; color: var(--accent); overflow-wrap: anywhere; }
.subline { margin: .4rem 0 .4rem; overflow-wrap: anywhere; }
.share { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.share > * { margin-top: .9rem; }
.share:has(> [hidden]) { grid-template-columns: 1fr; }

/* scorecard */
.sc-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.sc-head h2 { margin: 0; }
.inn-box { margin-top: .8rem; padding: .8rem .9rem; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; background: var(--field); min-width: 0; }
.inn-box h3 { overflow-wrap: anywhere; }
.sc-line { margin: .4rem 0 0; font-size: .92rem; color: var(--muted); overflow-wrap: anywhere; }
.scroll { max-width: 100%; overflow-x: auto; margin-top: .4rem; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: .35rem .4rem; text-align: right; border-bottom: 1px solid var(--line); }
thead th { color: var(--muted); font-size: .82rem; }
th:first-child { text-align: left; }
tbody th { font-weight: 400; }
tbody th .nm { display: block; font-weight: 700; overflow-wrap: anywhere; }
tbody th small { display: block; color: var(--muted); font-size: .8rem; }
.over-sum { list-style: none; margin: .6rem 0 0; padding: 0; display: grid; gap: .2rem; font-size: .92rem; }
.over-sum li { overflow-wrap: anywhere; }

/* past matches */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.hbox { border: 1px solid var(--line); border-radius: 12px; padding: .6rem .8rem; background: var(--field); }
.hbox p { margin: 0; overflow-wrap: anywhere; }
.h-title { font-weight: 700; }
.h-win { color: var(--accent); font-weight: 700; }
.h-meta { color: var(--muted); font-size: .9rem; }

.toast { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 2rem); z-index: 5;
         padding: .6rem 1rem; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.toast .link { color: var(--bg); text-decoration: underline; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: -1px; }
.faq h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
.faq details { border-top: 1px solid var(--line); padding: .6rem 0; }
.faq summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.faq details p { margin: .4rem 0 0; color: var(--muted); }
footer { text-align: center; margin-top: 1.5rem; font-size: .9rem; } footer a { color: var(--muted); }
.warn { margin: .9rem 0 0; text-align: left; padding: .7rem .9rem; border: 1px solid var(--err); border-radius: 12px; color: var(--err); font-weight: 600; }
[hidden] { display: none !important; }
@media (max-width: 345px) {
    body { padding-left: .6rem; padding-right: .6rem; }
    .theme-toggle { padding: 0 .65rem !important; }
    .card { padding: .9rem .8rem; }
    .pad { gap: .35rem; }
    .pad .ext, .pad .undo { font-size: .86rem; }
    .names-grid, .two-btn { grid-template-columns: 1fr; }
}

/* phones while playing: keep the scoring buttons close to the score */
@media (max-width: 899px) {
    .playing header .sub { display: none; }
    .playing header { margin-bottom: .8rem; }
    .board { padding: .8rem .9rem .9rem; }
    .board .runs { font-size: clamp(2.5rem, 12vw, 3.2rem); }
    .board .chase { margin-top: .45rem; padding: .45rem .6rem; }
    .board .at-crease { margin-top: .55rem; }
    .board .at-crease li { padding: .3rem .6rem; }
}

/* back to the list of all apps */
.back { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; margin: 0 0 .5rem; padding: 0 1rem 0 .8rem; border: 1px solid var(--line, rgba(127,127,127,.4)); border-radius: 999px; color: var(--muted, var(--mut, inherit)); font-size: .92rem; font-weight: 600; text-decoration: none; background: transparent; }
.back:hover { color: var(--ink, inherit); border-color: currentColor; }
.back:focus-visible { outline: 3px solid var(--accent, var(--acc, #fff)); outline-offset: 2px; }
@media print { .back, .toast, #pad, #pick { display: none; } }

/* laptops and desktops: scoring on the left, scorecard on the right */
@media (min-width: 900px) {
    .app { width: min(1120px, 100%); }
    header h1 { font-size: 2.3rem; }
    #setup { width: min(760px, 100%); margin-left: auto; margin-right: auto; }
    #team-boxes { grid-template-columns: 1fr 1fr; align-items: start; }
    .play-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
    .col-main, .col-side { min-width: 0; }
    .pad button { min-height: 66px; }
    #history-card, .faq, footer { width: min(760px, 100%); margin-left: auto; margin-right: auto; }
}
