:root {
  --blue: #1597e5;
  --blue-dark: #0876bd;
  --blue-soft: #eaf6fe;
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f6f8fb;
  --white: #ffffff;
  --red: #d92d20;
  --soft-red: #fff1f0;
  --green: #067647;
  --radius: 18px;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background-color: var(--bg);
  color-scheme: only light;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }

.topbar {
  min-height: 78px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: env(safe-area-inset-top) calc(28px + env(safe-area-inset-right)) 0 calc(28px + env(safe-area-inset-left));
  gap: 22px;
}

.brand-logo { display:block; width:154px; height:auto; object-fit:contain; }
.section-brand-logo { display:block; width:132px; max-width:42vw; height:auto; margin-bottom:10px; object-fit:contain; }
.results-brand-logo { display:block; width:150px; max-width:48vw; height:auto; margin:0 auto 12px; object-fit:contain; }

.app-title { color: var(--muted); font-weight: 700; }

main {
  max-width: 1450px;
  margin: auto;
  padding: 28px calc(28px + env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) calc(28px + env(safe-area-inset-left));
}

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

h1 {
  margin: 4px 0;
  font-size: clamp(30px, 4vw, 48px);
}

h2 { margin: 0; }
p { color: var(--muted); }

.eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1.4px;
}

.hero, .page-head, .live-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 25px;
  margin-bottom: 24px;
}

.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 17px;
  font-weight: 850;
}

.primary { background: var(--blue); color: #fff; }
.primary:hover { background: var(--blue-dark); }

.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.big { min-height: 54px; font-size: 16px; }
.full { grid-column: 1 / -1; }
.full-width { width: 100%; margin-top: 14px; }

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

label { font-size: 13px; font-weight: 800; }

.field-title {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 8px;
}

input, select {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 46px;
}

.inline { display: flex; gap: 8px; }

.courts {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.courts label {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}

.courts input { width: auto; display: inline; margin: 0 5px 0 0; }

.info, .format-description {
  background: #f2f4f7;
  border-radius: 12px;
  padding: 14px;
  font-size: 14px;
}

.format-description {
  background: var(--blue-soft);
  border: 1px solid #c9e8fb;
  line-height: 1.5;
}

.guide-button { text-align: left; }

.format-guide {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.guide-item {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.guide-item strong { display: block; margin-bottom: 5px; }
.guide-item p { margin: 0; font-size: 13px; line-height: 1.45; }

.format-options {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fbfdff;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.player-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.player-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
}

.player-card input, .player-card select { margin-top: 6px; }

.copied-player-wrap { position:relative; overflow:hidden; border-radius:14px; background:var(--soft-red); touch-action:pan-y; }
.copied-player-wrap .player-card { position:relative; z-index:2; transition:transform .2s ease; }
.copied-player-wrap.reveal .player-card { transform:translateX(-92px); }
.copied-player-remove { position:absolute; z-index:1; top:0; right:0; bottom:0; width:92px; border:0; background:var(--red); color:#fff; font-weight:900; }
.copied-roster-controls { display:flex; align-items:center; justify-content:center; gap:9px; margin-top:16px; color:var(--blue-dark); font-weight:850; }
.add-player-circle { width:42px; height:42px; border-radius:50%; border:0; background:var(--blue); color:#fff; font-size:30px; font-weight:900; line-height:1; box-shadow:0 5px 14px rgba(21,151,229,.28); }

.team-block {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.live-layout {
  display: grid;
  grid-template-columns: 285px 1fr;
  gap: 20px;
}

.leaderboard {
  height: max-content;
  position: sticky;
  top: 15px;
}

.leader-head, .round-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 15px;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 850;
}

.leader-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.leader-details {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.5;
}

.match-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.match-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.match-card.invalid { border: 2px solid var(--red); }

.court-title {
  font-size: 13px;
  font-weight: 950;
  margin-bottom: 10px;
  color: var(--blue-dark);
}

.team-btn {
  width: 100%;
  min-height: 72px;
  border: 0;
  border-radius: 13px;
  background: #f2f4f7;
  padding: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  font-weight: 850;
}

.score { font-size: 30px; font-weight: 950; }

.vs {
  text-align: center;
  padding: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.score-pad {
  background: var(--blue-soft);
  border: 2px solid var(--blue);
  border-radius: 13px;
  padding: 12px;
}

.score-pad-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.score-display {
  background: #fff;
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 29px;
  font-weight: 950;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.key {
  min-height: 52px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  font-size: 20px;
  font-weight: 900;
}

.key.zero { grid-column: span 2; }

.resting { margin-top: 14px; }
.player-manage-link { text-decoration: none; cursor: pointer; }
.player-manage-tip { margin-bottom:10px; padding:9px 10px; border-radius:9px; background:var(--blue-soft); color:var(--blue-dark); font-size:12px; line-height:1.4; }
.inactive-player { opacity: .68; }
.inactive-badge { font-size: .72rem; font-weight: 800; margin-left: 6px; color: var(--muted); }
.podium-tie { margin:-4px 0 10px; color:var(--blue-dark); font-size:.72rem; font-weight:900; letter-spacing:.08em; }

.round-navigation { display:flex; align-items:center; gap:10px; }
.round-navigation h2 { min-width:0; margin:0; }
.round-arrow {
  display:inline-flex;
  flex:0 0 48px;
  align-items:center;
  justify-content:center;
  width:48px;
  min-width:48px;
  height:48px;
  min-height:48px;
  aspect-ratio:1;
  padding:0;
  border:1px solid var(--line);
  border-radius:50%;
  background:#fff;
  color:var(--blue);
  line-height:0;
}
.round-chevron { display:block; width:20px; height:20px; overflow:visible; }
.round-chevron path { fill:none; stroke:currentColor; stroke-width:2.6; stroke-linecap:round; stroke-linejoin:round; }
.round-chevron-left { transform:scaleX(-1); }
.preview-return { margin-top:5px; }
.preview-match .team-btn { cursor:default; }
.preview-match .score { opacity:.7; }
.preview-match.historical-editable .team-btn { cursor:pointer; }
.preview-match.historical-editable .score { opacity:1; }

.error {
  background: var(--soft-red);
  border: 2px solid var(--red);
  color: var(--red);
  border-radius: 12px;
  padding: 14px;
  margin-top: 12px;
}

.success {
  background: #ecfdf3;
  border: 1px solid #abefc6;
  color: var(--green);
  border-radius: 12px;
  padding: 12px;
}

.why { margin-top: 15px; line-height: 1.65; }
.small { color: var(--muted); font-size: 12px; }

.saved-wrap {
  position: relative;
  overflow: visible;
  border-radius: 16px;
  margin-bottom: 10px;
}

.saved-card {
  position: relative;
  z-index: 2;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 17px;
  padding-right: 66px;
}
.saved-menu-btn { position:absolute; right:10px; top:50%; z-index:4; width:48px; height:48px; transform:translateY(-50%); border:1px solid var(--line); border-radius:12px; background:#fff; color:var(--ink); font-size:28px; line-height:1; font-weight:900; }
.saved-menu { position:absolute; right:10px; top:calc(50% + 28px); z-index:10; min-width:150px; overflow:hidden; border:1px solid var(--line); border-radius:12px; background:#fff; box-shadow:var(--premium-shadow); }
.saved-menu button { display:block; width:100%; min-height:46px; padding:10px 14px; border:0; border-bottom:1px solid var(--line); background:#fff; text-align:left; font-weight:800; }
.saved-menu button:last-child { border-bottom:0; }
.saved-menu .danger-text { color:var(--red); }

.player-manage-modal { width:min(430px,calc(100vw - 28px)); background:#fff; border-radius:22px; padding:24px; box-shadow:var(--premium-shadow); }
.player-manage-modal h2 { margin:8px 0 20px; }
.rename-tournament-modal { text-align:left; }
.live-name-button {
  display:block;
  max-width:100%;
  min-height:48px;
  margin:4px 0;
  padding:0 34px 0 0;
  border:0;
  background:transparent;
  color:var(--ink);
  font-size:clamp(30px,4vw,48px);
  font-weight:900;
  line-height:1.1;
  letter-spacing:-.025em;
  text-align:left;
  overflow-wrap:anywhere;
  position:relative;
}
.live-name-button::after {
  content:"";
  position:absolute;
  right:5px;
  top:50%;
  width:14px;
  height:14px;
  border-right:3px solid var(--blue);
  border-bottom:3px solid var(--blue);
  transform:translateY(-65%) rotate(-45deg);
  opacity:.8;
}
.live-name-button:hover { color:var(--blue-dark); }
.player-manage-actions { display:grid; gap:10px; }
.player-manage-actions.horizontal { grid-template-columns:1fr 1fr; margin-top:14px; }
.btn.danger { background:#b42318; color:#fff; border-color:#b42318; }

.saved-title { font-weight: 900; font-size: 16px; }
.saved-meta { color: var(--muted); font-size: 12px; margin-top: 5px; }

.empty {
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 30px;
  text-align: center;
  color: var(--muted);
}

.results { text-align: center; }
.winner-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 118px;
  min-height: 42px;
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 15px;
  font-weight: 950;
  letter-spacing: 1.5px;
  margin-bottom: 8px;
}

.podium {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
  max-width: 1050px;
  margin: 24px auto;
}

.podium-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  text-align: left;
}

.podium-card.rank-1 { border-color:#d8ad2f; background:linear-gradient(155deg,#fffdf3 0%,#fff 72%); box-shadow:0 18px 42px rgba(180,135,20,.17); }
.podium-card.rank-2 { border-color:#aeb8c6; background:linear-gradient(155deg,#f8fafc 0%,#fff 72%); }
.podium-card.rank-3 { border-color:#b97843; background:linear-gradient(155deg,#fff8f3 0%,#fff 72%); }
.podium-rank-head { display:flex; align-items:center; gap:13px; min-height:52px; }
.podium-icon-wrap { display:grid; place-items:center; flex:0 0 48px; width:48px; height:48px; border-radius:14px; color:#9a6b00; background:#fff0ad; }
.rank-2 .podium-icon-wrap { color:#687386; background:#e8edf3; }
.rank-3 .podium-icon-wrap { color:#8a4d27; background:#f4d5bd; }
.podium-icon { display:block; width:31px; height:31px; fill:currentColor; }
.podium-rank-label { font-size:18px; line-height:1.15; font-weight:950; letter-spacing:.045em; }
.podium-rank-note { margin:5px 0 0; color:var(--muted); font-size:12px; line-height:1.4; }
.podium-members { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:8px; margin-top:14px; }
.podium-member { min-width:0; padding:12px 13px; border:1px solid rgba(16,24,40,.08); border-radius:12px; background:rgba(255,255,255,.78); }
.podium-member h2 { margin:0 0 6px; font-size:clamp(18px,2.2vw,23px); line-height:1.25; overflow-wrap:anywhere; }
.podium-member strong { display:block; color:var(--blue-dark); font-size:14px; line-height:1.3; }
.podium-card { animation:podiumArrival .42s ease-out both; }
.podium-card:nth-child(2) { animation-delay:.06s; }
.podium-card:nth-child(3) { animation-delay:.12s; }
.podium-card:nth-child(n+4) { animation-delay:.16s; }
@keyframes podiumArrival { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }

.final-board {
  max-width: 700px;
  margin: 0 auto 25px;
}

.final-ranking-info { max-width:700px; margin:0 auto 25px; text-align:left; }
.final-ranking-info summary { cursor:pointer; min-height:48px; display:flex; align-items:center; justify-content:space-between; gap:14px; font-weight:900; color:var(--blue-dark); list-style:none; }
.final-ranking-info summary::-webkit-details-marker { display:none; }
.final-ranking-info summary::after { content:"+"; font-size:24px; line-height:1; }
.final-ranking-info[open] summary::after { content:"\2212"; }
.final-ranking-info p { margin:12px 0 0; line-height:1.55; }
.final-ranking-info ol { margin:12px 0 0; padding-left:24px; color:var(--muted); line-height:1.6; }

@media (max-width: 900px) {
  main { padding: 17px calc(17px + env(safe-area-inset-right)) calc(17px + env(safe-area-inset-bottom)) calc(17px + env(safe-area-inset-left)); }
  .hero { flex-direction: column; align-items: flex-start; }
  .setup-grid, .player-grid, .live-layout, .match-grid, .guide-grid, .team-block, .option-grid {
    grid-template-columns: 1fr;
  }
  .courts { grid-template-columns: repeat(3, 1fr); }
  .leaderboard { position: static; }
  .topbar { padding: env(safe-area-inset-top) calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left)); }
  .brand-logo { width:136px; }
}

@media (max-width: 640px) {
  .podium { grid-template-columns:1fr; }
  .podium-members { grid-template-columns:1fr; }
}

.podium-card:first-child:not(.rank-1) {
  border-color: var(--blue);
  box-shadow: 0 10px 30px rgba(21, 151, 229, .12);
}

.exact-note-title {
  display: block;
  font-weight: 950;
  margin-bottom: 4px;
}


.rule-card {
  border: 1px solid #dbe7f0;
  background: linear-gradient(180deg, #fbfdff 0%, #f6fbff 100%);
  border-radius: 14px;
  padding: 14px 15px;
  line-height: 1.55;
  color: var(--ink);
  font-size: 13px;
}

.rule-card strong {
  display: block;
  color: var(--blue-dark);
  margin-bottom: 4px;
  font-size: 13px;
}

.rule-card .rule-sequence {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.rule-card.is-rally {
  border-color: #cfe8d8;
  background: #f5fbf7;
}

.rule-card.is-rally strong {
  color: var(--green);
}

/* V7.4 premium finish */
:root{--premium-shadow:0 18px 50px rgba(15,23,42,.09);--premium-shadow-soft:0 8px 28px rgba(15,23,42,.065)}
.card,.podium-card,.match-card,.saved-card{box-shadow:var(--premium-shadow-soft)}
.btn{transition:transform .16s ease,box-shadow .16s ease,filter .16s ease}
.btn:active{transform:translateY(1px) scale(.992)}
.btn.primary{box-shadow:0 10px 24px rgba(24,157,224,.20)}
input,select,button{-webkit-tap-highlight-color:transparent}
.results::before{content:"";display:block;width:72px;height:5px;margin:0 auto 22px;border-radius:999px;background:linear-gradient(90deg,#111827 0 48%,#189de0 48% 100%)}
.results>h1{letter-spacing:-.035em}
.podium-card{position:relative;overflow:hidden;border:1px solid rgba(24,157,224,.12)}
.podium-card:first-child:not(.rank-1){box-shadow:var(--premium-shadow)}
.thank-you-card{margin:28px auto 24px;padding:30px 24px 28px;max-width:760px;text-align:center;background:linear-gradient(145deg,#fff 0%,#f7fbfe 100%);border:1px solid rgba(24,157,224,.20);border-radius:24px;box-shadow:var(--premium-shadow)}
.thank-you-card p{margin:0 auto;max-width:620px;line-height:1.6}
.thank-you-card #thankYouMessage{font-size:1.08rem}
.thank-you-close{margin-top:12px!important;font-weight:700}
.thank-you-love{margin-top:24px;color:#6b7280;font-size:.92rem;font-weight:700;text-transform:uppercase;letter-spacing:.14em}
.thank-you-logo{display:block;width:138px;max-width:52vw;height:auto;object-fit:contain;margin:10px auto 0}
@media(max-width:640px){.thank-you-card{padding:25px 18px 24px;border-radius:20px}}

/* V7.5 round timer and save feedback */
.round-timer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 16px;
  padding: 14px 16px;
}
.timer-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 1.3px;
}
.timer-inline-display {
  margin-top: 2px;
  font-size: 28px;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}
.saved-status {
  align-self: center;
  min-width: 62px;
  color: var(--green);
  font-size: 13px;
  font-weight: 850;
  opacity: 0;
  transition: opacity .2s ease;
}
.saved-status.show { opacity: 1; }
.timer-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16,24,40,.86);
  backdrop-filter: blur(5px);
}
.timer-modal {
  width: min(680px, 100%);
  background: var(--white);
  border-radius: 28px;
  padding: 36px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
}
.timer-round-name {
  margin-top: 8px;
  color: var(--ink);
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 900;
}
.timer-overlay-display {
  margin: 16px 0;
  font-size: clamp(72px, 16vw, 150px);
  line-height: .95;
  font-weight: 950;
  letter-spacing: -5px;
  font-variant-numeric: tabular-nums;
}
.times-up {
  margin: 10px 0 22px;
  color: var(--red);
  font-size: clamp(38px, 8vw, 72px);
  font-weight: 1000;
  letter-spacing: 1px;
}
@media (max-width: 650px) {
  .round-timer { align-items: stretch; flex-direction: column; }
  .round-timer .btn { width: 100%; }
  .timer-modal { padding: 28px 18px; }
  .timer-overlay-display { letter-spacing: -3px; }
}


/* V7.6 tournament-duration planning and timer-start protection */
.timing-plan {
  background: linear-gradient(135deg, #eef8ff, #f8fcff);
  border: 1px solid #bfe3f8;
  border-radius: 14px;
  padding: 16px;
  line-height: 1.5;
}
.timing-plan-title {
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .4px;
  margin-bottom: 5px;
  text-transform: uppercase;
}
.timing-plan .btn { margin-top: 12px; }
#useSuggestedTimeBtn.is-used {
  background: #ecfdf3;
  border-color: #abefc6;
  color: var(--green);
}
.timer-reminder {
  margin-top: 8px;
  color: var(--red);
  font-size: 14px;
  font-weight: 900;
}
.timer-attention {
  border: 2px solid var(--red) !important;
  box-shadow: 0 0 0 5px rgba(217,45,32,.10);
  animation: timerNudge .55s ease 2;
}
@keyframes timerNudge {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}


/* V7.8 linked timing / round recommendation layout */
.suggest-field { min-width: 0; }
.suggest-field > label { display:block; }
.suggest-row { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:10px; align-items:end; }
.suggest-row input { margin-top:7px; }
.suggest-btn { min-height:46px; margin-top:7px; padding-inline:16px; white-space:nowrap; }
.suggest-field small { display:block; margin-top:7px; }
@media (max-width:640px){ .suggest-row{grid-template-columns:minmax(0,1fr) auto}.suggest-btn{padding-inline:13px} }


/* V8.0 unified Smart Timing */
.timing-suggest-btn {
  width: 100%;
  margin-top: 14px;
}
#roundMinutes {
  font-variant-numeric: tabular-nums;
}
.timer-controls { display:flex; gap:10px; justify-content:center; margin:18px 0 12px; flex-wrap:wrap; }
.timer-controls .btn { min-width:110px; }
#timerWarning { margin-top:10px; font-weight:800; letter-spacing:.08em; }
#timerWarning.timer-warning-flashing {
  animation-name: finalMinuteTextFlash;
  animation-duration: 800ms;
  animation-timing-function: step-end;
  animation-iteration-count: 4;
  animation-fill-mode: both;
}
@keyframes finalMinuteTextFlash {
  0%, 49.999% { opacity:1; }
  50%, 100% { opacity:0; }
}
#transitionCountdown { margin-top:6px; }

/* V8.1 bring stale Smart Timing back into view after scoring-rule changes */
#timingPlan.timing-recalc-focus {
  border-color: #2f80ed;
  box-shadow: 0 0 0 5px rgba(47,128,237,.14), 0 12px 30px rgba(16,42,67,.10);
  animation: timingRecalcFocus 1.2s ease;
}
@keyframes timingRecalcFocus {
  0% { transform: scale(.992); }
  45% { transform: scale(1.008); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  #timingPlan.timing-recalc-focus { animation: none; }
  .podium-card { animation:none; }
}

/* Pass 1: restrained tablet-first design system */
:root {
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --control-height: 50px;
  --touch-height: 48px;
  --border-control: #d5dbe4;
  --surface-muted: #f8fafc;
  --surface-selected: #f0f9ff;
  --shadow-card: 0 8px 24px rgba(16,24,40,.055);
  --shadow-raised: 0 12px 30px rgba(16,24,40,.09);
  --shadow-selected: 0 8px 22px rgba(21,151,229,.15);
  --focus-ring: 0 0 0 4px rgba(21,151,229,.14);
  --motion-fast: 160ms;
}

body {
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main, .screen, .setup-grid > *, .live-layout > *, .match-grid > * { min-width: 0; }

.topbar {
  box-shadow: 0 1px 0 rgba(16,24,40,.025);
}

.card, .match-card, .saved-card {
  border-color: rgba(16,24,40,.095);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.btn, .text-btn, .round-arrow, .saved-menu-btn, .add-player-circle {
  min-height: var(--touch-height);
  transition: transform var(--motion-fast) ease, border-color var(--motion-fast) ease,
    background-color var(--motion-fast) ease, color var(--motion-fast) ease,
    box-shadow var(--motion-fast) ease, opacity var(--motion-fast) ease;
}

.btn {
  border-radius: var(--radius-md);
  letter-spacing: -.01em;
}

.btn.primary {
  background: var(--blue);
  box-shadow: 0 8px 20px rgba(21,151,229,.22);
}

.btn.secondary {
  background: #fff;
  border-color: var(--border-control);
  box-shadow: 0 2px 6px rgba(16,24,40,.035);
}

.btn:active, .text-btn:active, .round-arrow:active, .saved-menu-btn:active,
.add-player-circle:active, .courts label:active {
  transform: translateY(1px) scale(.985);
}

button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible,
.courtCheck:focus-visible + span {
  outline: none;
}

button:focus-visible, summary:focus-visible { box-shadow: var(--focus-ring); }

button:disabled {
  opacity: .46;
  filter: saturate(.65);
  box-shadow: none !important;
}

input, select {
  min-height: var(--control-height);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  background-color: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(16,24,40,.025);
  transition: border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease,
    background-color var(--motion-fast) ease;
}

input:hover, select:hover { border-color: #b9c3d0; }

input:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: var(--focus-ring), 0 2px 7px rgba(16,24,40,.04);
}

input:disabled, select:disabled {
  color: #8a94a3;
  background: #f2f4f7;
  cursor: not-allowed;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='m6 8 4 4 4-4' stroke='%23667085' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.field-title, .setup-grid > label, .player-card label {
  color: #344054;
  letter-spacing: .01em;
}

.format-description, .rule-card, .timing-plan, .info {
  border-radius: var(--radius-md);
}

.format-description {
  border-color: rgba(21,151,229,.22);
  background: #f2f9fe;
}

.timing-plan {
  border-color: rgba(21,151,229,.25);
  background: #f6fbff;
}

/* The native checkboxes remain accessible; the complete card is the control. */
.courts { gap: 12px; }

.courts label {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 66px;
  padding: 14px 10px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  color: #344054;
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 7px rgba(16,24,40,.035);
  transition: transform var(--motion-fast) ease, border-color var(--motion-fast) ease,
    background-color var(--motion-fast) ease, color var(--motion-fast) ease,
    box-shadow var(--motion-fast) ease;
}

.courts input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.courts label.is-selected {
  border-color: var(--blue);
  background: var(--surface-selected);
  color: var(--blue-dark);
  box-shadow: var(--shadow-selected);
  transform: translateY(-1px) scale(1.012);
}

.courts label:has(.courtCheck:focus-visible) {
  border-color: var(--blue);
  box-shadow: var(--focus-ring), var(--shadow-selected);
}

.player-card {
  border: 1px solid rgba(16,24,40,.09);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: 0 3px 10px rgba(16,24,40,.035);
}

.team-btn {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  transition: transform var(--motion-fast) ease, border-color var(--motion-fast) ease,
    background-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease;
}

.team-btn:active { transform: scale(.992); }
.team-btn:focus-visible { border-color: var(--blue); box-shadow: var(--focus-ring); outline: none; }

.saved-menu, .player-manage-modal, .timer-modal {
  border: 1px solid rgba(255,255,255,.25);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 70px rgba(16,24,40,.25);
}

.saved-menu { border-color: rgba(16,24,40,.11); border-radius: var(--radius-md); }
.saved-menu button { transition: background-color var(--motion-fast) ease, color var(--motion-fast) ease; }
.saved-menu button:active { background: var(--blue-soft); }

.timer-overlay:not(.hidden) { animation: overlayFade var(--motion-fast) ease-out; }
.timer-overlay:not(.hidden) > * { animation: modalEnter 180ms ease-out; }
@keyframes overlayFade { from { opacity:0; } }
@keyframes modalEnter { from { opacity:0; transform:translateY(8px) scale(.992); } }

.final-box-badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 25px;
  margin-top: 8px;
  padding: 4px 9px;
  border: 1px solid rgba(21,151,229,.22);
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.final-result-row { align-items: center; min-height: 58px; }
.final-result-player { display:flex; flex-direction:column; align-items:flex-start; min-width:0; }
.final-result-row .final-box-badge { margin-top:4px; }

.beat-draw-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: -2px 0 16px;
  padding: 12px 14px;
  border: 1px solid #f0d58b;
  border-radius: var(--radius-md);
  background: #fffbeb;
  color: #7a5211;
  font-size: 12px;
  line-height: 1.5;
}

.beat-draw-notice strong { flex:0 0 auto; }

.final-ranking-info {
  overflow: hidden;
  transition: box-shadow var(--motion-fast) ease, border-color var(--motion-fast) ease;
}
.final-ranking-info[open] { border-color: rgba(21,151,229,.28); box-shadow: var(--shadow-raised); }
.final-ranking-info[open] #finalRankingExplanation { animation: detailsEnter 180ms ease-out; }
@keyframes detailsEnter { from { opacity:0; transform:translateY(-4px); } }

@media (hover:hover) {
  .btn.primary:hover { background: var(--blue-dark); transform: translateY(-1px); }
  .btn.secondary:hover { border-color: #b9c3d0; background: #fbfcfd; }
  .courts label:hover { border-color: #b8c7d8; box-shadow: 0 6px 16px rgba(16,24,40,.065); }
  .courts label.is-selected:hover { border-color: var(--blue-dark); box-shadow: var(--shadow-selected); }
  .saved-menu button:hover { background: #f8fafc; }
}

@media (min-width: 901px) and (max-width: 1180px) {
  .live-layout { grid-template-columns: 260px minmax(0,1fr); }
  .match-grid { gap: 12px; }
}

@media (max-width: 900px) {
  .courts label { min-height: 62px; }
  .actions .btn { min-height: 50px; }
  .timer-overlay { padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
}

@media (max-width: 640px) {
  .courts { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .beat-draw-notice { flex-direction:column; gap:3px; }
  .final-result-row { align-items:flex-start; }
  .round-navigation { gap:8px; }
  .round-navigation h2 { font-size:clamp(18px,5.5vw,24px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior:auto !important; animation-duration:.01ms !important; animation-iteration-count:1 !important; transition-duration:.01ms !important; }
  .courts label.is-selected { transform:none; }
}
:root .rotation-status{margin-top:12px;padding:11px 14px;border:1px solid #a2ccea;border-radius:12px;background:#edf6ff;color:#164a72;line-height:1.4;font-size:14px}
:root .rotation-status strong{display:block;font-size:15px;margin-bottom:3px}
:root .rotation-status.perfect{border-color:#95c9ad;background:#eaf7ef;color:#185b38}
