:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #1f1a17;
  --muted: #6b625b;
  --border: #e6ded3;
  --accent: #b4532a;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --done: #9a918a;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412;
    --surface: #221e1b;
    --text: #f2ece6;
    --muted: #a99f97;
    --border: #3a332e;
    --accent: #e08a5d;
    --accent-text: #1a1210;
    --danger: #f2b8b5;
    --done: #756c65;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  text-decoration: none;
}

nav {
  display: flex;
  gap: 4px;
}

.install {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.85rem;
  color: var(--accent);
  border-color: var(--accent);
}

.install[hidden] {
  display: none;
}

.offline {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

nav a {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

nav a.active {
  color: var(--text);
  background: var(--bg);
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

h1 {
  font-size: 1.5rem;
  margin: 8px 0 16px;
  overflow-wrap: anywhere;
}

h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 24px 0 8px;
}

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

textarea,
input[type="password"],
input[type="text"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

textarea {
  min-height: 45vh;
  resize: vertical;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

button.primary,
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.danger {
  color: var(--danger);
}

button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.error {
  color: var(--danger);
  font-weight: 600;
}

.card-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.card a {
  flex: 1;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.card .title {
  display: block;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.card .meta {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
}

.card input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
}

details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

details summary {
  cursor: pointer;
  font-weight: 600;
}

details pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  font-size: 0.95rem;
  margin: 12px 0 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

td.amount {
  text-align: right;
  white-space: nowrap;
  color: var(--muted);
}

.progress {
  position: sticky;
  top: 58px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  background: var(--bg);
}

.progress-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

.items {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.items li + li {
  border-top: 1px solid var(--border);
}

.item {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 60px;
  padding: 10px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.item input {
  flex: none;
  width: 28px;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
}

.item .body {
  flex: 1;
  min-width: 0;
}

.item .name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item .notes {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
}

.item .amount {
  flex: none;
  font-weight: 600;
  text-align: right;
}

.item.checked .name,
.item.checked .amount {
  text-decoration: line-through;
  color: var(--done);
}

.item.checked .notes {
  color: var(--done);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
