:root {
  color-scheme: light dark;
  --bg: #fafaf7;
  --fg: #1c1c1a;
  --muted: #6b6b66;
  --line: #deded8;
  --field: #ffffff;
  --accent: #1f6f4a;
  --accent-fg: #ffffff;
  --up: #1f6f4a;
  --down: #b3372b;
  --tap: #e8f1ec;
  --tap-minus: #f6e9e7;
  --warn: #9a5b00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --fg: #ececec;
    --muted: #9a9a94;
    --line: #34342f;
    --field: #1f1f1d;
    --accent: #4fb385;
    --accent-fg: #0d1a13;
    --up: #6cc79c;
    --down: #ef8a7e;
    --tap: #1f2d26;
    --tap-minus: #2f2220;
    --warn: #e8b04a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 34rem;
  margin: 0 auto;
  /* Room for the undo popup below the last line */
  padding: 1.5rem 1rem 6rem;
}

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 2rem 0 .5rem; }
p { margin: .5rem 0; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.error { color: var(--down); }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

label { display: block; font-weight: 600; margin: 1.25rem 0 .35rem; }
label + .muted { margin-top: -.25rem; }

input, button {
  font: inherit;
  border-radius: 8px;
  min-height: 2.9rem;
}

input {
  width: 100%;
  min-width: 0;
  padding: .55rem .75rem;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--fg);
}

button {
  padding: .55rem 1rem;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: .6; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
#create button { margin-top: .75rem; width: 100%; }

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

.row { display: flex; gap: .5rem; }
.row input { flex: 1; }

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.status { font-size: .85rem; color: var(--up); white-space: nowrap; }
.status::before { content: "\25CF  "; }
.status.off { color: var(--muted); }

.total { text-align: center; margin: 1rem 0 .5rem; }
.total output {
  display: block;
  font-size: clamp(4rem, 22vw, 7rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.who { text-align: center; color: var(--muted); }
.who strong { color: var(--fg); }

.quick {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1.4fr;
  gap: .75rem;
  margin: .75rem 0;
}
button.tap {
  min-height: 6rem;
  font-size: 2.2rem;
  font-weight: 700;
  background: var(--tap);
  border-color: transparent;
  color: var(--up);
}
button.tap:active { transform: scale(.97); }
button.tap.minus { background: var(--tap-minus); color: var(--down); }

.capacity { margin: .35rem 0 0; color: var(--muted); }
.total[data-level="near"] output, .total[data-level="near"] .capacity { color: var(--warn); }
.total[data-level="full"] output, .total[data-level="full"] .capacity { color: var(--down); }
.total[data-level] .capacity { font-weight: 600; }
.total[data-level=""] .capacity { font-weight: 400; }

.closed { text-align: center; font-weight: 600; color: var(--muted); }
.warning { color: var(--warn); }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .5rem .5rem .5rem 1rem;
  border-radius: 10px;
  background: var(--fg);
  color: var(--bg);
  box-shadow: 0 4px 16px rgb(0 0 0 / .2);
  white-space: nowrap;
}
.toast button { min-height: 2.4rem; background: transparent; color: inherit; border-color: currentColor; font-weight: 600; }

#share { margin-top: 2rem; border-top: 1px solid var(--line); padding-top: 1rem; }
#share summary { cursor: pointer; font-weight: 600; }
#share img {
  display: block;
  margin: 1rem auto;
  background: #fff;
  border-radius: 8px;
  max-width: 100%;
  height: auto;
}

.links { padding-left: 1.2rem; }
.links li { margin: .35rem 0; }

.history { list-style: none; padding: 0; margin: 0; }
.history li {
  display: grid;
  grid-template-columns: auto 1fr auto 4.5rem;
  gap: .75rem;
  padding: .45rem 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.history .time { color: var(--muted); font-size: .9rem; align-self: center; }
.history .who { text-align: left; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .delta { font-weight: 600; }
.history .up .delta { color: var(--up); }
.history .down .delta { color: var(--down); }
.history .run { text-align: right; }
.history li.mine, .people li.mine { box-shadow: inset 3px 0 var(--accent); padding-left: .6rem; }
.history li.undone .delta, .history li.undone .run { text-decoration: line-through; color: var(--muted); }

main.wide { max-width: 64rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .5rem .75rem .5rem 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .9rem; color: var(--muted); font-weight: 600; }
td:first-child { white-space: normal; min-width: 10rem; }
th.num, td.num { text-align: right; }
td button { min-height: 2.2rem; padding: .25rem .75rem; }
td button.danger { color: var(--down); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.tag { font-size: .8rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 .35rem; }
@media (max-width: 600px) {
  th:nth-child(3), td:nth-child(3), th:nth-child(5), td:nth-child(5), th:nth-child(6), td:nth-child(6) { display: none; }
  td:first-child { min-width: 0; }
}

.people { list-style: none; padding: 0; margin: .25rem 0 0; }
.people li {
  display: grid;
  grid-template-columns: 1fr auto 4.5rem;
  gap: .75rem;
  padding: .45rem 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.people .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .changes { color: var(--muted); font-size: .9rem; align-self: center; }
.people .net { text-align: right; font-weight: 600; }
#history-toggle { margin-top: .6rem; }

body.screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}
.screen-main { text-align: center; }
.screen h1 { font-size: clamp(1.5rem, 4vw, 3.5rem); }
.screen .total output { font-size: clamp(6rem, 28vw, 24rem); }
.screen .capacity, .screen #recent { font-size: clamp(1rem, 2.5vw, 2rem); }
.screen .status { font-size: 1rem; }
.sound {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  min-height: 2.4rem;
  font-size: .9rem;
  color: var(--muted);
  background: transparent;
}
.sound[aria-pressed="true"] { color: var(--fg); }

/* Rolling digits on the big screen */
.total output.odometer { display: flex; justify-content: center; white-space: nowrap; }
.odo-digit { display: inline-block; flex: none; height: 1em; overflow: hidden; }
.odo-strip {
  display: block;
  width: 1ch;
  text-align: center;
  word-break: break-all;
  white-space: normal;
  line-height: 1;
  transition: transform .6s cubic-bezier(.2, .8, .2, 1);
}
.odo-instant .odo-strip { transition: none; }

/* Effects */
@keyframes bump-up {
  30% { transform: scale(1.08); color: var(--up); }
}
@keyframes bump-down {
  30% { transform: scale(.94); color: var(--down); }
}
.total output.bump-up { animation: bump-up .35s ease-out; }
.total output.bump-down { animation: bump-down .35s ease-out; }

@keyframes float-up {
  from { opacity: 1; transform: translate(-50%, 0) scale(1); }
  to { opacity: 0; transform: translate(-50%, -80px) scale(1.3); }
}
.float {
  position: fixed;
  pointer-events: none;
  font-size: 1.6rem;
  font-weight: 800;
  animation: float-up .7s ease-out forwards;
  z-index: 10;
}
.float.up { color: var(--up); }
.float.down { color: var(--down); }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }

@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  25% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
.banner {
  position: fixed;
  left: 50%;
  top: 40%;
  z-index: 21;
  pointer-events: none;
  padding: .5rem 1.25rem;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: clamp(2rem, 9vw, 6rem);
  font-weight: 800;
  white-space: nowrap;
  animation: banner 2.6s ease-out forwards;
}
.banner.capacity { background: var(--down); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .odo-strip { transition: none; }
  .banner { animation: none; transform: translate(-50%, -50%); }
}

.edit-open { font-size: .9rem; }
#edit { margin-bottom: 1rem; }
.edit-actions { margin-top: .75rem; }
