:root {
    --ink: #111;
    --muted: #6b6b6b;
    --rule: #9a9a9a;
    --bg: #ecebe7;
    --paper: #fff;
    --accent: #1d5c3a;
    --win: #e3f1e6;
    --loss: #fbdcdc;
    --level: #fbf0bf;
    --bad: #ffd29a;
    --b: 2px solid var(--ink);
    --rh: 34px;   /* one singles row; a pairs game is two */
    --th: 46px;   /* totals row */
    --sc: 2.7rem; /* score column */
    color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.35 "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, sans-serif;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}
a { color: var(--accent); }
h1 { font-size: 1.25rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: #a11; }

/* ---- chrome ---- */
.topnav { display: flex; align-items: center; gap: 1rem; max-width: 1000px; margin: 0 auto; height: 44px; }
.topnav a { text-decoration: none; color: var(--ink); font-weight: 600; }
.topnav a.on { color: var(--accent); text-decoration: underline; text-underline-offset: 4px; }
.topnav .brand { font-weight: 800; margin-right: auto; }
.topnav form { margin: 0; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.flash { max-width: 1000px; margin: 0 auto 8px; background: var(--win); border-radius: 6px; padding: 6px 12px; font-weight: 600; }
main { max-width: 1000px; margin: 0 auto 24px; }
.card { background: var(--paper); border-radius: 8px; padding: 16px; box-shadow: 0 1px 3px rgb(0 0 0 / .1); }
.card.narrow { max-width: 480px; margin: 24px auto; }
.card label { display: block; margin-bottom: 10px; font-weight: 600; }
.card input { display: block; width: 100%; font: inherit; padding: 8px 10px; border: 1px solid #bbb; border-radius: 6px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; min-width: 0; }
.spread { justify-content: space-between; }
.btn {
    display: inline-block; font: inherit; font-weight: 700; padding: 8px 14px; border-radius: 6px; border: 0;
    background: var(--accent); color: #fff; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn.ghost { background: #e6e6e1; color: var(--ink); }
.btn.danger { background: #f3dada; color: #8a1414; }
.players { list-style: none; padding: 0; margin: 12px 0; }
.players li { margin-bottom: 6px; }

.sheet-list { list-style: none; padding: 0; margin: 0; }
.sheet-list a {
    display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 4px;
    border-bottom: 1px solid #e3e3e3; text-decoration: none; color: var(--ink);
}
.sheet-list .when { color: var(--muted); font-size: .85rem; }
.sheet-list .teams { grid-column: 1; font-weight: 600; }
.sheet-list .tag { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: .8rem; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; background: #eee; }
.sheet-list .tag.won { background: var(--win); color: var(--accent); }
.sheet-list .tag.lost { background: var(--loss); color: #8a1414; }

/* ---- the paper sheet ---- */
.paper { background: var(--paper); padding: 14px 16px 0; box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.paper-title { text-align: center; font-weight: 800; font-size: 1.35rem; letter-spacing: .01em; margin: 0 0 12px; }
.lbl { font-style: italic; font-weight: 700; font-size: .68rem; letter-spacing: .02em; padding-top: 3px; }
.lbl.right { text-align: right; }

.head { display: grid; grid-template-columns: .6fr 2fr auto 2fr .85fr; column-gap: 14px; align-items: end; margin-bottom: 14px; }
.head > .line, .head > .vs { grid-row: 1; }
.head .league { grid-column: 1; }
.head .vs { grid-column: 3; }
.head .date { grid-column: 5; }
.head .lbl { grid-row: 2; }
.l-league { grid-column: 1; } .l-home { grid-column: 2; } .l-away { grid-column: 4; } .l-date { grid-column: 5; }
.line {
    font: inherit; font-weight: 600; border: 0; border-bottom: var(--b); border-radius: 0;
    background: transparent; height: 30px; padding: 0 2px; width: 100%; min-width: 0;
}
.line.slot { font-size: 1.05rem; }
.line .fixed { display: block; line-height: 28px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line.date { font-size: .85rem; }
.abbey-home .a-slot, .abbey-away .o-slot { grid-column: 2; }
.abbey-home .o-slot, .abbey-away .a-slot { grid-column: 4; }
.vs {
    font: inherit; font-weight: 800; background: none; border: 0; padding: 0 4px 4px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; line-height: 1; color: var(--ink);
}
.vs small { color: var(--accent); font-size: 1rem; margin-top: 2px; }

.body { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.half { display: grid; grid-template-columns: 1fr 1fr var(--sc) var(--sc); grid-template-rows: repeat(8, var(--rh)) var(--th); }
.cell { border-right: var(--b); border-bottom: var(--b); min-width: 0; }
.cell.first { border-top: var(--b); }
.abbey-home .a-name, .abbey-away .o-name { grid-column: 1; border-left: var(--b); }
.abbey-home .o-name, .abbey-away .a-name { grid-column: 2; }
.abbey-home .a-score, .abbey-away .o-score { grid-column: 3; }
.abbey-home .o-score, .abbey-away .a-score { grid-column: 4; }
.abbey-home .t-edge-a, .abbey-away .t-edge-o { border-left: var(--b); }

.names { display: flex; flex-direction: column; }
.name-input {
    flex: 1; width: 100%; min-width: 0; font: inherit; font-size: .9rem; border: 0; border-radius: 0;
    background: transparent; padding: 0 6px; color: var(--ink);
}
.names .name-input + .name-input { border-top: 1px solid var(--rule); }
select.name-input {
    -webkit-appearance: none; appearance: none; padding-right: 16px; text-overflow: ellipsis;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23aaa'/%3E%3C/svg%3E") no-repeat right 5px center;
}
.name-input:focus, .score-input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.name-input.dup { background-color: var(--loss); }

.score { display: flex; }
.score-input, .score output {
    width: 100%; height: 100%; border: 0; border-radius: 0; background: transparent; text-align: center;
    font: inherit; font-size: 1.3rem; font-weight: 700; padding: 0; color: var(--ink);
}
.score output { display: flex; align-items: center; justify-content: center; font-size: 1.5rem; }
.game { display: contents; }
.cell.win { background: var(--win); }
.o-score.win { background: var(--loss); }
.cell.bad { background: var(--bad); }
.cell.ahead { background: var(--win); }
.cell.behind { background: var(--loss); }
.cell.level { background: var(--level); }

.half.final { grid-column: 2; grid-template-rows: var(--th); padding: 18px 0 4px; }
.final .cell { grid-row: 1; }
.final-label { grid-column: 1 / span 2; grid-row: 1; align-self: center; text-align: right; font-weight: 700; padding-right: 14px; }
.final output { font-size: 1.7rem; }

.actions {
    position: sticky; bottom: 0; display: flex; gap: 8px; align-items: center; margin: 12px -16px 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: rgb(255 255 255 / .96); border-top: 1px solid #ddd;
}
.actions .warn { flex: 1; color: #a11; font-weight: 600; font-size: .85rem; }

/* Portrait phones: stack the halves */
@media (max-width: 640px) {
    .body { grid-template-columns: 1fr; }
    .body > .half + .half { margin-top: 14px; }
    .half.final { grid-column: 1; }
    .head { grid-template-columns: 1fr auto 1fr; row-gap: 0; }
    .head .league, .head .date { display: none; }
    .l-league, .l-date { display: none; }
    .abbey-home .a-slot, .abbey-away .o-slot, .l-home { grid-column: 1; }
    .head .vs { grid-column: 2; }
    .abbey-home .o-slot, .abbey-away .a-slot, .l-away { grid-column: 3; }
    .actions .warn { font-size: .75rem; }
    .paper-title { font-size: 1rem; }
}

/* Landscape phones: squeeze vertical chrome */
@media (max-height: 500px) {
    .paper-title { font-size: 1.05rem; margin-bottom: 6px; }
    .topnav { height: 36px; }
}
