:root {
  --bg: #A6301F;
  --bg-deep: #7C2116;
  --paper: #FFFBF6;
  --paper-shadow: rgba(40, 14, 8, 0.32);
  --ink: #2B1810;
  --ink-soft: #8A6F60;
  --line: #E6D6C6;
  --field: #F6EAE0;
  --field-border: #E4CFBC;
  --accent: #E8536B;
  --accent-ink: #FFFFFF;
  --danger: #A6301F;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #170C09;
    --bg-deep: #0D0705;
    --paper: #241510;
    --paper-shadow: rgba(0, 0, 0, 0.55);
    --ink: #F3E6D8;
    --ink-soft: #B99C89;
    --line: #4A342A;
    --field: #2E1D16;
    --field-border: #4A342A;
    --accent: #FF6F5C;
    --accent-ink: #1A0D08;
    --danger: #FF6F5C;
  }
}

:root[data-theme="dark"] {
  --bg: #170C09;
  --bg-deep: #0D0705;
  --paper: #241510;
  --paper-shadow: rgba(0, 0, 0, 0.55);
  --ink: #F3E6D8;
  --ink-soft: #B99C89;
  --line: #4A342A;
  --field: #2E1D16;
  --field-border: #4A342A;
  --accent: #FF6F5C;
  --accent-ink: #1A0D08;
  --danger: #FF6F5C;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, var(--bg) 0%, var(--bg-deep) 100%);
  color: var(--ink);
  font-family: "Manrope", ui-sans-serif, system-ui, sans-serif;
  display: flex;
  justify-content: center;
  padding: clamp(20px, 5vw, 56px) 16px 64px;
}

.receipt {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 28px 60px -20px var(--paper-shadow);
  clip-path: polygon(
    0% 1.5%, 3% 0%, 6% 1.5%, 9% 0%, 12% 1.5%, 15% 0%, 18% 1.5%, 21% 0%, 24% 1.5%, 27% 0%,
    30% 1.5%, 33% 0%, 36% 1.5%, 39% 0%, 42% 1.5%, 45% 0%, 48% 1.5%, 51% 0%, 54% 1.5%, 57% 0%,
    60% 1.5%, 63% 0%, 66% 1.5%, 69% 0%, 72% 1.5%, 75% 0%, 78% 1.5%, 81% 0%, 84% 1.5%, 87% 0%,
    90% 1.5%, 93% 0%, 96% 1.5%, 99% 0%, 100% 1.5%,
    100% 98.5%, 97% 100%, 94% 98.5%, 91% 100%, 88% 98.5%, 85% 100%, 82% 98.5%, 79% 100%,
    76% 98.5%, 73% 100%, 70% 98.5%, 67% 100%, 64% 98.5%, 61% 100%, 58% 98.5%, 55% 100%,
    52% 98.5%, 49% 100%, 46% 98.5%, 43% 100%, 40% 98.5%, 37% 100%, 34% 98.5%, 31% 100%,
    28% 98.5%, 25% 100%, 22% 98.5%, 19% 100%, 16% 98.5%, 13% 100%, 10% 98.5%, 7% 100%,
    4% 98.5%, 1% 100%, 0% 98.5%
  );
  padding: 40px 30px 34px;
}

.masthead {
  text-align: center;
  margin-bottom: 28px;
}

.note {
  font-family: "Manrope", sans-serif;
  font-style: italic;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.01em;
  color: var(--accent);
  display: block;
  margin: 0 0 4px;
}

h1 {
  font-family: "Sora", ui-sans-serif, system-ui, sans-serif;
  font-weight: 700;
  font-size: 1.9rem;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}

.tagline {
  color: var(--ink-soft);
  font-size: 0.85rem;
  margin: 6px 0 0;
}

.install-row {
  display: flex;
  justify-content: center;
  margin-top: 14px;
  min-height: 34px;
}

.install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-family: "Manrope", sans-serif;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.install-btn:hover { transform: translateY(-1px); }
.install-btn:active { transform: translateY(0); }
.install-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.install-btn[hidden] { display: none; }

.ios-hint {
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-align: center;
  border: 1px dashed var(--field-border);
  border-radius: 10px;
  padding: 6px 12px;
}
.ios-hint[hidden] { display: none; }

.divider {
  border: none;
  border-top: 1px dashed var(--line);
  margin: 24px 0;
}

.add-form {
  display: grid;
  grid-template-columns: 1fr 100px auto;
  gap: 8px;
}

.add-form input,
.field {
  font-family: "Manrope", sans-serif;
  font-size: 0.95rem;
  background: var(--field);
  border: 1px solid var(--field-border);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--ink);
  width: 100%;
}

.add-form input::placeholder { color: var(--ink-soft); }

.add-form input:focus,
.field:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#price-input {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

.add-btn {
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 10px;
  padding: 0 18px;
  font-family: "Manrope", sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.add-btn:hover { opacity: 0.85; }
.add-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.paste-zone {
  margin-top: 10px;
  border: 1.5px dashed var(--field-border);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--ink-soft);
  background: transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.paste-zone strong { color: var(--ink); font-family: "Manrope", sans-serif; font-size: 0.78rem; }
.paste-zone.flash {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.items {
  list-style: none;
  margin: 22px 0 0;
  padding: 0;
}

.item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 9px 0;
}

.item-name {
  font-size: 0.95rem;
  cursor: text;
}

.item-leader {
  flex: 1;
  border-bottom: 1px dotted var(--line);
  height: 0;
  transform: translateY(-4px);
}

.item-price {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  cursor: text;
  white-space: nowrap;
}

.item-remove {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 2px 4px 8px;
  transition: color 0.15s ease;
}
.item-remove:hover { color: var(--danger); }
.item-remove:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.item input {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.95rem;
  background: var(--field);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--ink);
  width: 100%;
}
.item input.name-edit { font-family: "Manrope", sans-serif; }
.item input.price-edit { width: 90px; text-align: right; }

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
  padding: 22px 0 6px;
}
.empty-state[hidden] { display: none; }

.summary {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 2px solid var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.summary-label {
  font-family: "Sora", ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
  font-size: 1.05rem;
}

.summary-count {
  display: block;
  font-family: "Manrope", sans-serif;
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-top: 2px;
}

.summary-total {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 600;
}

.footer-row {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 28px;
}

.stamp {
  font-family: "Manrope", sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.7rem;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  padding: 5px 14px;
  transform: rotate(-3deg);
  opacity: 0.9;
  white-space: nowrap;
}

.footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.footer-dot { color: var(--line); font-size: 0.78rem; }

.text-link {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-family: "Manrope", sans-serif;
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
}
.share-btn:hover { color: var(--accent); }
.clear-btn:hover { color: var(--danger); }
.text-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.theme-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-row-top {
  justify-content: flex-end;
  margin-bottom: 18px;
}

.theme-row-label {
  font-family: "Manrope", sans-serif;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  cursor: pointer;
}

.switch {
  position: relative;
  width: 40px;
  height: 22px;
  padding: 0;
  border-radius: 999px;
  background: var(--field-border);
  border: 1px solid var(--field-border);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.switch[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.switch[aria-checked="true"] .switch-thumb {
  transform: translateX(18px);
}
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--paper);
  font-family: "Manrope", sans-serif;
  font-size: 0.85rem;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (max-width: 380px) {
  .add-form { grid-template-columns: 1fr; }
  #price-input { text-align: left; }
}
