:root {
  color-scheme: light dark;

  --bg: #fafafa;
  --bg-secondary: #f4f4f5;
  --bg-tertiary: #e4e4e7;
  --border: #d4d4d8;
  --text: #18181b;
  --text-secondary: #52525b;
  --accent: #2563eb;
  --plus: #15803d;
  --minus: #b91c1c;
  --leader: #ca8a04;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --bg-secondary: #18181b;
    --bg-tertiary: #27272a;
    --border: #3f3f46;
    --text: #fafafa;
    --text-secondary: #a1a1aa;
    --accent: #60a5fa;
    --plus: #4ade80;
    --minus: #f87171;
    --leader: #fbbf24;
  }
}

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

[hidden] {
  display: none !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding: 0.75rem;
  -webkit-text-size-adjust: 100%;
}

.container {
  width: 100%;
  max-width: 40rem;
  margin-inline: auto;
}

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

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  padding: 0.5rem 0.9rem;
  background: var(--accent);
  color: #fff;

  &.secondary {
    background: var(--bg-secondary);
    color: var(--text);
    border-color: var(--border);
  }

  &.link {
    background: none;
    color: var(--accent);
    border: 0;
    padding: 0;
    text-decoration: underline;
  }
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;

  & h1 {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 1.25rem;
    letter-spacing: -0.01em;
  }
}

.action-btn {
  background: var(--bg-secondary);
  color: var(--text);
  border-color: var(--border);
  padding: 0.35rem 0.5rem;
  display: grid;
  place-items: center;
}

.icon-mask {
  display: inline-block;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.icon-settings {
  width: 1.25rem;
  height: 1.25rem;
  -webkit-mask-image: url(/icons/settings.svg);
  mask-image: url(/icons/settings.svg);
}

.players {
  list-style: none;
  display: grid;
  gap: 0.5rem;
}

.player {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.75rem;

  &.is-leader {
    border-color: var(--leader);
  }

  & .row {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name score" "history history";
    align-items: baseline;
    gap: 0 0.75rem;
    padding: 0.6rem 0.85rem;
    text-align: left;
    background: none;
    border: 0;
    border-radius: inherit;
    color: inherit;
    touch-action: manipulation;

    &:active {
      background: var(--bg-tertiary);
    }
  }

  & .name {
    grid-area: name;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
  }

  & .score {
    grid-area: score;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
  }

  & .history {
    grid-area: history;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.45rem;

    &:empty {
      display: none;
    }
  }

  & .chip {
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    padding: 0.1rem 0.4rem;
    border-radius: 0.35rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
  }

  & .up { color: var(--plus); }
  & .down { color: var(--minus); }
}

.empty {
  color: var(--text-secondary);
  text-align: center;
  padding: 2rem 0;
}

.footer {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
}

dialog {
  /* The global reset drops the UA's margin: auto, which centres a modal */
  margin: auto;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--bg);
  color: var(--text);
  padding: 0;
  width: min(28rem, 100% - 2rem);
  max-height: 85dvh;

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

.dialog-inner {
  padding: 1rem;
  display: grid;
  gap: 1rem;

  & h2 {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 1.25rem;
  }
}

.add-row {
  display: flex;
  gap: 0.5rem;

  & input {
    flex: 1;
    min-width: 0;
    font: inherit;
    padding: 0.5rem 0.65rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text);
  }
}

.edit-list {
  list-style: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 0.4rem;
  overflow-y: auto;

  & li {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.4rem 0.4rem 0.4rem 0.65rem;
  }

  & .edit-name {
    flex: 1;
    min-width: 0;
    font: inherit;
    border: 0;
    background: none;
    color: var(--text);
    padding: 0.25rem 0;
  }

  & .remove {
    background: none;
    color: var(--minus);
    border-color: var(--border);
    padding: 0.3rem 0.6rem;
  }
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.amount-ops {
  display: flex;
  gap: 0.5rem;
}

@media (max-width: 639px) {
  dialog {
    inset: 0;
    margin: 0;
    width: 100vw;
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }

  .dialog-inner {
    height: 100%;
  }

  #dlg-settings .dialog-inner {
    grid-template-rows: auto auto 1fr auto;
  }

  #dlg-amount .dialog-inner {
    grid-template-rows: auto auto 1fr;

    & .dialog-actions {
      align-self: end;
    }
  }
}

@media (min-width: 640px) {
  body { padding: 2rem; }

  .bar h1 { font-size: 1.75rem; }
}
