/* Theme tokens. Dark values follow the system setting. */
:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1a1d21;
  --muted: #5d6571;
  --border: #d5dae1;
  --accent: #4338ca;
  --accent-text: #ffffff;
  --accent-soft: #e8e9fd;
  --good: #15803d;
  --bad: #b91c1c;
  --focus: #2563eb;
  --radius: 12px;
  --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1b1e25;
    --surface-2: #252932;
    --text: #e8eaee;
    --muted: #a3aab6;
    --border: #343a45;
    --accent: #a5a1ff;
    --accent-text: #14151c;
    --accent-soft: #2b2d4a;
    --good: #4ade80;
    --bad: #f87171;
    --focus: #93c5fd;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

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

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.hint {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Layout */

.app-header {
  padding: 1rem 1rem 0;
  max-width: 48rem;
  margin: 0 auto;

  h1 {
    font-size: 1.25rem;
  }
}

main {
  display: grid;
  gap: 1rem;
  max-width: 48rem;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-width: 0;

  > h2 {
    font-size: 1.15rem;
  }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;

  .secondary {
    padding-inline: 0.875rem;
  }
}

/* Buttons */

.primary,
.secondary {
  min-height: var(--tap);
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
}

.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.secondary {
  background: var(--surface);
  border-color: var(--border);
}

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

.link-button {
  min-height: var(--tap);
  padding: 0 0.5rem;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.icon-button {
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

/* Number picker */

.picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tap), 1fr));
  gap: 0.375rem;
}

.pick {
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;

  &[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 700;
  }

  &.more {
    grid-column: span 2;
    font-size: 0.95rem;
  }
}

/* Setup */

fieldset {
  border: 0;
  margin: 1rem 0 0;
  padding: 0;
}

legend {
  font-weight: 600;
  margin-bottom: 0.5rem;
  padding: 0;
}

.seats {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.seat {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto;
  grid-template-areas:
    "num name moves"
    ". dealer moves";
  align-items: center;
  gap: 0.25rem 0.5rem;
}

.seat-number {
  grid-area: num;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.seat-name {
  grid-area: name;
  min-height: var(--tap);
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.dealer-choice {
  grid-area: dealer;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;

  input {
    width: 1.25rem;
    height: 1.25rem;
    margin: 0;
    accent-color: var(--accent);
  }
}

.seat-moves {
  grid-area: moves;
  display: flex;
  gap: 0.25rem;
}

.setup > .primary {
  width: 100%;
  margin-top: 1.25rem;
}

/* Round entry */

.round-header h2 {
  font-size: 1.15rem;

  .of {
    color: var(--muted);
    font-weight: 400;
  }
}

.player-cards {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.player-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  display: grid;
  gap: 0.5rem;
}

.player-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  .player-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .points {
    margin-left: auto;
    font-weight: 700;
  }
}

.badge {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
}

.field {
  display: grid;
  gap: 0.25rem;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.round-footer {
  position: sticky;
  bottom: 0;
  margin: 1rem -1rem -1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.summary {
  margin: 0;
  display: grid;
  font-variant-numeric: tabular-nums;

  .bid-status {
    color: var(--muted);
    font-size: 0.9rem;
  }

  &.done .bid-status {
    color: var(--good);
  }
}

.actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.good {
  color: var(--good);
}

.bad {
  color: var(--bad);
}

/* Scoreboard */

.table-scroll {
  overflow: auto;
  max-height: 70vh;
  border-radius: 8px;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  vertical-align: bottom;

  &.leader {
    background: var(--accent-soft);
  }
}

th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  width: 3rem;
}

thead th.corner {
  z-index: 2;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.crown {
  line-height: 1;
}

thead .crown {
  display: block;
  font-size: 1.1rem;
}

.name-button {
  display: block;
  max-width: 7rem;
  margin: 0 auto;
  min-height: 2rem;
  padding: 0 0.25rem;
  border: 0;
  background: none;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.total {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
}

.round-button {
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;

  &:disabled {
    opacity: 1;
    cursor: default;
    background: none;
    border-color: transparent;
  }
}

tr.viewing > * {
  background: var(--accent-soft);
}

td {
  min-width: 4.5rem;

  span {
    display: block;
  }

  .bid-won {
    color: var(--muted);
    font-size: 0.8rem;
  }

  .points {
    font-size: 0.85rem;
    font-weight: 600;
  }

  .running {
    font-weight: 700;
  }
}

/* Dealer marker: a small dot in the cell's corner. */
td.dealer {
  position: relative;
}

td.dealer::before,
.dealer-mark {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent);
}

td.dealer::before {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
}

.legend {
  margin-top: 0.75rem;
  font-size: 0.8rem;
}

/* Results */

.standings {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;

  li {
    display: grid;
    grid-template-columns: 2.5rem 1fr auto;
    align-items: center;
    padding: 0.5rem;
    border-radius: 8px;
  }

  .place-1 {
    background: var(--accent-soft);
    font-size: 1.15rem;
    font-weight: 700;
  }

  .place {
    text-align: center;
    font-size: 1.25rem;
  }

  .score {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
  }
}

/* Status toast */

.status {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  max-width: 30rem;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  text-align: center;
  z-index: 10;

  &.error {
    background: var(--bad);
  }
}

/* Podium image */

.results h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1rem;
}

.podium {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius);
}

.share {
  width: 100%;
  margin-top: 0.75rem;
}

/* Rage quit */

.quit-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

thead th.quit {
  color: var(--muted);

  .name-button {
    color: inherit;
    text-decoration: line-through;
  }
}

td.absent {
  color: var(--muted);
}

.standings li.quit {
  color: var(--muted);

  .quit-label {
    display: inline;
  }
}

.dialog {
  width: min(24rem, calc(100vw - 2rem));
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);

  h2 {
    font-size: 1.15rem;
  }

  > .secondary {
    width: 100%;
    margin-top: 1rem;
  }

  &::backdrop {
    background: rgb(0 0 0 / 0.5);
  }
}

.dialog-choices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: 0.5rem;
  margin-top: 1rem;
}
