:root {
  color-scheme: light;
  --bg: #f7f2ea;
  --ink: #18201b;
  --muted: #51483f;
  --soft: #ffffff;
  --disabled: #e5ded4;
  --green: #275d38;
  --red: #b3261e;
  --amber: #b26a00;
  --ring: #151515;
}

* {
  box-sizing: border-box;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100svh;
  height: 100svh;
  padding: max(20px, env(safe-area-inset-top)) clamp(12px, 3vw, 24px) max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: clamp(8px, 1.4svh, 14px);
  position: relative;
  overflow: hidden;
}

.topbar {
  height: 42px;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}

.menu {
  position: absolute;
  top: calc(max(28px, env(safe-area-inset-top)) + 46px);
  left: 16px;
  z-index: 20;
  min-width: 230px;
  padding: 8px;
  display: grid;
  gap: 4px;
  background: var(--soft);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(24, 32, 27, 0.18);
}

.menu[hidden] {
  display: none;
}

.menu button,
.menu a {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  font: inherit;
  font-weight: 700;
}

.menu button:active,
.menu a:active {
  background: var(--bg);
}

.quick-actions {
  width: min(100%, 390px);
  margin-inline: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.quick-actions button {
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.quick-actions button:active {
  background: var(--disabled);
}

.score-panel {
  display: grid;
  gap: clamp(6px, 1svh, 10px);
  width: min(100%, 390px);
  margin-inline: auto;
  text-align: center;
}

.target {
  font-size: clamp(44px, 12vw, 72px);
  line-height: 0.96;
  font-weight: 900;
  letter-spacing: 0;
}

.remaining {
  font-size: clamp(16px, 4.2vw, 18px);
  color: var(--muted);
  line-height: 1.2;
}

.difficulty-label {
  font-size: 13px;
  color: #6f665d;
  font-weight: 700;
}

.throws {
  min-height: 38px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.throw-slot {
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--soft);
  font-size: 18px;
  font-weight: 800;
}

.message {
  min-height: 30px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  font-size: 15px;
  line-height: 1.35;
  padding-inline: 4px;
}

.message.correct {
  color: #1b6b3a;
}

.message.error {
  color: var(--red);
}

.message.warn {
  color: var(--amber);
}

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

.secondary,
.primary,
.option-button {
  height: 46px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 800;
}

.secondary {
  background: var(--soft);
  color: var(--ink);
}

.secondary:disabled {
  background: var(--disabled);
  color: #93897e;
}

.primary {
  width: 100%;
  background: var(--green);
  color: #fff;
}

.board-panel {
  min-height: 0;
  display: grid;
  place-items: center;
  padding-block: clamp(6px, 1.6svh, 14px);
  overflow: hidden;
}

#dartboard {
  display: block;
  width: min(100%, 46svh, 460px);
  height: auto;
  max-height: 100%;
  aspect-ratio: 1;
  touch-action: manipulation;
}

dialog {
  width: min(92vw, 520px);
  max-height: 82svh;
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--soft);
  color: var(--ink);
  box-shadow: 0 22px 60px rgba(24, 32, 27, 0.24);
}

dialog::backdrop {
  background: rgba(24, 32, 27, 0.32);
}

.dialog-header {
  height: 56px;
  display: grid;
  grid-template-columns: 1fr 42px;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 8px 18px;
  border-bottom: 1px solid #ece3d8;
}

.dialog-header h2 {
  margin: 0;
  font-size: 18px;
}

.dialog-content {
  padding: 16px 18px 18px;
  overflow: auto;
  max-height: calc(82svh - 56px);
  line-height: 1.6;
}

.arrange-row,
.stat-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--bg);
}

.arrange-row strong,
.stat-card strong {
  font-size: 18px;
}

.difficulty-options {
  display: grid;
  gap: 8px;
}

.color-settings {
  display: grid;
  gap: 16px;
}

.color-picker {
  display: grid;
  gap: 8px;
}

.color-picker-header {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.color-current,
.color-swatch {
  background: var(--swatch);
}

.color-current {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 3px solid var(--ink);
  border-radius: 999px;
}

.color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border: 1px solid var(--disabled);
  border-radius: 999px;
  padding: 0;
}

.color-swatch.selected {
  border: 3px solid var(--ink);
}

.option-button {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  text-align: left;
  padding-inline: 14px;
}

.option-button.selected {
  background: var(--green);
  color: #fff;
}

@media (min-width: 860px) and (orientation: landscape) {
  .app {
    grid-template-columns: minmax(280px, 360px) 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    column-gap: clamp(18px, 4vw, 56px);
  }

  .topbar {
    grid-column: 1 / -1;
  }

  .quick-actions {
    width: 100%;
    margin-inline: 0;
    grid-column: 1;
  }

  .score-panel {
    width: 100%;
    margin-inline: 0;
    align-self: start;
  }

  .board-panel {
    grid-row: 2 / -1;
    grid-column: 2;
  }

  #dartboard {
    width: min(100%, 74svh, 560px);
  }
}

@media (max-height: 760px) and (orientation: portrait) {
  .app {
    padding-top: max(16px, env(safe-area-inset-top));
    gap: 6px;
  }

  .topbar {
    height: 38px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .target {
    font-size: 42px;
  }

  .throws {
    min-height: 36px;
  }

  .secondary,
  .primary {
    height: 40px;
  }
}

@media (max-height: 620px) and (orientation: portrait) {
  .target {
    font-size: 38px;
  }

  .remaining,
  .difficulty-label {
    display: inline;
  }

  .message {
    min-height: 24px;
    font-size: 14px;
  }

  .throws {
    min-height: 34px;
  }

  .secondary,
  .primary {
    height: 38px;
  }
}
