:root {
  --paper: #f7f5f0;
  --panel: #fffdf9;
  --ink: #1d1b17;
  --ink-2: #57534a;
  --ink-3: #8a857a;
  --rule: #e4dfd4;
  --rule-strong: #cfc8b9;
  --accent: #2f4fd8;
  --accent-ink: #ffffff;
  --accent-wash: #e9edfc;
  --ok: #217a4b;
  --warn: #9a5b00;
  --bad: #b02a1f;
  --bad-wash: #fbecea;
  --shadow: 0 1px 2px rgb(40 30 10 / 6%), 0 8px 24px -12px rgb(40 30 10 / 14%);
  --radius: 14px;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15140f;
    --panel: #1d1b16;
    --ink: #f1ede4;
    --ink-2: #bdb6a8;
    --ink-3: #8c8679;
    --rule: #302d26;
    --rule-strong: #46423a;
    --accent: #8ea4ff;
    --accent-ink: #10142a;
    --accent-wash: #232a4a;
    --ok: #6fd19c;
    --warn: #f0b860;
    --bad: #ff8f84;
    --bad-wash: #3a1e1b;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 12px 28px -14px rgb(0 0 0 / 60%);
  }
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
.wrap {
  width: min(1120px, 100% - 40px);
  margin-inline: auto;
}
a {
  color: var(--accent);
  text-underline-offset: 3px;
}
h1,
h2 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
h2 {
  font-size: 1.2rem;
}
p {
  margin: 0;
}
.muted {
  color: var(--ink-3);
}
.small {
  font-size: 0.875rem;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Header */
.bar {
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 2;
}
.bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  white-space: nowrap;
}
.brand-mark {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.badge {
  font-size: 0.8rem;
  color: var(--ink-2);
  text-decoration: none;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  padding: 4px 12px;
  white-space: nowrap;
}
@media (max-width: 480px) {
  .badge .wide {
    display: none;
  }
}
.badge:hover {
  color: var(--ink);
  border-color: var(--ink-3);
}

/* Intro */
.intro {
  padding: 44px 0 24px;
  max-width: 640px;
}
.intro h1 {
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  line-height: 1.15;
  margin-bottom: 10px;
}
.lead {
  font-size: 1.08rem;
  color: var(--ink-2);
}

.notice {
  border: 1px solid var(--bad);
  background: var(--bad-wash);
  color: var(--bad);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

/* Desk layout */
.desk {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .desk {
    grid-template-columns: minmax(0, 1fr);
  }
}
.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.compose {
  display: grid;
  gap: 18px;
}

/* Tasks */
.tasks {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}
.tasks legend {
  font-weight: 600;
  margin-bottom: 10px;
  padding: 0;
}
.task-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.task {
  position: relative;
}
.task input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.task span {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  color: var(--ink-2);
  background: transparent;
  font-size: 0.95rem;
  transition:
    background 120ms,
    color 120ms,
    border-color 120ms;
  user-select: none;
}
.task input:hover + span {
  border-color: var(--ink-3);
  color: var(--ink);
}
.task input:checked + span {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.task input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.task-hint {
  color: var(--ink-3);
  font-size: 0.875rem;
  margin-top: 10px;
  min-height: 1.4em;
}
.skeleton {
  display: inline-block;
  width: 92px;
  height: 36px;
  border-radius: 999px;
  background: var(--rule);
  animation: pulse 1.2s ease-in-out infinite alternate;
}
@keyframes pulse {
  to {
    opacity: 0.45;
  }
}

/* Fields */
.option {
  display: flex;
  align-items: center;
  gap: 10px;
}
.option label {
  font-weight: 600;
}
select,
textarea {
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
}
select {
  padding: 7px 10px;
}
textarea {
  width: 100%;
  padding: 12px 14px;
  resize: vertical;
  min-height: 220px;
  line-height: 1.6;
}
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
.field-head,
.field-foot,
.section-head,
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.field-head {
  margin-bottom: 8px;
}
.field-head label {
  font-weight: 600;
}
.field-foot {
  margin-top: 6px;
}
.count {
  font-size: 0.85rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.count.over {
  color: var(--bad);
  font-weight: 600;
}

/* Buttons */
button {
  font: inherit;
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 10px;
  padding: 11px 20px;
  font-weight: 600;
  min-width: 150px;
}
.primary:not(:disabled):hover {
  filter: brightness(1.06);
}
.ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.9rem;
}
.ghost:hover {
  color: var(--ink);
  border-color: var(--ink-3);
}
.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-size: 0.9rem;
}
.link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.submit-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.hint {
  font: 0.8rem var(--sans);
  color: var(--ink-3);
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
}

/* Result */
.result {
  display: grid;
  gap: 16px;
  align-content: start;
}
@media (min-width: 861px) {
  .result {
    position: sticky;
    top: 80px;
  }
}
.result-actions {
  display: flex;
  gap: 8px;
}
.idle {
  border: 1px dashed var(--rule-strong);
  border-radius: 10px;
  padding: 28px 20px;
  text-align: center;
  display: grid;
  gap: 6px;
  color: var(--ink-2);
}
.idle .muted {
  font-size: 0.875rem;
}
.working {
  display: grid;
  gap: 14px;
  justify-items: start;
}
.steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
}
.steps li {
  flex: 1 1 0;
  min-width: 70px;
  font-size: 0.8rem;
  color: var(--ink-3);
  padding-top: 8px;
  border-top: 3px solid var(--rule);
  transition:
    border-color 200ms,
    color 200ms;
}
.steps li.done {
  border-color: var(--ink-2);
  color: var(--ink-2);
}
.steps li.current {
  border-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
}
.working-line {
  display: flex;
  align-items: center;
  gap: 10px;
}
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--rule-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}
#elapsed {
  font-variant-numeric: tabular-nums;
}
.output {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--serif);
  font-size: 1.06rem;
  line-height: 1.7;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 16px 18px;
  max-height: 60vh;
  overflow: auto;
  animation: rise 220ms ease-out;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}
.meta {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--ink-3);
}
.failure {
  border: 1px solid var(--bad);
  background: var(--bad-wash);
  color: var(--bad);
  border-radius: 10px;
  padding: 14px 16px;
  display: grid;
  gap: 10px;
  justify-items: start;
}
.failure .ghost {
  color: var(--bad);
  border-color: currentColor;
}

/* History */
.history {
  margin-top: 36px;
}
.history-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}
.history-list button {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: baseline;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--ink);
}
.history-list button:hover {
  border-color: var(--rule-strong);
}
.history-task {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.history-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-2);
}
.history-when {
  font-size: 0.8rem;
  color: var(--ink-3);
  white-space: nowrap;
}

/* How it works */
.how {
  margin: 48px 0 24px;
  padding-top: 32px;
  border-top: 1px solid var(--rule);
  display: grid;
  gap: 16px;
  max-width: 820px;
}
.how > p {
  color: var(--ink-2);
}
.flow {
  list-style: none;
  counter-reset: flow;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 720px) {
  .flow {
    grid-template-columns: minmax(0, 1fr);
  }
}
.flow li {
  counter-increment: flow;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 14px 16px;
  display: grid;
  gap: 4px;
  font-size: 0.93rem;
  color: var(--ink-2);
}
.flow li::before {
  content: counter(flow);
  font: 600 0.8rem var(--mono);
  color: var(--accent);
}
.flow strong {
  color: var(--ink);
}
.quota {
  display: grid;
  gap: 8px;
  max-width: 480px;
}
.quota-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}
#quota-text {
  font-variant-numeric: tabular-nums;
}
.meter {
  height: 8px;
  border-radius: 999px;
  background: var(--rule);
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ok);
  border-radius: inherit;
  transition: width 400ms ease;
}
.meter.high span {
  background: var(--warn);
}
.meter.full span {
  background: var(--bad);
}
.links {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.foot {
  font-size: 0.85rem;
  padding: 20px 0 40px;
  border-top: 1px solid var(--rule);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
