/* Buzz Bowl – a 1960s rec-room look: cream tin, tomato red, mustard and teal. */
:root {
  --bg: #efe4c8;
  --paper: #f8f1de;
  --ink: #2b2118;
  --muted: #6e6152;
  --line: #d4c4a0;
  --red: #c8442b;
  --mustard: #e0a82e;
  --teal: #2f7f7a;
  --board: #1b1712;
  --amber: #ffb43b;
  --shadow: 0 2px 0 rgba(0,0,0,.08), 0 8px 22px rgba(60,40,10,.12);
  --display: "Futura", "Century Gothic", "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(rgba(120,90,40,.07) 1px, transparent 1px);
  background-size: 6px 6px;
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
a { color: var(--teal); }
.hidden { display: none !important; }

header.top { max-width: 1100px; margin: 0 auto; padding: 14px 16px 0; }
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.home-link { font-size: 14px; text-decoration: none; color: var(--muted); font-weight: 600; }
h1 { margin: 2px 0 0; font-family: var(--display); font-weight: 800; font-size: clamp(32px, 6vw, 48px); letter-spacing: 1px; line-height: 1; text-transform: uppercase; font-style: italic; }
h1 .b1 { color: var(--red); text-shadow: 3px 3px 0 var(--mustard); }
h1 .b2 { color: var(--teal); text-shadow: 3px 3px 0 var(--mustard); }
.sub { margin: 6px 0 0; color: var(--muted); font-family: var(--display); letter-spacing: .5px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.profile-chip { font-size: 14px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.profile-chip a { color: var(--ink); font-weight: 600; }
.profile-chip .sp-in, .profile-chip .sp-up { text-decoration: none; padding: 5px 11px; border-radius: 8px; border: 2px solid var(--ink); background: var(--paper); }
.profile-chip .sp-up { background: var(--ink); color: var(--paper); }
.profile-chip .sp-or { color: var(--muted); }
.profile-chip .sp-out { font: inherit; font-size: 13px; padding: 4px 10px; border-radius: 8px; border: 2px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer; }

.tabs { display: flex; gap: 4px; margin-top: 12px; border-bottom: 3px solid var(--ink); overflow-x: auto; }
.tab { font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; font-size: 14px; background: var(--line); color: var(--ink); border: 0; padding: 8px 16px; border-radius: 10px 10px 0 0; cursor: pointer; white-space: nowrap; }
.tab.active { background: var(--ink); color: var(--mustard); }

main { max-width: 1100px; margin: 0 auto; padding: 14px 16px 24px; }
footer { text-align: center; color: var(--muted); font-size: 13px; padding: 10px 16px 24px; }

button { font: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
.primary { background: var(--red); color: #fff8e8; border: 3px solid var(--ink); border-radius: 12px; padding: 9px 18px; font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; box-shadow: 3px 3px 0 var(--ink); }
.primary:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.primary.big { font-size: 20px; padding: 12px 28px; margin-top: 8px; }
.primary.teal { background: var(--teal); }
.primary.mustard { background: var(--mustard); color: var(--ink); }
.ghost { background: var(--paper); border: 2px solid var(--ink); border-radius: 10px; padding: 7px 12px; color: var(--ink); font-weight: 600; }
.ghost.small, button.small { font-size: 13px; padding: 4px 10px; }
.ghost.on { background: var(--ink); color: var(--mustard); }

.card { background: var(--paper); border: 3px solid var(--ink); border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 10px; font-family: var(--display); text-transform: uppercase; letter-spacing: 1px; }
.card h3 { margin: 16px 0 6px; font-family: var(--display); text-transform: uppercase; letter-spacing: .8px; font-size: 16px; color: var(--red); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.hint { color: var(--muted); font-size: 14px; }

/* New game */
.newgame { max-width: 720px; margin: 0 auto; }
.field-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.lbl { font-family: var(--display); font-weight: 700; text-transform: uppercase; font-size: 13px; letter-spacing: .8px; color: var(--muted); min-width: 120px; display: inline-block; }
.seg { display: inline-flex; border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button { background: var(--paper); border: 0; border-right: 2px solid var(--ink); padding: 6px 12px; font-weight: 600; color: var(--ink); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--teal); color: #fff8e8; }
.teams-row { display: flex; align-items: center; gap: 14px; margin: 16px 0 6px; flex-wrap: wrap; }
.team-pick { flex: 1; min-width: 220px; }
.team-pick label { display: block; }
.team-pick input { width: 100%; font: inherit; font-family: var(--display); font-weight: 700; font-size: 20px; padding: 6px 10px; border: 2px solid var(--ink); border-radius: 10px; background: #fffaf0; color: var(--ink); text-transform: uppercase; }
.vs { font-family: var(--display); font-weight: 800; font-style: italic; font-size: 22px; color: var(--red); }
.swatches { display: flex; gap: 6px; margin-top: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--paper); box-shadow: 0 0 0 2px var(--ink); cursor: pointer; padding: 0; }
.swatch.sel { box-shadow: 0 0 0 2px var(--ink), 0 0 0 5px var(--mustard); }
.swatch:disabled { opacity: .25; }
.resume { background: #fff6d8; border: 2px dashed var(--mustard); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
.resume p { margin: 0 0 8px; }

/* Scoreboard */
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; background: var(--board); border: 4px solid #6b4a2b; border-radius: 14px; padding: 10px 14px; color: #f3e6c8; box-shadow: inset 0 0 0 2px #000, var(--shadow); margin-bottom: 10px; }
.digits { font-family: "DS-Digital", "Courier New", ui-monospace, monospace; color: var(--amber); text-shadow: 0 0 6px rgba(255,160,40,.7); font-weight: 700; }
.sb-team { display: flex; align-items: center; gap: 10px; }
#sbT1 { flex-direction: row-reverse; }
.sb-name { font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; font-size: clamp(14px, 2.4vw, 22px); padding: 3px 10px; border-radius: 6px; color: #fff; }
.sb-score { font-size: clamp(30px, 6vw, 48px); line-height: 1; min-width: 2ch; text-align: center; background: #000; border-radius: 6px; padding: 2px 8px; }
.sb-ball { color: var(--amber); visibility: hidden; font-size: 18px; }
.sb-team.poss .sb-ball { visibility: visible; }
.sb-mid { text-align: center; display: flex; flex-direction: column; gap: 2px; justify-content: center; }
.sb-clock { font-size: clamp(26px, 5vw, 40px); line-height: 1; background: #000; border-radius: 6px; padding: 2px 10px; }
.sb-row { display: flex; gap: 12px; font-size: 12px; letter-spacing: 1px; justify-content: center; }
.sb-row b { font-size: 18px; }
.sb-spot { font-size: 12px; color: #cdbd98; letter-spacing: .5px; }

/* Field */
.banner { font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; text-align: center; padding: 8px 12px; background: var(--mustard); color: var(--ink); border: 3px solid var(--ink); border-bottom: 0; border-radius: 12px 12px 0 0; font-size: clamp(13px, 2.2vw, 17px); }
.banner small { display: block; font-family: system-ui, sans-serif; text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; }
.field-wrap { position: relative; border: 3px solid var(--ink); border-radius: 0 0 12px 12px; overflow: hidden; background: #6b4a2b; line-height: 0; }
canvas#field { width: 100%; height: auto; display: block; touch-action: pan-y; }
canvas#field.grab { touch-action: none; cursor: grab; }
.field-wrap.buzz canvas { animation: buzz .07s linear infinite; }
@keyframes buzz { 0% { transform: translate(0,0); } 25% { transform: translate(.6px,-.5px); } 50% { transform: translate(-.5px,.6px); } 75% { transform: translate(.5px,.4px); } 100% { transform: translate(0,0); } }
.flash { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; font-family: var(--display); font-weight: 900; font-style: italic; text-transform: uppercase; font-size: clamp(28px, 7vw, 70px); color: var(--mustard); text-shadow: 4px 4px 0 var(--red), 7px 7px 0 var(--ink); line-height: 1.1; text-align: center; animation: pop .5s ease-out; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; padding: 10px 4px; min-height: 58px; }
.controls .grp { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.controls .sep { width: 2px; height: 28px; background: var(--line); }
.controls .note { color: var(--muted); font-size: 14px; }
.fourth { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.fourth .primary small { display: block; font-size: 11px; letter-spacing: 0; font-family: system-ui, sans-serif; font-weight: 600; text-transform: none; }

.below { margin-top: 6px; }
.log { margin: 8px 0 0; padding-left: 22px; max-height: 220px; overflow-y: auto; font-size: 14px; }
.log li { margin: 2px 0; }
.log li.big { font-weight: 700; color: var(--red); }
.log li.q { list-style: none; margin-left: -22px; font-family: var(--display); font-weight: 700; text-transform: uppercase; color: var(--teal); letter-spacing: 1px; }

/* Records */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 10px 0; }
.stat { background: #fffaf0; border: 2px solid var(--ink); border-radius: 12px; padding: 8px 12px; }
.stat b { display: block; font-family: var(--display); font-size: 26px; color: var(--red); }
.stat span { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
table.games { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
table.games th, table.games td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
table.games th { font-family: var(--display); text-transform: uppercase; font-size: 12px; letter-spacing: .6px; color: var(--muted); }
.res-W { color: var(--teal); font-weight: 700; }
.res-L { color: var(--red); font-weight: 700; }
.res-T { color: var(--muted); font-weight: 700; }

.howto { max-width: 820px; margin: 0 auto; }
.howto li { margin: 4px 0; }

@media (max-width: 640px) {
  .lbl { min-width: 0; display: block; }
  .scoreboard { padding: 8px; gap: 6px; }
  .sb-row { gap: 6px; }
  .controls { gap: 6px; }
  .primary { padding: 8px 12px; }
}

/* narrow screens: stack the scoreboard */
@media (max-width: 640px) {
  .scoreboard { grid-template-columns: 1fr 1.25fr 1fr; }
  .sb-team, #sbT1 { flex-direction: column; gap: 4px; min-width: 0; justify-content: center; }
  .sb-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; padding: 2px 6px; }
  .sb-row { flex-wrap: wrap; }
  .sb-ball { font-size: 12px; }
  canvas#field { max-width: 100%; }
  .controls { position: sticky; bottom: 0; z-index: 5; background: rgba(239,228,200,.96); border-top: 2px solid var(--ink); margin: 0 -16px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
}

/* Season */
.season .card { margin-bottom: 14px; }
.tchip { display: inline-block; padding: 1px 8px; border-radius: 6px; font-family: var(--display); font-weight: 700; font-size: 13px; letter-spacing: .3px; white-space: nowrap; }
.sel { font: inherit; padding: 6px 10px; border: 2px solid var(--ink); border-radius: 10px; background: #fffaf0; color: var(--ink); max-width: 100%; }
.nextgame { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; background: #fff6d8; border: 2px dashed var(--mustard); border-radius: 12px; padding: 10px 14px; }
.ng-line { margin-top: 4px; font-weight: 600; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stand-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
table.stand { width: 100%; border-collapse: collapse; font-size: 13px; }
table.stand th, table.stand td { padding: 3px 5px; border-bottom: 1px solid var(--line); text-align: right; }
table.stand th:first-child, table.stand td:first-child { text-align: left; }
table.stand th { font-family: var(--display); text-transform: uppercase; font-size: 11px; color: var(--muted); }
tr.me td { background: #fff1c4; font-weight: 700; }
.scores { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; font-size: 14px; }
.score { background: #fffaf0; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.score .wn { font-weight: 800; }
.bracket { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 4px; }
.round { min-width: 220px; display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }
.round h4 { margin: 0; font-family: var(--display); text-transform: uppercase; font-size: 13px; color: var(--teal); letter-spacing: .6px; }
.bgame { border: 2px solid var(--ink); border-radius: 10px; background: #fffaf0; padding: 4px 6px; }
.bteam { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 2px 0; opacity: .7; }
.bteam.wn { opacity: 1; font-weight: 800; }
.bteam.me .tchip { box-shadow: 0 0 0 2px var(--mustard); }
.champ { text-align: center; }
.big-champ .tchip { font-size: 26px; padding: 6px 16px; }
.league { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.ldiv h4 { margin: 4px 0; font-family: var(--display); text-transform: uppercase; font-size: 13px; color: var(--teal); }
.lteam { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.lteam .tn { flex: 1; }
.lteam .rt { color: var(--muted); font-size: 12px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--ink); display: inline-block; }
.lteam.editing { flex-wrap: wrap; background: #fff6d8; padding: 8px; border-radius: 10px; }
.lteam.editing input[type=text], .lteam.editing input:not([type]) { font: inherit; padding: 4px 8px; border: 2px solid var(--ink); border-radius: 8px; width: 140px; background: #fffaf0; }
.clr { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.clr input { width: 40px; height: 28px; padding: 0; border: 2px solid var(--ink); border-radius: 6px; background: none; }
