/* Domino Tally: SLAM's palette and 5x7 font. Font sizes stay on multiples of 8px so the pixel font is crisp;
   art images are scaled by whole numbers (--kb, --kf from app.js). Phone first, full height, safe areas. */
@font-face { font-family: Slam5x7; src: url(fonts/slam.woff2) format('woff2'); font-display: block; }
:root {
  --cream: #fff6dc; --gold: #f2c35a; --red: #c4492f; --ink: #20161a;
  --rail: #1c1410; --wood: #5a3e2c; --tan: #c8a070;
  --blue: #6c9ce8; --blue-d: #2c4ea0; --rose: #e8705a; --rose-d: #a02c1c;
  --kb: 6; --kf: 3; --px: 2px;
  --font: Slam5x7, "Courier New", monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 16px/24px var(--font); letter-spacing: 0; color: var(--cream);
  background: linear-gradient(rgba(28, 20, 16, .45), rgba(28, 20, 16, .45)), var(--boards) repeat var(--rail);
  background-size: auto, calc(152px * 3) calc(18px * 3);
  image-rendering: pixelated;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none;
  -webkit-font-smoothing: none;
}
body[data-route="match"] { background-image: var(--felt); background-size: 48px 48px; }
img { image-rendering: pixelated; image-rendering: crisp-edges; }
#app, .panel, #toast { zoom: var(--z, 1); }
#app {
  min-height: calc(100dvh / var(--z, 1)); max-width: 760px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column;
}
h1, h2, h3, p { margin: 0; font-weight: normal; }
h2 { font-size: 24px; line-height: 32px; margin: 0 40px 16px 0; }
h3 { font-size: 16px; color: var(--gold); margin: 24px 0 8px; text-shadow: 2px 2px 0 var(--ink); }
a { color: inherit; }
b { font-weight: normal; color: var(--gold); }
small { display: block; font-size: 16px; opacity: .85; }
.fine { color: var(--tan); text-shadow: 2px 2px 0 var(--ink); margin: 8px 0; }
.help { margin: 8px 0 16px; text-shadow: 2px 2px 0 var(--ink); }
.empty { padding: 24px 8px; text-align: center; text-shadow: 2px 2px 0 var(--ink); }

/* SLAM's window: cream fill, ink border, red inner line, clipped corners */
.win {
  background: var(--cream); color: var(--ink);
  border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px var(--cream), inset 0 0 0 4px var(--red);
  clip-path: polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% calc(100% - 2px), calc(100% - 2px) 100%, 2px 100%, 0 calc(100% - 2px), 0 2px);
}
.win h3, .win .help, .win .fine, .win .empty { text-shadow: none; }
.win h3 { color: var(--red); }
.win .fine { color: var(--wood); }
.win b { color: var(--red); }

/* buttons */
button, .btn { font: inherit; color: inherit; touch-action: manipulation; }
.btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 56px; padding: 12px 16px; text-align: center; text-decoration: none; cursor: pointer;
  background: var(--cream); color: var(--ink); border: 2px solid var(--ink); border-radius: 0;
  box-shadow: 4px 4px 0 var(--ink);
  user-select: none; -webkit-user-select: none;
}
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.gold { background: var(--gold); }
.btn.big { min-height: 72px; font-size: 24px; line-height: 32px; }
.btn.ghost { background: transparent; color: inherit; border-color: transparent; box-shadow: none; min-height: 48px; }
.win .btn.ghost { color: var(--ink); }
.btn.danger { color: var(--red); margin-top: 32px; }
.btn:focus-visible, .who:focus-visible, .seat:focus-visible, .item:focus-visible { outline: 4px solid var(--gold); outline-offset: 2px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.menu { display: flex; flex-direction: column; gap: 16px; }

/* top bar */
.bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 64px; gap: 8px; }
.bar h1 { font-size: 24px; line-height: 32px; text-align: center; text-shadow: 2px 2px 0 var(--ink); white-space: nowrap; }
.bar .back, .bar > :first-child { white-space: nowrap; justify-self: start; padding-left: 0; padding-right: 8px; }
.bar > :last-child { justify-self: end; }
.rec { color: var(--gold); text-shadow: 2px 2px 0 var(--ink); text-align: right; }

/* home */
.home { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 24px; padding: 24px 0; }
.logo { display: block; width: calc(152px * 2); max-width: 100%; margin: 0 auto; }
.tag { text-align: center; color: var(--gold); text-shadow: 2px 2px 0 var(--ink); }
.home .menu { width: 100%; max-width: 420px; margin: 0 auto; }
.home .fine { text-align: center; }

/* faces */
.face { width: calc(16px * var(--kf)); height: calc(16px * var(--kf)); flex: none; display: block; }
.face.sm { width: 32px; height: 32px; }
.face.big { width: 64px; height: 64px; }

/* setup */
.setup { display: flex; flex-direction: column; gap: 8px; padding-bottom: 24px; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.tab { flex: 1 1 auto; min-height: 48px; padding: 8px 4px; background: var(--wood); color: var(--cream); border: 2px solid var(--ink); cursor: pointer; }
.tab.on { background: var(--gold); color: var(--ink); box-shadow: inset 0 -4px 0 var(--red); }
.modeline { color: var(--gold); text-shadow: 2px 2px 0 var(--ink); }
.teams { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 8px; align-items: center; }
.vs { font-size: 24px; color: var(--gold); text-shadow: 2px 2px 0 var(--ink); }
.team h3, .bench h3 { margin-top: 0; }
.team.t0 h3 { color: var(--blue); } .team.t1 h3 { color: var(--rose); }
.seats { display: grid; gap: 8px; }
.seats.cut { grid-template-columns: 1fr 1fr; }
.seats.wait { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.bench { margin-top: 16px; }
.seat {
  display: flex; align-items: center; gap: 8px; min-height: 64px; padding: 8px; cursor: pointer; text-align: left;
  background: rgba(255, 246, 220, .12); color: var(--cream); border: 2px dashed var(--tan);
}
.seat.full { background: var(--cream); color: var(--ink); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.team.t0 .seat.full { box-shadow: 4px 4px 0 var(--blue-d); } .team.t1 .seat.full { box-shadow: 4px 4px 0 var(--rose-d); }
.seat span { min-width: 0; overflow-wrap: anywhere; }
.seat .plus { font-size: 32px; line-height: 32px; width: 32px; text-align: center; }
.seat .face { width: 48px; height: 48px; }
.setup > .btn.big { margin-top: 24px; }

/* match */
.match-bar h1 { color: var(--cream); }
.play { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.poseline { text-align: center; text-shadow: 2px 2px 0 var(--ink); }
.poseline b { color: var(--gold); }
.board { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.bone { display: block; width: calc(37px * var(--kb)); height: calc(19px * var(--kb)); filter: drop-shadow(4px 4px 0 rgba(6, 32, 14, .7)); }
.bone.bump { animation: thud .32s steps(4); }
@keyframes thud { 0% { transform: translateY(-8px) scale(1.04); } 60% { transform: translateY(2px); } 100% { transform: none; } }
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.sname { min-height: 48px; text-align: center; text-shadow: 2px 2px 0 var(--ink); overflow-wrap: anywhere; }
.side.t0 .sname { color: #e2ecff; } .side.t1 .sname { color: #ffe4dc; }
.streak { display: block; color: var(--gold); }
.score { display: none; }
.who {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 80px; padding: 12px; cursor: pointer;
  background: var(--cream); color: var(--ink); border: 2px solid var(--ink); text-align: left;
  user-select: none; -webkit-user-select: none;
}
.side.t0 .who { box-shadow: 4px 4px 0 var(--blue-d), inset 0 -6px 0 var(--blue); }
.side.t1 .who { box-shadow: 4px 4px 0 var(--rose-d), inset 0 -6px 0 var(--rose); }
.who:active { transform: translate(2px, 2px); }
.who .nm { min-width: 0; overflow-wrap: anywhere; }
.who.bump { animation: flash .4s steps(2) 1; }
@keyframes flash { 0%, 50% { background: var(--gold); } 100% { background: var(--cream); } }
.pose { position: absolute; top: -10px; right: 6px; padding: 0 6px; background: var(--red); color: var(--cream); border: 2px solid var(--ink); line-height: 20px; }
.board.cut { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; }
.who.cutp { flex-direction: column; justify-content: center; min-height: 160px; box-shadow: 4px 4px 0 var(--ink); text-align: center; }
.pipf { width: calc(19px * var(--kf)); height: calc(19px * var(--kf)); }
.who.cutp .pipf { width: calc(19px * (var(--kf) + 1)); height: calc(19px * (var(--kf) + 1)); }
.hint { text-align: center; color: var(--cream); opacity: .9; text-shadow: 2px 2px 0 var(--ink); font-size: 16px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: auto; }
.strip {
  display: flex; gap: 16px; overflow: hidden; white-space: nowrap; width: 100%; min-height: 48px; padding: 12px; cursor: pointer;
  background: rgba(6, 32, 14, .55); color: #b4e69c; border: 2px solid #06200e; text-align: left;
}

/* match over */
.over { flex: 1; display: flex; flex-direction: column; gap: 24px; padding-bottom: 8px; }
.over .win { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 24px 16px; }
.banner { font-size: 32px; line-height: 40px; color: var(--red); }
.over.six .banner { font-size: 40px; line-height: 48px; white-space: nowrap; color: var(--gold); text-shadow: -4px 0 var(--ink), 4px 0 var(--ink), 0 -4px var(--ink), 0 4px var(--ink), 6px 6px 0 var(--red); animation: wobble .6s steps(3) 2; }
@keyframes wobble { 0% { transform: rotate(-3deg) scale(1.1); } 50% { transform: rotate(3deg); } 100% { transform: none; } }
.champs { display: flex; gap: 24px; }
.champs div { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.result { text-align: center; }
.cutfinal { display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: 8px; width: 100%; }
.over .bone { width: calc(37px * min(var(--kb), 5)); height: calc(19px * min(var(--kb), 5)); }
.over .champs .face.big { width: 48px; height: 48px; }
.cutfinal div { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px; }
.cutfinal .won { background: var(--gold); }
.cutfinal .pipf { width: 38px; height: 38px; }
.btn.share { background: #b4e69c; }

/* lists */
.list { display: flex; flex-direction: column; gap: 12px; }
.item {
  display: grid; grid-template-columns: 1fr; gap: 4px; padding: 12px 16px; cursor: pointer; text-align: left;
  background: var(--cream); color: var(--ink); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
}
.item .when { color: var(--red); }
.item .when b { color: var(--ink); background: var(--gold); padding: 0 4px; }
.item .faces { display: flex; gap: 4px; }
.item.open { opacity: .75; }
.mini { width: 39px; height: 21px; vertical-align: middle; margin: 0 4px; }
.prow { grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; }
.prow .face { grid-row: span 2; }
.grow { grid-template-columns: auto auto 1fr auto; align-items: center; column-gap: 12px; }
.night { display: flex; flex-direction: column; padding-bottom: 24px; }
.night > .btn.big { margin-bottom: 8px; }
.standings { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.stand { display: flex; align-items: center; gap: 8px; padding: 8px; background: rgba(28, 20, 16, .75); border: 2px solid var(--ink); }
.stand span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.stand b { font-size: 24px; }

/* player page */
.pview { display: flex; flex-direction: column; padding-bottom: 24px; }
.who-big { display: flex; align-items: center; gap: 16px; margin: 8px 0 16px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { display: flex; flex-direction: column; padding: 12px; background: var(--cream); color: var(--ink); border: 2px solid var(--ink); }
.stat b { font-size: 32px; line-height: 40px; color: var(--red); }

/* settings */
.settings { display: flex; flex-direction: column; gap: 12px; padding-bottom: 24px; }
.toggle { flex-direction: row; justify-content: space-between; text-align: left; }
.toggle b { color: var(--wood); }
.toggle.on b { color: var(--red); }
.settings label.btn { cursor: pointer; }

/* sheets */
#sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
#sheet[hidden] { display: none; }
.scrim { position: absolute; inset: 0; background: rgba(12, 6, 4, .72); }
.panel {
  position: relative; width: min(100%, 560px); max-height: calc((100dvh - 24px - env(safe-area-inset-top)) / var(--z, 1)); overflow-y: auto; overscroll-behavior: contain;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px;
  animation: up .18s steps(3);
}
@keyframes up { from { transform: translateY(40px); } to { transform: none; } }
@media (min-width: 600px) and (min-height: 600px) { #sheet { align-items: center; } .panel { padding-bottom: 24px; } }
.panel h2 { color: var(--ink); }
.panel .x { position: absolute; top: 12px; right: 12px; width: 48px; min-height: 48px; padding: 0; font-size: 24px; }
.panel .btn.danger { margin-top: 8px; }
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.rp {
  display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 6px 8px; cursor: pointer; text-align: left;
  background: #fffbef; color: var(--ink); border: 2px solid var(--ink); position: relative;
}
.rp.on { background: var(--gold); }
.rp span { min-width: 0; overflow-wrap: anywhere; }
.rp i { position: absolute; right: -2px; top: -12px; font-style: normal; background: var(--wood); color: var(--cream); padding: 0 4px; line-height: 20px; }
.newp { display: flex; align-items: center; gap: 12px; }
.newp input, .fbin {
  flex: 1; min-width: 0; height: 56px; padding: 0 12px; font: 24px/32px var(--font); text-transform: uppercase;
  background: #fffbef; color: var(--ink); border: 2px solid var(--ink); border-radius: 0; outline: none;
}
.newp input:focus { border-color: var(--red); box-shadow: inset 0 0 0 2px var(--red); }
.newp input::placeholder { color: #b8a888; }
.picker { display: flex; flex-direction: column; gap: 8px; }
.faces8, .cols8 { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.fpick { padding: 2px; border: 2px solid transparent; background: none; cursor: pointer; display: flex; justify-content: center; }
.fpick .face { width: 32px; height: 32px; }
@media (min-width: 420px) { .fpick .face { width: 48px; height: 48px; } }
.fpick.on { border-color: var(--ink); background: var(--gold); }
.cpick { height: 32px; border: 2px solid var(--ink); cursor: pointer; }
.cpick.on { outline: 4px solid var(--red); outline-offset: -2px; }
.cardimg { width: 100%; max-width: 320px; margin: 0 auto; display: block; border: 2px solid var(--ink); }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 24px); z-index: 30;
  max-width: calc(100% - 32px); padding: 8px 16px; background: var(--ink); color: var(--gold); border: 2px solid var(--gold);
  opacity: 0; pointer-events: none; transition: opacity .15s steps(2), transform .15s steps(2); text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
body[data-route="match"] #toast { top: calc(64px + env(safe-area-inset-top)); bottom: auto; transform: translate(-50%, -24px); }
body[data-route="match"] #toast.on { transform: translate(-50%, 0); }

/* wide: phones on their side and landscape tablets/computers (body.wide from app.js): the two sides
   either side of the bone */
body.wide .play { gap: 8px; }
body.wide .board { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
body.wide .board .sides { display: contents; }
body.wide .board .side.t0 { grid-column: 1; grid-row: 1; }
body.wide .board .side.t1 { grid-column: 3; grid-row: 1; }
body.wide .board .bone { grid-column: 2; grid-row: 1; }
body.wide .board.cut { grid-template-columns: repeat(4, 1fr); }
body.wide .who { min-height: 64px; }
body.wide .who.cutp { min-height: 120px; }
body.wide .sname { min-height: 0; }
body.wide.short .hint { display: none; }
body.wide .play { justify-content: center; }
body.wide .actions { margin-top: 16px; }
body.wide .over { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
body.wide .over .win { padding: 16px; gap: 8px; }
body.wide .bar { min-height: 48px; }
body.wide .home { flex-direction: row; align-items: center; }
body.wide .home .logo { width: 304px; }
body.wide .home .tag, body.wide .home .fine { display: none; }
/* very narrow phones (iPhone SE): faces above names */
@media (max-width: 359px) {
  .seat .face { width: 32px; height: 32px; }
  .seat { flex-direction: column; justify-content: center; text-align: center; gap: 4px; }
  .who:not(.cutp) { flex-direction: column; justify-content: center; text-align: center; gap: 4px; padding: 8px; }
  .vs { font-size: 16px; }
}
