:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --text: #1a1f1c;
  --muted: #5c6b62;
  --border: #d8e2dc;
  --primary: #1a7a4c;
  --primary-press: #14603c;
  --danger: #b33a3a;
  --bought: #8a978e;
  --shadow: 0 8px 24px rgba(20, 40, 28, 0.08);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; }
.hidden { display: none !important; }

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(12px + var(--safe-t)) 14px calc(24px + var(--safe-b));
}

.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero { text-align: center; padding: 36px 8px 20px; }
.logo { font-size: 48px; line-height: 1; }
.hero h1 { margin: 8px 0 6px; font-size: 1.85rem; letter-spacing: -0.02em; }
.tagline { margin: 0; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.hint { text-align: center; color: var(--muted); font-size: 0.92rem; margin-top: 18px; padding: 0 8px; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, transform .08s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-press); }
.btn-secondary { background: #e8f2ec; color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-lg { padding: 14px 18px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.55; cursor: default; }

.divider {
  display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  background: #fafcfb;
}
.join-row input:focus, .add-fields input:focus, #share-url:focus {
  outline: 2px solid rgba(26,122,76,.35); border-color: var(--primary);
}

.topbar {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px;
}
.topbar-center { flex: 1; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.code-pill {
  font-size: 0.78rem; color: var(--primary); letter-spacing: 0.08em; font-weight: 700;
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-size: 1.15rem; cursor: pointer;
}

.add-bar {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}
.add-fields { display: flex; gap: 8px; grid-column: 1 / -1; }
.add-fields #item-name { flex: 1; }
.add-fields #item-qty { width: 88px; }
.add-fields input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: #fafcfb;
}
#btn-add { grid-column: 2; }

.suggest {
  position: absolute;
  left: 10px; right: 10px; top: calc(100% - 2px);
  z-index: 20;
  margin: 0; padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow: auto;
}
.suggest li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
}
.suggest li:hover, .suggest li.active { background: #eef7f1; }
.suggest .cat { color: var(--muted); font-size: 0.8rem; }

.list-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin: 4px 2px 10px; min-height: 28px;
}
.sync { font-size: 0.8rem; color: var(--muted); }
.sync.ok { color: var(--primary); }
.sync.err { color: var(--danger); }
.link-btn {
  border: none; background: none; color: var(--primary);
  font-weight: 600; font-size: 0.85rem; cursor: pointer; padding: 4px 0;
}

.section-title {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 16px 4px 8px; font-weight: 700;
}

.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px 8px 6px;
}
.item.bought .item-name { text-decoration: line-through; color: var(--bought); }
.item.bought { opacity: 0.78; }

.check {
  width: 28px; height: 28px; margin: 0 auto;
  border-radius: 999px; border: 2px solid var(--primary);
  background: transparent; cursor: pointer;
  display: grid; place-items: center; color: #fff; font-size: 0.85rem;
}
.item.bought .check { background: var(--primary); }

.item-main { min-width: 0; }
.item-name { font-weight: 600; word-break: break-word; }
.item-qty { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

.del {
  border: none; background: transparent; color: var(--muted);
  font-size: 1.2rem; width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
}
.del:active { background: #f3e0e0; color: var(--danger); }

.empty {
  text-align: center; color: var(--muted); padding: 36px 12px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10,20,14,.45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + var(--safe-b));
  box-shadow: 0 -10px 40px rgba(0,0,0,.15);
  max-width: 520px; margin: 0 auto;
}
.sheet-panel h2 { margin: 0 0 8px; }
.share-code { margin: 0 0 12px; color: var(--muted); }
#share-url {
  width: 100%; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; margin-bottom: 12px; background: #fafcfb;
}
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet-actions .btn-ghost { grid-column: 1 / -1; }
.toast {
  text-align: center; color: var(--primary); font-weight: 700; margin: 10px 0 0;
}

@media (min-width: 600px) {
  .sheet-panel { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 20px; left: 14px; right: 14px; }
}

.qty-toggle {
  border: 1px solid var(--border);
  background: #eef5f0;
  color: var(--muted);
  border-radius: 10px;
  min-width: 42px;
  font-weight: 700;
  cursor: pointer;
}
.qty-input { max-width: 88px; }
.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  overflow: visible;
  padding: 4px 0 10px;
  max-width: 100%;
}
.chip {
  flex: 0 1 auto;
  max-width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:active { background: #e8f2ec; }
.live-toast {
  position: sticky;
  top: 8px;
  z-index: 5;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #143528;
  color: #fff;
  font-weight: 600;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  animation: fade .15s ease;
}
.live-toast.hidden { display: none !important; }
.peers { color: var(--muted); font-size: 0.82rem; }
.item.flash {
  animation: flash 0.7s ease;
}
@keyframes flash {
  0% { background: #d8f5e4; }
  100% { background: transparent; }
}
.add-fields { display: flex; gap: 8px; align-items: stretch; flex: 1; }
.add-fields input[type="text"] {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 0;
}

.item-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.item-line .item-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-line .item-qty {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  flex: 0 0 auto;
  white-space: nowrap;
}
.item-line .item-qty::before {
  content: "· ";
  color: var(--border);
}

.logo-img {
  display: block;
  margin: 0 auto;
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.home-actions {
  text-align: center;
  margin-top: 14px;
}
.install-card {
  margin-top: 12px;
}
.install-card > .logo-img {
  margin-bottom: 4px;
}
.install-block h3 {
  margin: 8px 0 6px;
  font-size: 1rem;
}
.install-block ol {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.45;
}
.install-block li { margin: 4px 0; }
.icon-btn svg {
  display: block;
}
.check svg {
  display: block;
}

.qty-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  margin-left: auto;
}
.qty-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #eef5f0;
  color: var(--primary);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.qty-btn:active { background: #dceee4; }
.qty-controls .item-qty {
  min-width: 1.6rem;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
}
.qty-controls .item-qty-empty {
  color: var(--bought);
}
.qty-controls .item-qty::before { content: none; }
