:root {
  color-scheme: light;
  --bg: oklch(1 0 0);
  --surface: oklch(0.97 0 0);
  --line: oklch(0.922 0 0);
  --text: oklch(0.145 0 0);
  --muted: oklch(0.556 0 0);
  --backdrop: oklch(0 0 0 / 0.5);

  --font: "Geist", system-ui, sans-serif;
  --text-sm: 0.8125rem;
  --text-md: 0.9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --weight-medium: 500;
  --weight-strong: 600;
  --leading: 1.5;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  --radius: 0.375rem;
  --round: 50%;
  --border: 1px solid var(--line);
  --control: 2.25rem;
  --nav: 3.5rem;
  --icon: 1.125rem;
  --stroke: 1.75;
  --amount: 6rem;
  --page: 32rem;
  --pulse: 1.2s;
  --disabled: 0.3;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: oklch(0.145 0 0);
    --surface: oklch(0.205 0 0);
    --line: oklch(0.269 0 0);
    --text: oklch(0.985 0 0);
    --muted: oklch(0.708 0 0);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: oklch(0.145 0 0);
  --surface: oklch(0.205 0 0);
  --line: oklch(0.269 0 0);
  --text: oklch(0.985 0 0);
  --muted: oklch(0.708 0 0);
}

/* Base */

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

[hidden] {
  display: none !important;
}

body {
  max-width: var(--page);
  margin-inline: auto;
  padding: 0 var(--space-4) calc(var(--nav) + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: var(--text-md) / var(--leading) var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

h1 {
  font-size: var(--text-xl);
  font-weight: var(--weight-strong);
}

h2 {
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
}

ul {
  padding: 0;
  list-style: none;
}

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

button,
input:not([type="checkbox"]) {
  height: var(--control);
  padding-inline: var(--space-3);
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: var(--disabled);
  cursor: default;
}

input {
  min-width: 0;
  appearance: none;
}

input:focus {
  outline: none;
  border-color: var(--muted);
}

input[type="number"] {
  appearance: textfield;
}

::-webkit-inner-spin-button {
  display: none;
}

::placeholder {
  color: var(--muted);
}

input[type="checkbox"] {
  width: var(--icon);
  height: var(--icon);
  margin-right: var(--space-2);
  vertical-align: middle;
  appearance: auto;
  accent-color: var(--text);
}

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

.icon-btn {
  display: grid;
  place-items: center;
  width: var(--control);
  padding: 0;
  border-color: transparent;
  background: none;
  color: var(--muted);
}

.icon {
  width: var(--icon);
  height: var(--icon);
  fill: none;
  stroke: currentColor;
  stroke-width: var(--stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.empty {
  padding-block: var(--space-8);
  color: var(--muted);
  text-align: center;
}

@media (hover: hover) {
  button:not(.primary, :disabled):hover {
    background: var(--surface);
    color: var(--text);
  }

  .row:hover {
    background: var(--surface);
  }

  .nav button:hover {
    background: none;
  }
}

/* Gate */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--bg);
  text-align: center;
}

.lock {
  display: grid;
  gap: var(--space-3);
}

.lock h1 {
  margin-bottom: var(--space-4);
}

.lock input {
  text-align: center;
}

.loader {
  width: var(--space-8);
  aspect-ratio: 1;
  border-radius: var(--round);
  background: var(--text);
  animation: pulse var(--pulse) ease-out infinite;
}

@keyframes pulse {
  from {
    scale: 0;
    opacity: 1;
  }
  to {
    scale: 1;
    opacity: 0;
  }
}

/* Layout */

.bar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding-block: var(--space-3);
  background: var(--bg);
}

header.bar {
  position: sticky;
  top: 0;
  z-index: 1;
  margin-bottom: var(--space-2);
  padding-top: calc(var(--space-3) + env(safe-area-inset-top));
  border-bottom: var(--border);
}

footer.bar {
  border-top: var(--border);
}

.bar h2 {
  margin-right: auto;
  padding-inline: var(--space-2);
}

.bar > div {
  display: flex;
}

.total {
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
}

.nav {
  position: fixed;
  inset: auto 0 0;
  z-index: 1;
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: var(--border);
  background: var(--bg);
}

.nav button {
  flex: 1;
  max-width: calc(var(--page) / 5);
  height: var(--nav);
  border: 0;
  background: none;
  color: var(--muted);
}

.nav [aria-current="page"] {
  color: var(--text);
}

/* Rows */

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  height: auto;
  min-height: var(--control);
  padding: var(--space-1) var(--space-2);
  border: 0;
  border-radius: var(--radius);
  background: none;
  text-align: left;
}

.row.selected,
.row.current {
  background: var(--surface);
}

.name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name small {
  display: block;
  color: var(--muted);
  font-size: var(--text-sm);
}

.row:has(:checked) .name {
  color: var(--muted);
  text-decoration: line-through;
}

.actions {
  display: none;
  gap: var(--space-1);
}

.selected .actions {
  display: flex;
}

.actions button {
  height: auto;
  padding-block: var(--space-1);
  font-size: var(--text-sm);
}

.day {
  display: flex;
  justify-content: space-between;
  padding: var(--space-4) var(--space-2) var(--space-1);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

/* Forms */

.composer {
  position: sticky;
  bottom: calc(var(--nav) + env(safe-area-inset-bottom));
  display: flex;
  gap: var(--space-2);
  padding-block: var(--space-3);
  background: var(--bg);
}

#item {
  flex: 1;
}

#amount {
  width: var(--amount);
  text-align: right;
}

.search {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.range {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.range input {
  flex: 1;
}

/* Settings */

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-2);
  border-bottom: var(--border);
}

.buttons {
  display: flex;
  gap: var(--space-2);
}

.segmented {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  border: var(--border);
  border-radius: var(--radius);
}

.segmented [aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
}

/* Overlays */

dialog {
  margin: auto;
  padding: var(--space-6);
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

dialog::backdrop {
  background: var(--backdrop);
}

dialog form {
  display: grid;
  gap: var(--space-3);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.toast {
  position: fixed;
  bottom: calc(var(--nav) + env(safe-area-inset-bottom) + var(--space-4));
  left: 50%;
  z-index: 2;
  width: max-content;
  max-width: calc(100% - var(--space-8));
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: var(--text-sm);
  translate: -50%;
}
