:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #151920;
  --panel-soft: #1b2028;
  --text: #f4f1e9;
  --muted: #a9b0bb;
  --line: #303846;
  --accent: #32c28d;
  --accent-strong: #52d6a4;
  --danger: #c94b54;
  --gold: #d9a83a;
  --silver: #b7c0cc;
  --bronze: #b67845;
  --button: #26313f;
  --button-hover: #313d4d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 20px;
}

.is-playing .app-header {
  display: none;
}

.eyebrow,
.turn-kicker {
  margin: 0 0 2px;
  color: var(--accent-strong);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: 2.45rem;
}

h2 {
  font-size: 1.35rem;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

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

.panel,
.turn-panel,
.throw-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, black);
  box-shadow: 0 22px 46px rgba(0, 0, 0, 0.23);
}

.panel {
  padding: 18px;
}

.panel-heading,
.player-panel-heading,
.game-topbar,
.action-row,
.inline-control,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-group {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

label,
.field-group > label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.score-presets {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.segment-option,
.score-option,
.secondary-button,
.ghost-button,
.primary-button,
.icon-button,
.mini-button,
.dart-slot {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button);
  color: var(--text);
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
  touch-action: manipulation;
}

.segment-option:hover,
.score-option:hover,
.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover,
.mini-button:hover,
.dart-slot:hover {
  background: var(--button-hover);
}

.segment-option.selected,
.score-option.selected,
.dart-slot.selected {
  border-color: var(--accent);
  background: rgba(50, 194, 141, 0.18);
}

.primary-button {
  width: 100%;
  min-height: 52px;
  border-color: rgba(82, 214, 164, 0.62);
  background: var(--accent);
  color: #06130d;
  font-weight: 900;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button,
.ghost-button {
  padding: 0 14px;
  font-weight: 800;
}

.ghost-button {
  background: transparent;
}

.icon-button,
.mini-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 1.35rem;
  font-weight: 900;
}

.inline-control {
  align-items: stretch;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1218;
  color: var(--text);
  padding: 0 12px;
}

input:focus,
button:focus-visible,
.board-field:focus-visible,
.bull:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 3px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  color: var(--text);
}

.toggle-row input {
  width: 24px;
  min-height: 24px;
  accent-color: var(--accent);
}

.players-list {
  display: grid;
  gap: 9px;
  margin: 18px 0;
}

.player-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.game-topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 6px 0;
  background: linear-gradient(var(--bg), rgba(11, 13, 16, 0.86));
  backdrop-filter: blur(10px);
}

.desktop-overview {
  display: none;
}

.game-sidebar {
  display: contents;
}

.turn-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 12px;
  padding: 12px 14px 12px 18px;
  border-color: rgba(82, 214, 164, 0.8);
  background: #111820;
  box-shadow: 0 0 0 1px rgba(82, 214, 164, 0.16), 0 22px 46px rgba(0, 0, 0, 0.3);
}

.turn-panel::before {
  position: absolute;
  inset: 10px auto 10px 0;
  width: 4px;
  border-radius: 0 999px 999px 0;
  background: var(--accent);
  content: "";
}

.turn-panel .turn-kicker {
  grid-column: 1;
  grid-row: 1;
}

.turn-panel h2 {
  grid-column: 1;
  grid-row: 2;
}

.turn-panel h2 {
  color: #fff8ec;
  font-size: 1.7rem;
  font-weight: 950;
  overflow-wrap: anywhere;
}

.score-line {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  min-width: 104px;
  padding: 8px 11px;
  border: 1px solid rgba(82, 214, 164, 0.75);
  border-radius: 8px;
  background: rgba(50, 194, 141, 0.14);
  box-shadow: inset 0 0 0 1px rgba(82, 214, 164, 0.08);
}

.score-line span:first-child {
  color: #fff8ec;
  font-size: 2rem;
  font-weight: 950;
  line-height: 1;
}

.score-line span:last-child {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.turn-message {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.turn-message:empty {
  display: none;
}

.board-section {
  display: grid;
  place-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, black);
  box-shadow: 0 22px 46px rgba(0, 0, 0, 0.23);
  margin: 10px 0;
}

.dartboard {
  position: relative;
  width: min(90vw, 640px);
  aspect-ratio: 1;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.dartboard-svg {
  display: block;
  width: 92%;
  height: 92%;
  margin: 4%;
  filter: drop-shadow(0 20px 32px rgba(0, 0, 0, 0.35));
}

.board-rim {
  fill: #030405;
}

.board-field,
.bull,
.board-rim {
  stroke: #07090c;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.board-field,
.bull {
  cursor: pointer;
  pointer-events: none;
}

.board-hit-zone {
  fill: transparent;
  stroke: transparent;
  cursor: pointer;
  pointer-events: all;
}

.board-hit-zone:focus,
.board-hit-zone:focus-visible,
.board-rim:focus,
.board-rim:focus-visible,
.zero-corner:focus,
.zero-corner:focus-visible {
  outline: 0;
}

.zero-corner {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  min-height: 48px;
  border: 1px solid rgba(244, 241, 233, 0.32);
  border-radius: 8px;
  background: rgba(21, 25, 32, 0.92);
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 950;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.zero-corner:hover {
  background: var(--button-hover);
}

.zero-corner.top-left {
  top: 5.5%;
  left: 5.5%;
}

.zero-corner.top-right {
  top: 5.5%;
  right: 5.5%;
}

.zero-corner.bottom-left {
  bottom: 5.5%;
  left: 5.5%;
}

.zero-corner.bottom-right {
  right: 5.5%;
  bottom: 5.5%;
}

.single-light {
  fill: #e5decf;
}

.single-dark {
  fill: #20252c;
}

.accent-red {
  fill: #bb414d;
}

.accent-green {
  fill: #168761;
}

.outer-bull {
  fill: #168761;
}

.bullseye {
  fill: #bb414d;
}

.board-field.field-hover,
.bull.field-hover,
.board-rim:hover {
  filter: brightness(1.18);
}

.board-field.is-hit,
.bull.is-hit {
  stroke: #fff7d1;
  stroke-width: 4;
  filter: brightness(1.25) saturate(1.15);
}

.hit-flash {
  filter: brightness(1.35);
}

.hit-marker-layer {
  position: absolute;
  inset: 4%;
  z-index: 3;
  pointer-events: none;
}

.hit-marker {
  position: absolute;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid #fff7d1;
  border-radius: 50%;
  background: rgba(11, 13, 16, 0.72);
  color: #fff7d1;
  font-size: 0.68rem;
  font-weight: 950;
  line-height: 1;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.65), 0 0 14px rgba(255, 247, 209, 0.25);
}

.hit-marker:empty::before {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff7d1;
  content: "";
}

.zero-corner.is-hit {
  border-color: #fff7d1;
  background: rgba(255, 247, 209, 0.16);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.65), 0 0 16px rgba(255, 247, 209, 0.2);
}

.zero-corner.is-hit::after {
  position: absolute;
  top: -8px;
  right: -8px;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  border: 1px solid #fff7d1;
  border-radius: 50%;
  background: #0b0d10;
  color: #fff7d1;
  font-size: 0.66rem;
  font-weight: 950;
  content: attr(data-hit-count);
}

.board-label {
  fill: #f4f1e9;
  font-size: 20px;
  font-weight: 900;
  pointer-events: none;
  paint-order: stroke;
  stroke: #030405;
  stroke-width: 4px;
  vector-effect: non-scaling-stroke;
}

.bull-label {
  fill: #fff7ea;
  font-size: 18px;
  font-weight: 950;
  pointer-events: none;
}

.throw-panel {
  position: sticky;
  bottom: 0;
  z-index: 4;
  padding: 10px;
  background: rgba(21, 25, 32, 0.96);
  backdrop-filter: blur(12px);
}

.dart-slots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.dart-slot {
  display: grid;
  gap: 1px;
  min-width: 0;
  min-height: 66px;
  padding: 7px 5px;
  text-align: center;
}

.dart-slot span,
.dart-slot small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dart-slot strong {
  font-size: 1.25rem;
  line-height: 1;
}

.throw-total {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid rgba(82, 214, 164, 0.56);
  border-radius: 8px;
  background: rgba(50, 194, 141, 0.13);
  color: rgba(244, 241, 233, 0.78);
  font-weight: 800;
  white-space: nowrap;
}

.throw-total strong {
  color: var(--text);
  font-size: 1.45rem;
  line-height: 1;
}

.throw-total span {
  font-size: 1rem;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  margin-top: 8px;
  gap: 8px;
}

.throw-panel .primary-button,
.throw-panel .secondary-button {
  width: 100%;
  min-height: 46px;
}

.overview-dialog,
.confirm-dialog {
  width: min(calc(100vw - 28px), 520px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
}

.overview-dialog::backdrop,
.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.dialog-header {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.dialog-body {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.dialog-body p {
  margin: 0;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 750;
  line-height: 1.35;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.dialog-actions .primary-button {
  width: 100%;
}

.desktop-overview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, black);
  box-shadow: 0 22px 46px rgba(0, 0, 0, 0.23);
}

.desktop-overview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

#desktop-new-game-button {
  display: none;
}

.overview-list,
.results-list {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.overview-row,
.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.overview-row.current {
  border-color: rgba(82, 214, 164, 0.7);
  background: rgba(50, 194, 141, 0.14);
  box-shadow: inset 4px 0 0 var(--accent);
}

.overview-row div:first-child,
.result-row div:first-child {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.overview-row strong,
.result-row strong {
  overflow-wrap: anywhere;
}

.overview-row span,
.result-row span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.overview-score {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.overview-score strong {
  font-size: 1.35rem;
}

.rank-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 28px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 950;
  line-height: 1;
  text-shadow:
    -1px -1px 0 #000,
    1px -1px 0 #000,
    -1px 1px 0 #000,
    1px 1px 0 #000;
  white-space: nowrap;
}

.rank-icon {
  flex: 0 0 auto;
  font-size: 1.05rem;
  line-height: 1;
  text-shadow:
    -1px -1px 0 #000,
    1px -1px 0 #000,
    -1px 1px 0 #000,
    1px 1px 0 #000;
}

.rank-1 {
  border-color: #0b0d10;
  background: var(--gold);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.82);
}

.rank-2 {
  border-color: #0b0d10;
  background: var(--silver);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.82);
}

.rank-3 {
  border-color: #0b0d10;
  background: var(--bronze);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.82);
}

.rank-outline {
  border-color: rgba(244, 241, 233, 0.65);
  background: transparent;
}

.final-panel {
  max-width: 620px;
  margin: 16px auto 0;
}

.final-panel .primary-button {
  margin-top: 8px;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .app-header {
    padding-bottom: 12px;
  }

  .setup-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  .turn-panel {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 3px 10px;
    padding: 6px 10px 6px 14px;
  }

  .turn-panel::before {
    inset: 8px auto 8px 0;
  }

  .turn-panel h2 {
    font-size: 1.25rem;
  }

  .score-line {
    min-width: 78px;
    padding: 4px 8px;
  }

  .score-line span:first-child {
    font-size: 1.45rem;
  }

  .board-section {
    padding: 6px;
    margin: 6px 0;
    overflow: visible;
  }

  .dartboard {
    width: min(100%, 680px, calc(100svh - 286px));
  }

  .zero-corner {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .zero-corner.top-left {
    top: 3%;
    left: 3%;
  }

  .zero-corner.top-right {
    top: 3%;
    right: 3%;
  }

  .zero-corner.bottom-left {
    bottom: 3%;
    left: 3%;
  }

  .zero-corner.bottom-right {
    right: 3%;
    bottom: 3%;
  }

  .throw-panel {
    padding: 6px;
    margin: 0 -4px;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
  }

  .dart-slots {
    gap: 5px;
  }

  .dart-slot {
    min-height: 54px;
    padding: 5px 4px;
  }

  .dart-slot span,
  .dart-slot small {
    font-size: 0.68rem;
  }

  .dart-slot strong {
    font-size: 1.05rem;
  }

  .throw-total {
    min-height: 40px;
    padding: 0 8px;
    gap: 5px;
  }

  .throw-total strong {
    font-size: 1.25rem;
  }

  .throw-total span {
    font-size: 1rem;
  }

  .throw-panel .primary-button,
  .throw-panel .secondary-button {
    min-height: 40px;
  }

  .action-row {
    margin-top: 7px;
    gap: 6px;
  }
}

@media (min-width: 900px) and (orientation: landscape) {
  .is-playing .app-shell {
    width: min(100%, 1320px);
    padding: 12px;
  }

  #game-screen.active {
    display: grid;
    grid-template-columns: minmax(300px, 1fr) minmax(430px, 1fr);
    grid-template-rows: auto auto;
    gap: 12px 16px;
    align-items: start;
  }

  .desktop-overview {
    display: flex;
    flex: 1;
    min-height: 0;
    max-height: none;
    flex-direction: column;
    overflow: hidden;
  }

  .desktop-overview .overview-list {
    padding: 12px;
    overflow: auto;
  }

  .board-section,
  .throw-panel {
    grid-column: 2;
  }

  .game-sidebar {
    display: flex;
    grid-column: 1;
    grid-row: 1 / span 2;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    align-self: stretch;
  }

  .game-topbar {
    display: none;
  }

  #overview-button {
    display: none;
  }

  #desktop-new-game-button {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 0 12px;
    white-space: nowrap;
  }

  .turn-panel {
    display: none;
  }

  .board-section {
    grid-row: 1;
    padding: 10px;
    margin: 0;
  }

  .dartboard {
    width: min(48vw, 530px, calc(100svh - 202px));
    min-width: min(380px, 48vw);
  }

  .throw-panel {
    grid-row: 2;
    position: static;
    padding: 10px;
  }

  .dart-slot {
    min-height: 64px;
  }
}

@media (min-width: 900px) and (orientation: landscape) and (max-height: 820px) {
  .is-playing .app-shell {
    padding: 10px;
  }

  #game-screen.active {
    grid-template-columns: minmax(280px, 1fr) minmax(400px, 1fr);
    gap: 10px 14px;
  }

  .desktop-overview {
    max-height: none;
  }

  .desktop-overview .overview-list {
    padding: 10px;
  }

  .game-sidebar {
    gap: 10px;
  }

  .board-section {
    padding: 8px;
  }

  .dartboard {
    width: min(46vw, 500px, calc(100svh - 190px));
    min-width: min(350px, 46vw);
  }

  .throw-panel {
    padding: 8px;
  }

  .dart-slots {
    gap: 6px;
  }

  .dart-slot {
    min-height: 52px;
    padding: 5px 4px;
  }

  .dart-slot span,
  .dart-slot small {
    font-size: 0.68rem;
  }

  .dart-slot strong {
    font-size: 1.05rem;
  }

  .throw-total {
    min-height: 40px;
    padding: 0 8px;
  }

  .throw-total strong {
    font-size: 1.25rem;
  }

  .throw-total span {
    font-size: 1rem;
  }

  .throw-panel .primary-button,
  .throw-panel .secondary-button {
    min-height: 40px;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 2rem;
  }

  .inline-control,
  .game-topbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .segmented,
  .score-presets {
    gap: 6px;
  }

  .secondary-button,
  .ghost-button {
    padding: 0 10px;
  }

  .overview-row,
  .result-row {
    align-items: flex-start;
  }

  .overview-score {
    flex-direction: column;
    align-items: flex-end;
  }
}
