/* Wishlist. Mobile first; wide-screen rules at the bottom. No inline styles anywhere: all of it lives here. */

:root {
  color-scheme: light dark;
  --bg: #fbf4ea;
  --surface: #ffffff;
  --surface-2: #f6e9d9;
  --text: #2e2023;
  --muted: #6d5a5e;
  --border: #e8d6c3;
  --border-strong: #9b8179;
  --primary: #a8324a;
  --primary-hover: #8f2840;
  --primary-text: #ffffff;
  --primary-soft: #f9dfe3;
  --gold: #c98a1b;
  --gold-soft: #fbeccb;
  --good: #2c7a55;
  --good-soft: #dcf1e4;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --focus: #1c6dd0;
  --shadow: 0 1px 2px rgba(70, 30, 30, 0.08), 0 6px 18px rgba(70, 30, 30, 0.07);
  --radius: 16px;
  --tab-h: 64px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1517;
    --surface: #271d20;
    --surface-2: #33262a;
    --text: #f8ece6;
    --muted: #c7b2b2;
    --border: #46343a;
    --border-strong: #8d7479;
    --primary: #ff8da1;
    --primary-hover: #ffa5b4;
    --primary-text: #36070f;
    --primary-soft: #4a2229;
    --gold: #f0b34a;
    --gold-soft: #4a3a17;
    --good: #7fdaa5;
    --good-soft: #1f3a2b;
    --danger: #ff9086;
    --danger-soft: #4a2420;
    --focus: #7ab7ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; font-size: 106.25%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
body.bare { padding-bottom: 0; }
body.modal-open { overflow: hidden; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0; }
p { margin: 0; }
a { color: var(--primary); }
img { max-width: 100%; display: block; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.noscript { padding: 24px; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.skip { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--surface); border: 2px solid var(--primary); border-radius: 10px; padding: 10px 14px; }
.skip:focus { top: 8px; }

/* header and tabs */
.app-header { background: var(--primary); color: var(--primary-text); padding-top: env(safe-area-inset-top); }
.header-inner { max-width: 1040px; margin: 0 auto; padding: 0 16px; min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-family: var(--serif); font-size: 1.4rem; font-weight: 700; min-height: 44px; }
.brand-mark { display: inline-flex; width: 34px; height: 34px; border-radius: 10px; background: rgba(255, 255, 255, 0.2); align-items: center; justify-content: center; }
.brand-mark .icon { width: 22px; height: 22px; }
.top-nav { display: none; }
.tab-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
body.bare .tab-bar, body.bare .top-nav { display: none; }
.tab { flex: 1; min-height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.tab[aria-current="page"] { color: var(--primary); }
.tab[aria-current="page"] .icon { stroke-width: 2.6; }

.main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 32px; outline: none; }
.screen { display: flex; flex-direction: column; gap: 16px; }
.page-title { font-size: 1.75rem; outline: none; }
.section-title { font-size: 1.2rem; }
.block { display: flex; flex-direction: column; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; align-self: flex-start; text-decoration: none; font-weight: 600; }
.divider { border-top: 1px solid var(--border); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.list-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.list-card.primary { border-color: var(--primary); }
.list-card-main { display: flex; align-items: center; gap: 14px; padding: 16px; text-decoration: none; color: inherit; min-height: 44px; }
.list-card-mark { width: 48px; height: 48px; border-radius: 14px; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; flex: none; }
.list-card-mark .icon { width: 26px; height: 26px; }
.list-card-title { font-size: 1.15rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 18px; border-radius: 999px; border: 2px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 700; text-decoration: none; cursor: pointer; line-height: 1.2; }
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--primary); }
.btn-quiet:hover { background: var(--primary-soft); border-color: transparent; }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover { background: var(--danger-soft); }
.btn-small { padding: 6px 12px; font-size: 0.9rem; }
.btn-big { min-height: 52px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.busy::after { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 3px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.link-btn { background: none; border: 0; padding: 8px 4px; min-height: 44px; color: var(--primary); font-weight: 600; text-decoration: underline; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.center-btn { align-self: center; }
.row-actions, .toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 700; }
.field-hint { color: var(--muted); font-size: 0.875rem; }
.input { width: 100%; min-height: 48px; padding: 10px 14px; border: 2px solid var(--border-strong); border-radius: 12px; background: var(--surface); }
textarea.input { resize: vertical; min-height: 88px; }
.input:focus { border-color: var(--primary); }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 14px; font-weight: 600; }
.error-box { background: var(--danger-soft); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.notice { background: var(--gold-soft); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.notice ul { margin: 0; padding-left: 20px; }
.check-row { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; }
.check-row input { width: 22px; height: 22px; accent-color: var(--primary); }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.step-btn { width: 48px; height: 48px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.stepper-input { width: 72px; text-align: center; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .grow { flex: 1 1 220px; }
.import-card { display: flex; flex-direction: column; gap: 10px; background: var(--gold-soft); border-color: var(--gold); }
.import-card .notice { background: var(--surface); }
.import-status:empty { display: none; }
.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 0.9rem; color: var(--muted); }
.rule { display: flex; gap: 8px; }
.rule.ok { color: var(--good); font-weight: 600; }
.rule-mark { width: 1em; text-align: center; }
.image-preview { width: 160px; }
.image-preview .item-img { border-radius: 12px; }

.switch-row { display: flex; gap: 12px; align-items: flex-start; }
.switch { position: relative; display: inline-block; width: 56px; height: 44px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch-track { position: absolute; left: 0; top: 7px; width: 56px; height: 30px; border-radius: 999px; background: var(--border-strong); transition: background 0.15s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(26px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch-text { padding-top: 8px; }
.switch-label { font-weight: 700; }

/* auth and join */
.auth-card { max-width: 440px; margin: 24px auto; width: 100%; display: flex; flex-direction: column; gap: 14px; }
.auth-mark { width: 64px; height: 64px; border-radius: 20px; background: var(--primary-soft); color: var(--primary); margin: 0 auto; display: flex; align-items: center; justify-content: center; }
.auth-mark .icon { width: 36px; height: 36px; }
.auth-title { text-align: center; font-size: 1.6rem; outline: none; }
.join-panel { display: flex; flex-direction: column; gap: 14px; }
body.bare .main { padding-top: 12px; }
body.bare .app-header { background: transparent; color: var(--primary); }
body.bare .brand-mark { background: var(--primary-soft); }

/* list screens */
.item-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; grid-template-columns: 1fr; }
.item-card, .purchase-row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.item-img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--surface-2); }
.item-img.placeholder { display: flex; align-items: center; justify-content: center; color: var(--border-strong); }
.item-img.placeholder .icon { width: 44px; height: 44px; stroke-width: 1.5; }
.item-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.item-name { font-size: 1.1rem; overflow-wrap: anywhere; }
.item-price { font-weight: 800; font-size: 1.1rem; color: var(--primary); }
.item-wants { display: inline-block; align-self: flex-start; background: var(--gold-soft); border-radius: 999px; padding: 2px 12px; font-weight: 700; font-size: 0.9rem; }
.item-note { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
.item-actions { margin-top: auto; padding-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.is-bought .item-img, .is-bought .item-name, .is-bought .item-price, .is-bought .item-note { opacity: 0.55; }
.is-bought { background: var(--surface-2); }
.buyer-lines, .bought-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.buyer-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--good); font-weight: 700; }
.buyer-line .mine { color: var(--primary); }
.bought-box { background: var(--good-soft); border-radius: 12px; padding: 8px 12px; color: var(--text); }
.tag { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 12px; font-size: 0.85rem; font-weight: 700; }
.toggle-purchased { padding: 0 4px; }
.purchase-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.purchase-row { flex-direction: row; }
.purchase-row .item-img { width: 110px; aspect-ratio: 1; flex: none; height: auto; }
.guest-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.guest-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 8px 8px 16px; }

/* states */
.empty { text-align: center; padding: 28px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius); }
.empty-mark { width: 56px; height: 56px; border-radius: 18px; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; }
.empty-mark .icon { width: 30px; height: 30px; }
.empty-title { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; }
.loading { display: flex; align-items: center; gap: 10px; padding: 24px 4px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner, .btn.busy::after { animation-duration: 3s; } .switch-track, .switch-track::after { transition: none; } }

/* dialogs and toasts */
dialog.sheet { border: 0; padding: 0; background: var(--surface); color: var(--text); width: 100%; max-width: 520px; max-height: 92vh; margin: auto auto 0; border-radius: 22px 22px 0 0; box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.3); overflow: auto; }
dialog.sheet::backdrop { background: rgba(40, 10, 20, 0.55); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 8px 4px 20px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sheet-title { font-size: 1.3rem; }
.sheet-body { padding: 8px 20px calc(20px + env(safe-area-inset-bottom)); }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: stretch; z-index: 60; pointer-events: none; gap: 6px; padding: 0 12px; }
body.bare .toasts { bottom: 12px; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); color: #fff; }
.toast-action { background: transparent; border: 2px solid currentColor; color: inherit; border-radius: 999px; min-height: 40px; padding: 4px 16px; font-weight: 800; cursor: pointer; }

/* wide screens */
@media (min-width: 720px) {
  body, body.bare { padding-bottom: 0; }
  .tab-bar { display: none; }
  .top-nav { display: flex; gap: 4px; }
  body.bare .top-nav { display: none; }
  .top-link { color: inherit; text-decoration: none; font-weight: 700; padding: 10px 16px; border-radius: 999px; min-height: 44px; display: inline-flex; align-items: center; }
  .top-link:hover { background: rgba(255, 255, 255, 0.18); }
  .top-link[aria-current="page"] { background: rgba(255, 255, 255, 0.28); }
  .main { padding: 28px 24px 48px; }
  .page-title { font-size: 2.1rem; }
  .item-grid { grid-template-columns: repeat(2, 1fr); gap: 18px; }
  .list-grid { grid-template-columns: repeat(2, 1fr); }
  .toasts { bottom: 20px; align-items: center; }
  .toast { max-width: 480px; }
  dialog.sheet { margin: auto; border-radius: 22px; }
}
@media (min-width: 1000px) {
  .item-grid { grid-template-columns: repeat(3, 1fr); }
  .screen-settings, .screen-share, .screen-purchases { max-width: 640px; }
  .screen-list > .item-form, .screen-list > .import-card { max-width: 640px; }
}

/* long unbroken names must wrap, not scroll the page sideways */
.page-title, .auth-title, .list-card-title, .muted, .guest-row strong, .buyer-line, .sheet-title, .notice { overflow-wrap: anywhere; }
.list-card-main > div, .guest-row > div, .buyer-line > span, .main, .auth-card, .card { min-width: 0; }
.link-note { margin-top: 8px; }
