:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  background: #a9e663;
  color: #15240d;
  --green: #baf469;
  --muted: #263624;
}
:root[data-countdown="warning"] { background: #ffdc56; }
:root[data-countdown="urgent"] { background: #ff7770; }
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { position: fixed; inset: 0; margin: 0; }
button {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  color: inherit;
  border: 1px solid transparent;
  border-radius: 12px;
  min-height: 44px;
  padding: .55rem .8rem;
}
button:focus-visible, #clock:focus-visible { outline: 3px solid #18231d; outline-offset: 4px; }
button:disabled { cursor: default; opacity: .48; }
#app {
  max-width: 650px;
  height: 100svh;
  margin: auto;
  padding: clamp(12px, 4vw, 28px);
  display: flex;
  flex-direction: column;
  gap: clamp(9px, 2vh, 20px);
  touch-action: none;
  user-select: none;
}
#app > :not(#clock) { flex-shrink: 0; }
header { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .35rem; }
#new-match { justify-self: start; }
#settings { justify-self: end; }
.dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
h1 { margin: 0; width: min(100%, 36vw, 240px); justify-self: center; }
.app-logo { display: block; width: 100%; height: auto; }
.outline { background: #1c2721; color: #f3faf5; border-color: #38483e; font-size: .9rem; }
.scoreboard { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: .5rem; }
.player { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; gap: .45rem; font-weight: 700; }
.player-name { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.versus { color: var(--muted); font-size: .875rem; font-weight: 700; }
.score {
  display: grid;
  place-items: center;
  width: clamp(62px, 23vw, min(112px, 15svh));
  aspect-ratio: 1;
  border-radius: 50%;
  background: #2365bb;
  color: white;
  font-size: clamp(1.65rem, 9vw, 3rem);
  font-variant-numeric: tabular-nums;
}
.active .score { outline: 2px solid #15240d; outline-offset: 3px; }
.score-controls { position: relative; }
.score-minus {
  position: absolute;
  inset-inline-end: -14px;
  bottom: -4px;
  width: 44px;
  padding: 0;
  border-radius: 50%;
  background: #15240d;
  color: white;
  font-size: 1.15rem;
}
.score-minus:disabled { visibility: hidden; }
.turn { background: transparent; color: var(--muted); font-size: .875rem; }
.active .turn { color: #15240d; }
#clock {
  display: grid;
  flex: 0 1 auto;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  align-content: start;
  gap: .35rem;
  padding: 0 0 .5rem;
  border-radius: 22px;
  cursor: pointer;
  touch-action: none;
}
#phase { font-weight: 750; }
.unit { font-size: .875rem; font-weight: 800; letter-spacing: .13em; }
#digits { display: flex; gap: 10px; height: min(45svh, 71vw, 440px); max-height: 100%; }
.digit { height: 100%; aspect-ratio: 100 / 166; position: relative; }
.digit[hidden] { display: none; }
#digits.three-digits { height: min(45svh, 46vw, 315px); }
.segment { position: absolute; inset: 0; background: currentColor; opacity: .085; }
.segment.lit { opacity: 1; }
.a { clip-path: polygon(5% 0,95% 0,80% 9%,20% 9%); }
.b { clip-path: polygon(100% 3%,100% 46%,94% 49%,85% 44%,85% 12%); }
.c { clip-path: polygon(94% 51%,100% 54%,100% 97%,85% 88%,85% 56%); }
.d { clip-path: polygon(20% 91%,80% 91%,95% 100%,5% 100%); }
.e { clip-path: polygon(6% 51%,15% 56%,15% 88%,0 97%,0 54%); }
.f { clip-path: polygon(0 3%,15% 12%,15% 44%,6% 49%,0 46%); }
.g { clip-path: polygon(19% 46%,81% 46%,89% 50%,81% 54%,19% 54%,11% 50%); }
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; margin-top: 8px; }
.controls button { min-height: 56px; font-size: 1.05rem; }
.match-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; }
.extension { background: #263426; color: #e0f7b9; }
#toggle { background: #15240d; color: white; }
.primary { background: var(--green); color: #15240d; }
dialog { max-width: min(90vw, 420px); border: 1px solid #38483e; border-radius: 18px; background: #18231d; color: #f3faf5; padding: 1.25rem; }
dialog h2 { margin: 0; }
#break-screen {
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #15240d;
}
.break-content { min-height: 100%; display: grid; place-content: center; justify-items: center; gap: 1rem; }
#break-time { font-size: min(24vw, 35svh, 12rem); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
#break-status:empty { display: none; }
#rack-result .dialog-actions { margin-top: 1rem; }
#rack-result [data-rack-winner] { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#rack-result .outline { margin-top: .75rem; }
dialog::backdrop { background: #000a; }
.settings-fields { display: grid; gap: .65rem; margin: .8rem 0 1rem; }
.settings-fields label { display: grid; gap: .3rem; }
.settings-fields input, .settings-fields select {
  width: 100%;
  min-height: 44px;
  padding: .45rem .6rem;
  border: 1px solid #687b6e;
  border-radius: 8px;
  background: #101613;
  color: inherit;
  font: inherit;
}
@media (max-width: 420px) { header .outline { padding-inline: .4rem; font-size: .8rem; } }
@media (max-width: 350px) { button { padding-inline: .45rem; } }
@media (max-height: 460px) {
  #app { padding-block: 6px; gap: 5px; }
  .player { gap: .2rem; }
  .score { width: 44px; font-size: 1.35rem; }
  .score-minus { inset-inline-end: -48px; bottom: 0; }
  #clock { padding-bottom: 0; gap: .15rem; }
  .controls { margin-top: 0; }
  .controls button { min-height: 44px; }
}
