/* squash.css — "Parquet" squash scorer. Warm maple court, vintage club board.
   Big Shoulders Display (numerals/headers) + Instrument Sans (UI). */

/* Design tokens live in chainline-tokens.css (loaded first). */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  touch-action: manipulation;
  color: var(--cream);
  font-family: var(--ui);
  background:
    repeating-linear-gradient(91deg, rgba(0,0,0,0) 0 15px, rgba(0,0,0,0.16) 15px 16px),
    linear-gradient(168deg, #2a1d0f 0%, #1c140b 52%, #120c06 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

input { font: inherit; color: inherit; }
button { font: inherit; cursor: pointer; }

.app {
  height: 100dvh; display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ───────── Top bar ───────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--maple-dim);
}
.brand { display: flex; flex-direction: column; line-height: 1; gap: 4px; min-width: 0; }
.brand .court {
  font-family: var(--display); font-weight: 800; letter-spacing: 0.04em;
  font-size: clamp(20px, 2.6vw, 30px); color: var(--cream); white-space: nowrap;
}
.brand .config {
  font-family: var(--ui); font-size: clamp(10px, 1.1vw, 12px);
  letter-spacing: 0.16em; color: var(--cream-dim); text-transform: uppercase; white-space: nowrap;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  font-family: var(--ui); font-size: 12px; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--cream-dim);
  padding: 9px 14px; border-radius: 9px;
  border: 1px solid var(--maple-dim); background: transparent;
  transition: -webkit-transform 0.06s ease, transform 0.06s ease, border-color 0.2s, color 0.2s, background 0.2s;
}
#mobileMenuBtn { display: none; }
.btn:hover { color: var(--cream); border-color: rgba(199,154,93,0.5); }
.btn:active {
  -webkit-transform: translateY(1px);
  transform: translateY(1px);
}
.btn-red { color: var(--cream); border-color: var(--red); background: color-mix(in srgb, var(--red) 16%, transparent); }
.btn-red:hover { background: color-mix(in srgb, var(--red) 30%, transparent); border-color: var(--red); }
.btn-solid { background: var(--red); border-color: var(--red); color: var(--on-red); font-weight: 700; }
.btn-solid:hover { background: var(--red-deep); }
.btn-lg { font-size: 13px; padding: 12px 20px; }
#undoBtn {
  color: var(--cream); border-color: var(--maple);
  background: rgba(199, 154, 93, 0.35); font-weight: 700;
}
#undoBtn:hover { background: rgba(199, 154, 93, 0.55); }

.color-btn {
  width: 40px; height: 40px; border-radius: 8px; border: 2px solid transparent;
  cursor: pointer; transition: all 0.2s; padding: 0;
  -webkit-touch-callout: none;
}
.color-btn:hover {
  -webkit-transform: scale(1.1);
  transform: scale(1.1);
}

/* ───────── Status / timer line ───────── */
.statusbar {
  min-height: 30px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 14px;
  padding: 4px 16px;
  font-family: var(--ui); font-size: 13px; letter-spacing: 0.06em; color: var(--cream-dim);
  border-bottom: 1px solid rgba(199,154,93,0.1);
}
.statusbar:empty { display: none; }
.statusbar .timer {
  font-family: var(--display); font-weight: 800; font-size: 22px; color: var(--cream);
  letter-spacing: 0.04em;
}
.statusbar .timer.warn { color: var(--red); }
#skipBtn { display: none; }

/* ───────── Board ───────── */
.board {
  flex: 1 1 auto; display: flex; position: relative; min-height: 0;
}
.col {
  flex: 1; position: relative; overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; touch-action: manipulation;
  border-top: 3px solid transparent;
  border-left: 5px solid transparent;
  transition: background 0.25s, border-color 0.25s;
}
.col.serving {
  border-top-color: var(--red);
  box-shadow: inset 0 90px 90px -70px color-mix(in srgb, var(--red) 22%, transparent), inset 0 -90px 90px -70px rgba(199,154,93,0.08);
}
.name-input {
  background: transparent !important; -webkit-appearance: none; appearance: none;
  border: none; text-align: center; outline: none;
  width: 88%; max-width: 420px;
  font-family: var(--display); font-weight: 700; text-transform: uppercase;
  font-size: clamp(20px, 3.2vw, 38px); letter-spacing: 0.04em;
  color: var(--cream-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.col.serving .name-input { color: var(--cream); }
.name-input:focus { color: var(--cream); }
.score {
  font-family: var(--display); font-weight: 800; line-height: 0.78;
  font-variant-numeric: tabular-nums;
  font-size: clamp(80px, min(25vh, 30vw), 300px); color: var(--cream-dim);
  text-shadow: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.col.serving .score { color: var(--cream); text-shadow: 0 0 60px color-mix(in srgb, var(--red) 22%, transparent); }

/* games pips */
.pips { display: flex; gap: 9px; }
.pip {
  width: clamp(12px, 1.4vw, 16px); height: clamp(12px, 1.4vw, 16px);
  border-radius: 50%; border: 1.5px solid var(--cream-faint); background: transparent;
}
.pip.on { background: var(--red); border-color: var(--red); box-shadow: 0 0 10px color-mix(in srgb, var(--red) 50%, transparent); }

/* serve mini-court under serving player */
.serve-tag {
  display: none; flex-direction: column; align-items: center; gap: 5px;
  position: absolute; bottom: 18px;
}
.col.serving .serve-tag { display: flex; }
.serve-tag .lbl {
  font-family: var(--display); font-weight: 700; font-size: 12px;
  letter-spacing: 0.22em; color: var(--cream-dim);
}

/* center divider + games tag */
.divider {
  width: 2px; flex-shrink: 0;
  background: linear-gradient(180deg, transparent, var(--cream-faint), transparent);
}
.game-tag {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4;
  padding: 6px 16px; border-radius: 999px; background: var(--ink);
  border: 1.5px solid var(--red); display: flex; align-items: center; gap: 8px;
  font-family: var(--display); font-weight: 800; font-size: 19px; letter-spacing: 0.05em;
  color: var(--cream); white-space: nowrap;
}

/* center rally column — always visible */
.center {
  width: clamp(100px, 16vw, 260px); flex-shrink: 0;
  flex-direction: column; background: rgba(20,15,8,0.5); display: flex;
  min-height: 0; overflow: hidden;
}
.center .chead {
  text-align: center; padding: 12px; border-bottom: 1px solid var(--maple-dim);
  font-family: var(--display); font-weight: 700; letter-spacing: 0.1em; font-size: 15px;
  color: var(--cream); text-transform: uppercase;
}
.center .cgames {
  text-align: center; padding: 14px 8px; border-bottom: 1px solid var(--maple-dim);
  font-family: var(--display); font-weight: 800; font-size: 30px; letter-spacing: 0.05em;
  color: var(--cream);
}
.rallies { flex: 1 1 auto; overflow-y: auto; padding: 8px 10px; }
.rallies::-webkit-scrollbar { width: 5px; }
.rallies::-webkit-scrollbar-thumb { background: var(--maple-dim); border-radius: 3px; }
.rally-row {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 5px 4px; border-bottom: 1px dashed rgba(199,154,93,0.12);
}
.rally-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
.rally-next {
  font-family: var(--ui); font-size: 10px; letter-spacing: 0.12em; color: var(--cream-dim);
  border: 1px solid var(--maple-dim); border-radius: 999px; padding: 1px 7px;
}

/* ───────── Footer service band ───────── */
.footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--red); padding: 0 16px; height: 56px; flex-shrink: 0;
  flex-wrap: wrap;
}
.footer .game-lbl {
  font-family: var(--ui); font-size: 12px; font-weight: 700; letter-spacing: 0.28em;
  color: var(--on-red); text-transform: uppercase;
}
.footer .serve-readout {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--ui); font-weight: 700; letter-spacing: 0.04em; font-size: 15px;
  color: var(--on-red);
}
.footer .serve-readout .verb { font-weight: 500; opacity: 0.65; }
.footer .undo {
  font-family: var(--ui); font-size: 12px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--cream);
  background: rgba(20,12,7,0.32); border: 1px solid rgba(20,12,7,0.4);
  padding: 9px 18px; border-radius: 9px;
}
.footer .undo:hover { background: rgba(20,12,7,0.5); }
.foot-actions { display: flex; gap: 8px; }
@media (max-width: 639px) {
  .serve-readout { display: none; }
  .footer { padding: 0 12px; }
  .footer .undo { padding: 9px 13px; }
}

/* ───────── Modals ───────── */
.modal {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center; padding: 18px;
  background: rgba(12,8,4,0.78); backdrop-filter: blur(6px);
}
.modal.open { display: flex; }
.panel {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--maple-dim);
  border-radius: 16px; padding: 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.55);
}
.panel.wide { max-width: 720px; }
.panel h3 {
  margin: 0 0 4px; font-family: var(--display); font-weight: 800;
  font-size: 26px; letter-spacing: 0.03em; color: var(--cream);
}
.panel .sub { margin: 0 0 18px; font-size: 13px; color: var(--cream-dim); letter-spacing: 0.04em; }
.panel h4 {
  margin: 16px 0 10px; font-family: var(--ui); font-size: 12px; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--maple);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--cream-dim);
}
.field select, .field input {
  background: var(--ink); border: 1px solid var(--maple-dim); border-radius: 9px;
  padding: 11px 12px; color: var(--cream); font-size: 15px; outline: none;
}
.field select:focus, .field input:focus { border-color: var(--red); }
.seg { display: inline-flex; border: 1px solid var(--maple-dim); border-radius: 10px; overflow: hidden; }
.seg button {
  flex: 1; background: var(--ink); border: none; color: var(--cream-dim);
  padding: 11px 14px; font-family: var(--ui); font-weight: 600; font-size: 14px;
  letter-spacing: 0.04em;
}
.seg button.active { background: var(--red); color: var(--on-red); }
.choice {
  width: 100%; text-align: left; background: var(--ink); border: 1px solid var(--maple-dim);
  border-radius: 10px; padding: 13px 15px; color: var(--cream); font-size: 14px;
  font-weight: 600; letter-spacing: 0.03em; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
}
.choice:hover { border-color: rgba(199,154,93,0.5); background: var(--surface-2); }
.choice.red { border-color: var(--red); }
.choice .tagdot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* history */
.hist-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.hist-list { margin-top: 12px; }
.hist-item { padding: 14px 0; border-bottom: 1px solid var(--maple-dim); }
.hist-item .top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.hist-item .vs { font-family: var(--display); font-weight: 700; font-size: 19px; color: var(--cream); letter-spacing: 0.03em; }
.hist-item .date { font-size: 11px; color: var(--cream-dim); letter-spacing: 0.08em; white-space: nowrap; }
.hist-item .games { margin-top: 4px; font-size: 12px; color: var(--cream-dim); letter-spacing: 0.06em; }
.hist-item .row-actions { margin-top: 10px; display: flex; gap: 8px; }
.hist-empty { padding: 30px 0; text-align: center; color: var(--cream-dim); font-size: 14px; }
.inprogress { color: var(--red); font-weight: 600; }

/* winner overlay */
.win {
  position: fixed; inset: 0; z-index: 70; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: rgba(12,8,4,0.9); backdrop-filter: blur(10px); text-align: center; padding: 24px;
}
.win.open { display: flex; }
.win .label { font-family: var(--ui); font-size: 13px; letter-spacing: 0.3em; color: var(--cream-dim); text-transform: uppercase; }
.win .who { font-family: var(--display); font-weight: 800; font-size: clamp(40px, 9vw, 92px); color: var(--red); line-height: 0.95; max-width: 94vw; overflow-wrap: anywhere; }
.win .score-line { font-family: var(--display); font-weight: 700; font-size: 24px; color: var(--cream); letter-spacing: 0.06em; }

/* ───────── Tablet / landscape ───────── */
@media (min-width: 760px) and (min-height: 520px) {
  .game-tag { display: none; }
  .serve-tag { bottom: 30px; }
  .topbar { padding: 16px 26px; }
  .board { margin: 0; }
}
@media (max-width: 759px) {
  .game-tag { font-size: 18px; padding: 6px 14px; }
  .center { display: none; }
  .divider { display: none; }
  .topbar { max-height: 60px; padding: 8px 12px; gap: 8px; }
  #desktopActions { display: none; }
  #mobileMenuBtn { display: block; padding: 7px 12px; font-size: 11px; }
  .brand { min-width: auto; }
  .center-top { flex-shrink: 0; }
  .actions { display: none !important; }
  #centerActions { display: none; }
  #mobileFootActions { display: flex !important; order: -1; }
  .footer { padding: 8px 12px; height: auto; gap: 8px; }
  .footer .game-lbl { display: none; }
  .footer .serve-readout { font-size: 12px; margin-left: auto; }
}

/* Force hide desktop actions on small screens */
@media (max-width: 900px) {
  #desktopActions { display: none !important; }
  .actions { display: none !important; }
}

/* Footer layout: left buttons | center undo | right serve */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  gap: 8px;
  flex-wrap: wrap;
}

.footer-left {
  display: flex;
  gap: 6px;
}

.btn-undo {
  background: var(--maple-accent) !important;
  color: var(--cream) !important;
  font-weight: 700 !important;
  flex: 0 1 auto;
  padding: 10px 16px !important;
  border-radius: 6px;
  transition: transform 0.1s;
}

.btn-undo:active {
  transform: scale(0.95);
}

.serve-readout {
  flex: 0 1 auto;
}

/* Score caption */
#scoreCaption {
  color: var(--cream);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Mobile footer adjustments */
@media (max-width: 759px) {
  .footer {
    padding: 8px 10px;
    gap: 6px;
  }
  
  .footer-left {
    gap: 4px;
  }
  
  .footer-left .btn {
    padding: 6px 10px !important;
    font-size: 11px !important;
  }
  
  .btn-undo {
    padding: 8px 12px !important;
    font-size: 12px !important;
  }
  
  .serve-readout {
    font-size: 12px;
  }
}

/* ───────── Modal form fields (setup / options) ───────── */
.panel h3 { margin-bottom: 14px; }
.panel label {
  display: block;
  font-size: 11px; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--cream-dim);
  margin-bottom: 6px;
}
.panel input[type="text"],
.panel input[type="number"],
.panel select {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--maple-dim);
  border-radius: 9px;
  padding: 11px 12px;
  color: var(--cream);
  font-size: 15px;
  outline: none;
}
.panel input[type="text"]:focus,
.panel input[type="number"]:focus,
.panel select:focus { border-color: var(--red); }

/* ───────── Hub link, watermark, phone-landscape layout ───────── */
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.watermark {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 4px 0;
  font-family: var(--ui); font-size: 10px; font-weight: 600;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--cream); opacity: 0.3;
  pointer-events: none; white-space: nowrap;
}
.watermark img.clc { height: 15px; width: auto; display: block; }
.board .watermark {
  position: absolute; left: 10px; top: 8px; bottom: auto; transform: none;
  z-index: 3; padding: 0; opacity: 0.18;
}
.serve-tag, .footer .serve-readout { cursor: pointer; }
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { padding: 6px 12px; }
  #desktopActions, .actions { display: none !important; }
  #mobileMenuBtn { display: block; padding: 6px 10px; font-size: 11px; }
  #centerActions { display: none !important; }
  .game-tag { display: none !important; }
  .board .center { display: flex !important; width: clamp(110px, 18vw, 200px); }
  .board .divider { display: block !important; }
  .score { font-size: clamp(56px, 36vh, 150px); }
  .name-input { font-size: clamp(15px, 5vh, 24px); }
  .serve-tag { display: none !important; }
  .footer { min-height: 44px; height: auto; padding: 4px 10px; }
  .board .watermark { top: 5px; bottom: auto; }
}
/* compact modals in phone landscape (propagated from squash) */
@media (orientation: landscape) and (max-height: 500px) {
  .modal { padding: 8px; align-items: flex-start; padding-top: 6px; }
  .panel { padding: 12px 14px; border-radius: 10px; max-height: 96vh; }
  .panel h3 { font-size: 18px; margin-bottom: 2px; }
  .panel .sub { margin-bottom: 10px; font-size: 11px; }
  .panel h4 { margin: 10px 0 6px; font-size: 11px; }
  .grid2 { gap: 8px; }
  .field select, .field input { padding: 7px 10px; font-size: 14px; }
  .seg button { padding: 7px 10px; font-size: 13px; }
  .modal-foot { margin-top: 12px; }
}

/* ── feature pack: stats table + history empty state ── */
.stat-table { width: 100%; border-collapse: collapse; margin: 6px 0 14px; }
.stat-table th, .stat-table td { padding: 7px 10px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--maple-dim); color: var(--cream); }
.stat-table th { color: var(--maple); font-family: var(--ui); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }
.hist-empty { color: var(--cream-dim); font-size: 13px; padding: 12px 0; }
/* ── color swatch hardening: visibility, selection, focus, forced-colors ── */
#startP1Colors button, #startP2Colors button,
#optP1Colors button, #optP2Colors button {
  outline: 1px solid rgba(239,226,200,0.28);
  outline-offset: -1px;
  forced-color-adjust: none;
  position: relative;
}
#startP1Colors button:focus-visible, #startP2Colors button:focus-visible,
#optP1Colors button:focus-visible, #optP2Colors button:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}
#startP1Colors button.selected, #startP2Colors button.selected,
#optP1Colors button.selected, #optP2Colors button.selected {
  outline: 2px solid var(--cream);
  outline-offset: 1px;
}
#startP1Colors button.selected::after, #startP2Colors button.selected::after,
#optP1Colors button.selected::after, #optP2Colors button.selected::after {
  content: "\2713";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  text-shadow: 0 0 3px rgba(0,0,0,0.9), 0 0 1px rgba(0,0,0,0.9);
  pointer-events: none;
}

/* chainline redesign: broadcast numerals (weight 900, tabular slashed-zero) */
.score { font-weight: 900; font-variant-numeric: tabular-nums slashed-zero; font-feature-settings: "zero" 1, "tnum" 1; }
