:root {
  color-scheme: light dark;
  --bg: #f2f2f4;
  --surface: #ffffff;
  --text: #1c1c1e;
  --secondary: #6e6e73;
  --line: rgba(60, 60, 67, 0.12);
  --fill: #ececef;
  --danger: #ff3b30;
  --shadow: rgba(0, 0, 0, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f2f2f7;
    --secondary: #8e8e93;
    --line: rgba(255, 255, 255, 0.12);
    --fill: #2c2c2e;
    --danger: #ff453a;
    --shadow: rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body.reordering {
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  color: var(--text);
  padding: calc(env(safe-area-inset-top) + 6px) 12px 8px;
}

.bar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

#edit {
  justify-self: start;
}

#add {
  justify-self: end;
}

.bar-btn {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 17px;
  font-weight: 400;
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
}

.icon-btn {
  display: grid;
  place-items: center;
  padding: 8px;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn svg[hidden] {
  display: none;
}

.add-btn {
  font-size: 32px;
  font-weight: 300;
  line-height: 1;
}

main {
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

#list {
  position: relative;
  list-style: none;
  margin: 8px 16px 0;
  padding: 0;
  background: var(--surface);
  border-radius: 18px;
  overflow: hidden;
}

.row {
  position: relative;
  overflow: hidden;
  min-height: 72px;
  background: var(--surface);
  transition: transform 180ms ease;
}

.row + .row {
  box-shadow: inset 0 1px 0 var(--line);
}

.row-face {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 12px 14px;
  background: var(--surface);
  position: relative;
  z-index: 1;
  transition: transform 180ms ease;
  touch-action: pan-y;
}

.row-face.swiping {
  transition: none;
}

.trash {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  width: 76px;
  border: 0;
  background: var(--danger);
  color: #fff;
  display: grid;
  place-items: center;
}

.trash svg {
  width: 22px;
  height: 22px;
}

.row.dragging {
  position: fixed;
  z-index: 5;
  border-radius: 16px;
  box-shadow: 0 16px 40px var(--shadow);
  transform: scale(1.02);
  transition: none;
  pointer-events: none;
  touch-action: none;
}

.placeholder {
  background: var(--fill);
  box-shadow: inset 0 1px 0 var(--line);
}

.label {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.value {
  font-size: 32px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}

.name,
.name-input {
  font-size: 17px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--secondary);
}

.name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name-input {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 8px;
  background: var(--fill);
  color: var(--text);
  padding: 6px 8px;
}

.name-input:focus {
  outline: 2px solid color-mix(in srgb, var(--text) 35%, transparent);
  outline-offset: 0;
}

.stepper {
  display: flex;
  flex: none;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: var(--fill);
}

.stepper button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 40px;
  margin: 0;
  /* Default button padding plus the font box leave the glyph about 2px low. */
  padding: 0 0 4px;
  border: 0;
  border-radius: 999px;
  appearance: none;
  background: transparent;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.stepper button:active {
  background: var(--surface);
}

.delete,
.handle {
  flex: none;
  border: 0;
  background: transparent;
  padding: 0;
}

.delete {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}

.handle {
  width: 36px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--secondary);
  touch-action: none;
  cursor: grab;
}

.handle svg {
  width: 18px;
  height: 18px;
  display: block;
  margin: 0 auto;
}

.empty {
  margin: 36px 16px 0;
  text-align: center;
  color: var(--secondary);
  font-size: 16px;
}

.zero {
  display: block;
  margin: 22px auto 8px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  min-height: 44px;
  padding: 10px 22px;
}

dialog {
  border: 0;
  border-radius: 16px;
  padding: 22px 18px 14px;
  width: min(300px, calc(100vw - 48px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 40px var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

dialog p {
  margin: 0;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
}

dialog p.confirm-note {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 400;
  color: var(--secondary);
}

.confirm-actions {
  display: flex;
  margin: 18px -18px -14px;
  border-top: 1px solid var(--line);
}

.confirm-actions button {
  flex: 1;
  min-height: 48px;
  border: 0;
  background: transparent;
  font-size: 17px;
  color: var(--text);
}

.confirm-actions button + button {
  border-left: 1px solid var(--line);
  font-weight: 600;
  color: var(--danger);
}

.confirm-actions button:active {
  background: var(--fill);
}
