:root {
  color-scheme: dark;
  font-family: Arial, Helvetica, sans-serif;
  background: #15191d;
  color: #fff;
  font-synthesis: none;
  --mint: #5ca595;
  --mint-bright: #6fd2be;
  --panel: #2b2b40;
  --field: #303847;
  --dark: #252a38;
  --ink: #18172e;
}

@property --spent {
  syntax: "<angle>";
  inherits: true;
  initial-value: 0deg;
}

* { box-sizing: border-box; }

html, body, #app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button, input { font: inherit; letter-spacing: 0; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: 100%;
  height: 100%;
  min-height: 320px;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--mint);
}

.setup-panel, .menu-panel {
  width: min(430px, 92vw);
  max-height: calc(100vh - 24px);
  padding: clamp(14px, 3vh, 28px);
  display: grid;
  gap: clamp(7px, 1.5vh, 12px);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 34px rgb(18 24 30 / 24%);
}

.app-title {
  margin: 0 0 2px;
  text-align: center;
  font-size: clamp(24px, 5vh, 38px);
  line-height: 1;
  font-weight: 800;
}

.field, .primary-button, .secondary-button {
  width: 100%;
  min-height: clamp(38px, 7vh, 52px);
  border: 0;
  border-radius: 7px;
  color: #fff;
}

.field {
  padding: 0 18px;
  text-align: center;
  background: var(--field);
  outline: 2px solid transparent;
}

.field:focus { outline-color: var(--mint-bright); }
.primary-button { background: var(--dark); font-size: clamp(17px, 3.3vh, 23px); }
.secondary-button { background: var(--field); font-size: clamp(15px, 2.8vh, 19px); }
button:active { transform: scale(.985); filter: brightness(1.12); }

.score-screen {
  position: relative;
  width: min(100%, 1500px);
  height: min(100%, 900px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(7px, 1.5vh, 14px);
  align-items: center;
}

.score-actions { display: flex; justify-content: center; gap: 10px; }
.small-button {
  min-width: 82px;
  min-height: 34px;
  padding: 8px 16px;
  border: 0;
  border-radius: 7px;
  background: #39776d;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.board-wrap {
  position: relative;
  width: min(100%, 1500px);
  aspect-ratio: 1.93 / 1;
  max-height: 100%;
  justify-self: center;
  background: center / contain no-repeat url("../assets/background_no_player.png");
}

.board-wrap.player-0 { background-image: url("../assets/background_player_1.png"); }
.board-wrap.player-1 { background-image: url("../assets/background_player_2.png"); }

.checkout-suggestions {
  position: absolute;
  top: 36.4%;
  width: 16.3%;
  aspect-ratio: 302 / 375;
  z-index: 4;
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  color: #fff;
  font-size: clamp(11px, 2vw, 32px);
  font-weight: 800;
  text-shadow: 0 2px 3px rgb(0 0 0 / 50%);
  pointer-events: none;
}

.checkout-suggestions::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: center / 100% 100% no-repeat url("../assets/sugestii.png");
}

.checkout-suggestions.left {
  left: 2.7%;
  animation: checkout-in-left 320ms ease-out both;
}

.checkout-suggestions.right {
  right: 2.7%;
  animation: checkout-in-right 320ms ease-out both;
}

.checkout-suggestions.right::before { transform: scaleX(-1); }

.checkout-suggestions span {
  position: absolute;
  left: 50%;
  translate: -50% -50%;
  opacity: 0;
  animation: checkout-text-in 220ms 300ms ease-out forwards;
}

.checkout-suggestions span:nth-child(1) { top: 18.5%; }
.checkout-suggestions span:nth-child(2) { top: 50.4%; }
.checkout-suggestions span:nth-child(3) { top: 81.9%; }
.checkout-suggestions.left span:nth-child(2) { left: 45.5%; }
.checkout-suggestions.right span:nth-child(2) { left: 54.5%; }

@keyframes checkout-in-left {
  from { opacity: 0; transform: translateX(-110%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes checkout-in-right {
  from { opacity: 0; transform: translateX(110%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes checkout-text-in {
  to { opacity: 1; }
}

.player-name, .score, .legs, .match-label, .starter-dart {
  position: absolute;
  text-align: center;
  text-shadow: 0 2px 4px rgb(0 0 0 / 35%);
}

.progress-ring {
  --spent: 0deg;
  --ring-width: clamp(7px, .82vw, 14px);
  position: absolute;
  top: 36.4%;
  width: 20.3%;
  aspect-ratio: 1;
  z-index: 1;
  border-radius: 50%;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgb(16 65 58 / 24%));
  transition: --spent 850ms cubic-bezier(.2, .75, .2, 1);
}
.progress-ring.left { left: 18.25%; }
.progress-ring.right { left: 62.25%; }

.progress-ring::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(transparent 0deg var(--spent), var(--mint-bright) var(--spent) 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--ring-width)), #000 calc(100% - var(--ring-width) + 1px));
  mask: radial-gradient(farthest-side, transparent calc(100% - var(--ring-width)), #000 calc(100% - var(--ring-width) + 1px));
}

.progress-ring::after,
.progress-cap::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: var(--ring-width);
  height: var(--ring-width);
  border-radius: 50%;
  background: var(--mint-bright);
  transform: translateX(-50%);
}

.progress-cap {
  position: absolute;
  inset: 0;
  transform: rotate(var(--spent));
}

.progress-ring.empty::after,
.progress-ring.empty .progress-cap { opacity: 0; }

.player-name {
  top: 25%;
  width: 29%;
  font-size: clamp(15px, 3.1vw, 54px);
  font-weight: 800;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.player-name.left { left: 21%; }
.player-name.right { right: 21%; }

.score {
  top: 48%;
  width: 18%;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: clamp(28px, 6.5vw, 96px);
  line-height: 1;
  font-style: italic;
  font-weight: 800;
  cursor: pointer;
  z-index: 2;
}
.score.left { left: 19.4%; }
.score.right { right: 19.4%; }
.score[disabled] { cursor: default; }

.match-label {
  top: 42%;
  left: 41%;
  width: 18%;
  font-size: clamp(13px, 2.8vw, 42px);
  line-height: 1.15;
}
.legs { top: 61%; width: 8%; font-size: clamp(24px, 5vw, 76px); font-style: italic; font-weight: 700; }
.legs.left { left: 40%; }
.legs.right { right: 40%; }

.starter-dart {
  top: 63%;
  width: 5%;
  aspect-ratio: 1;
  background: center / contain no-repeat url("../assets/dart_grey.png");
}
.starter-dart.left { left: 26%; }
.starter-dart.right { right: 26%; }

.online-badge {
  position: absolute;
  left: 50%;
  top: 30%;
  translate: -50% 0;
  padding: 5px 10px;
  border-radius: 6px;
  background: rgb(37 42 56 / 84%);
  font-size: clamp(9px, 1.5vw, 14px);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(15 20 24 / 67%);
}

.score-modal {
  width: min(440px, 94vw);
  padding: 18px;
  border-radius: 8px;
  background: #8c9691;
  box-shadow: 0 20px 50px rgb(0 0 0 / 35%);
}

.score-display {
  width: 100%;
  height: 58px;
  margin-bottom: 12px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--field);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
}

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.keypad button {
  min-height: 54px;
  border: 0;
  border-radius: 7px;
  background: var(--field);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
}

.status {
  min-height: 20px;
  margin: 0;
  text-align: center;
  color: #d8fff6;
  font-size: 14px;
}

.board-code {
  margin: 3px 0;
  text-align: center;
  font-size: clamp(36px, 9vw, 64px);
  font-weight: 800;
  letter-spacing: 6px;
}

.checkout-question {
  width: min(520px, 94vw);
  padding: 24px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 50px rgb(0 0 0 / 35%);
  text-align: center;
}

.checkout-question h2 {
  margin: 0 0 20px;
  font-size: clamp(18px, 3vw, 25px);
}

.checkout-choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.checkout-choices button {
  min-height: 64px;
  border: 0;
  border-radius: 7px;
  background: var(--field);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
}

.stats-screen {
  position: relative;
  width: min(100%, 1500px);
  aspect-ratio: 1.93 / 1;
  max-height: 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}

.stats-screen.winner-left { background-image: url("../assets/match_stats_winner_left.png"); }
.stats-screen.winner-right { background-image: url("../assets/match_stats_winner_right.png"); }

.stats-name,
.stats-value {
  position: absolute;
  translate: -50% -50%;
  color: #fff;
  text-shadow: 0 2px 4px rgb(0 0 0 / 35%);
  font-weight: 800;
  white-space: nowrap;
}

.stats-name {
  top: 29.3%;
  max-width: 28%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(18px, 4vw, 64px);
}
.stats-name.left { left: 34%; }
.stats-name.right { left: 66%; }

.stats-value {
  font-size: clamp(15px, 2.5vw, 40px);
}
.stats-value.left { left: 27.5%; }
.stats-value.right { left: 72.5%; }
.stats-value.row-1 { top: 39.7%; }
.stats-value.row-2 { top: 48.7%; }
.stats-value.row-3 { top: 57.8%; }
.stats-value.row-4 { top: 66.8%; }
.stats-value.row-5 { top: 75.8%; }

.new-match-button {
  position: absolute;
  left: 50%;
  top: 90.5%;
  translate: -50% -50%;
  min-width: 132px;
  min-height: 42px;
  padding: 9px 18px;
  border: 0;
  border-radius: 7px;
  background: #39776d;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

@media (orientation: portrait) {
  .app-shell::before {
    content: "Rotate your device";
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background: #202532;
    color: #fff;
    font-size: 24px;
    font-weight: 700;
  }
}

@media (max-height: 480px) {
  .setup-panel, .menu-panel { padding: 10px 18px; gap: 5px; }
  .app-title { font-size: 24px; }
  .field, .primary-button, .secondary-button { min-height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
