:root {
  --bg: #f3eee6;
  --paper: #fffcf7;
  --ink: #1c1612;
  --muted: #6d6259;
  --line: #e4d9cc;
  --accent: #1f7a4d;
  --accent-dark: #165c3a;
  --accent-soft: #e5f4ec;
  --danger: #b42318;
  --shadow: 0 10px 28px rgba(48, 32, 18, 0.12);
  --tab-h: calc(72px + env(safe-area-inset-bottom));
  --radius: 22px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

body {
  padding: env(safe-area-inset-top) 0 0;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

img {
  display: block;
  max-width: 100%;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  padding: 12px 16px 8px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.03em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.counts {
  font-size: 14px;
  font-weight: 650;
  color: var(--accent-dark);
  background: var(--accent-soft);
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.reset-btn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: #efe7dc;
  color: var(--danger);
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
  touch-action: manipulation;
}

.reset-btn:active {
  background: #e4d4c6;
}

.strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 2px 6px;
  scrollbar-width: none;
}

.strip::-webkit-scrollbar {
  display: none;
}

.strip-item {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  text-align: center;
}

.strip-item img,
.strip-fallback {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: var(--shadow);
}

.strip-item img.is-box {
  object-fit: contain;
  background: #f4efe8;
}

.strip-fallback {
  display: grid;
  place-items: center;
  background: #d9c3a8;
  font-size: 28px;
}

.strip-copies {
  position: absolute;
  right: -4px;
  top: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.main {
  padding: 8px 16px var(--tab-h);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 12px;
}

@media (min-width: 720px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 16px;
  }
}

.card {
  position: relative;
  background: var(--paper);
  border: 3px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: left;
  touch-action: manipulation;
  transform: translateZ(0);
}

.card-hit {
  display: block;
  width: 100%;
  text-align: left;
}

.stepper-wrap {
  padding-top: 0;
}

.sheet-card {
  max-height: min(88dvh, 820px);
  display: flex;
  flex-direction: column;
}

.sheet-handle {
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: #d8cbbd;
  margin: 0 auto 14px;
}

.ing-list {
  overflow-y: auto;
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  padding-right: 2px;
}

.ing-row {
  display: grid;
  grid-template-columns: 36px 40px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: 8px 10px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(48, 32, 18, 0.06);
  text-align: left;
}

.qty-stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-stepper b {
  min-width: 2.6em;
  text-align: center;
  font-size: 15px;
}

.qty-stepper .step {
  width: 40px;
  height: 40px;
  font-size: 22px;
}

.item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--paper);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: 0 6px 16px rgba(48, 32, 18, 0.06);
  margin-bottom: 8px;
}

.ing-row.is-off {
  opacity: 0.55;
}

.ing-row.is-off .ing-copy b {
  text-decoration: line-through;
}

.ing-check {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.ing-row.is-off .ing-check {
  background: #efe7dc;
  color: transparent;
}

.ing-emoji {
  font-size: 26px;
  text-align: center;
}

.ing-copy b {
  display: block;
  font-size: 16px;
}

.ing-copy small {
  color: var(--muted);
  font-size: 13px;
}

.sheet-actions {
  display: grid;
  gap: 8px;
}

.card.is-on {
  border-color: var(--accent);
}

.card-photo,
.card-fallback {
  height: 132px;
  width: 100%;
  object-fit: cover;
  background: #d9c3a8;
}

.card-photo.is-box {
  object-fit: contain;
  background: #f4efe8;
}

.card-fallback {
  display: grid;
  place-items: center;
  font-size: 56px;
}

.card-body {
  padding: 10px 12px 12px;
}

.card-name {
  margin: 0;
  font-size: 16px;
  font-weight: 750;
  line-height: 1.2;
}

.card-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: none;
  place-items: center;
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(31, 122, 77, 0.35);
}

.card.is-on .check {
  display: grid;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.stepper b {
  font-size: 18px;
}

.step {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 28px;
  line-height: 1;
  font-weight: 700;
}

.step:active {
  background: #cfe8da;
}

.list-wrap {
  display: grid;
  gap: 18px;
  padding-bottom: 24px;
}

.cat {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--paper);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: 0 6px 16px rgba(48, 32, 18, 0.06);
  margin-bottom: 8px;
}

.item-emoji {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: #f0e7db;
  font-size: 24px;
}

.item-name {
  font-weight: 700;
}

.item-desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  margin-top: 2px;
}

.item-qty {
  font-weight: 800;
  color: var(--accent-dark);
  white-space: nowrap;
}

.actions {
  position: sticky;
  bottom: calc(var(--tab-h) + 8px);
  display: grid;
  gap: 10px;
  margin-top: 8px;
  padding: 12px 0 8px;
  background: linear-gradient(to bottom, transparent, var(--bg) 24%);
  z-index: 4;
}

.btn {
  min-height: 56px;
  border-radius: 18px;
  font-size: 17px;
  font-weight: 750;
  padding: 0 16px;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:active {
  background: var(--accent-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--danger);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 12px;
  font-size: 17px;
}

.preview-sheet {
  background: #fff;
  color: #000;
  border-radius: 16px;
  padding: 20px 18px 24px;
  box-shadow: var(--shadow);
}

.preview-sheet h2 {
  margin: 0 0 14px;
  font-size: 22px;
}

.preview-sheet ol {
  margin: 0;
  padding: 0 0 0 1.3em;
  font-size: 16px;
  line-height: 1.55;
}

.preview-sheet li {
  margin: 0 0 10px;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr 1fr;
  max-width: 1100px;
  margin: 0 auto;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 56px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tab svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.tab.is-active {
  color: var(--accent-dark);
}

.badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 28px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  display: grid;
  place-items: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + 8px);
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: min(92vw, 420px);
  background: #1c1612;
  color: #fff;
  border-radius: 16px;
  padding: 14px 16px;
  font-weight: 650;
  box-shadow: var(--shadow);
}

.toast button {
  margin-left: auto;
  color: #b7f0cf;
  font-weight: 800;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(28, 22, 18, 0.45);
  display: grid;
  place-items: end center;
}

.modal-card {
  width: min(100%, 520px);
  background: var(--paper);
  border-radius: 24px 24px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 22px;
}

.modal-card p {
  margin: 0 0 16px;
  color: var(--muted);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-cancel {
  background: #efe7dc;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

@media (min-width: 720px) {
  .modal {
    place-items: center;
  }
  .modal-card {
    border-radius: 24px;
    padding-bottom: 20px;
  }
}
