/* GemBridge portals: shared tokens and components */
:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #f1ece4;
  --ink: #1b1a17;
  --ink-2: #5a554d;
  --ink-3: #8a8378;
  --line: #e5ded3;
  --line-strong: #d3cabc;
  --gold: #9c7a3c;
  --gold-soft: #f3ead9;
  --heart: #b3263e;
  --ok: #2f6b4f;
  --ok-soft: #e4f0e9;
  --warn: #8a5a12;
  --warn-soft: #f6ecd9;
  --danger: #a32a2a;
  --btn-bg: #1b1a17;
  --btn-ink: #f7f4ef;
  --scrim: rgba(20, 18, 15, 0.42);
  --shadow: 0 1px 2px rgba(27, 26, 23, 0.04), 0 6px 24px rgba(27, 26, 23, 0.06);
  --shadow-lg: 0 20px 60px rgba(27, 26, 23, 0.18);
  --radius: 14px;
  --radius-sm: 10px;
  --gutter: 16px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --surface: #1b1a18;
    --surface-2: #252320;
    --ink: #f2eee7;
    --ink-2: #bcb5a9;
    --ink-3: #8b8479;
    --line: #2f2c28;
    --line-strong: #423e38;
    --gold: #cfae6f;
    --gold-soft: #2c261b;
    --heart: #e0566c;
    --ok: #7cc6a0;
    --ok-soft: #1c2b23;
    --warn: #e2b56a;
    --warn-soft: #2d2518;
    --danger: #ef7b7b;
    --btn-bg: #f2eee7;
    --btn-ink: #121110;
    --scrim: rgba(0, 0, 0, 0.6);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html.locked, html.locked body { overflow: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100dvh;
}
img { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 var(--gutter); }

/* Brand */
.brand { display: inline-flex; align-items: baseline; gap: 8px; text-decoration: none; }
.brand-mark { font-family: var(--serif); font-weight: 600; font-size: 23px; letter-spacing: 0.01em; }
.brand-sub { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); }
.brand-gem { width: 16px; height: 16px; align-self: center; color: var(--gold); }

.mockbar {
  background: var(--gold-soft); color: var(--gold); text-align: center;
  font-size: 12px; letter-spacing: 0.04em; padding: 5px var(--gutter);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 999px;
  border: 1px solid transparent; background: var(--btn-bg); color: var(--btn-ink);
  font-weight: 500; font-size: 15px; letter-spacing: 0.01em;
  transition: transform .12s ease, opacity .15s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-quiet { background: transparent; color: var(--ink-2); border-color: transparent; min-height: 40px; padding: 0 10px; }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: 14px; }
.link { background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: 14px; white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .count { font-size: 12px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--gold); color: #fff; display: inline-grid; place-items: center; padding: 0 5px; }

/* Forms */
.field { display: grid; gap: 6px; }
.field > span, .label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.input, .textarea {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 16px;
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 22%, transparent); }
.code-input { letter-spacing: 0.5em; text-align: center; font-size: 24px; font-variant-numeric: tabular-nums; }
.hint { font-size: 13px; color: var(--ink-3); margin: 0; }
.form-error { color: var(--danger); font-size: 14px; margin: 0; }
.debug { font-size: 13px; background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: var(--radius-sm); margin: 0; }

/* Notices */
.notice { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 28px 20px; text-align: center; }
.notice h2 { font-family: var(--serif); font-weight: 600; font-size: 26px; margin: 0 0 6px; line-height: 1.15; }
.notice p { color: var(--ink-2); margin: 0 auto 18px; max-width: 42ch; }
.notice .actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.notice.error { border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; letter-spacing: 0.04em; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.badge-gone { background: var(--warn-soft); color: var(--warn); }
.badge-gold { background: var(--gold-soft); color: var(--gold); }

/* Sign-in layout */
.auth { min-height: calc(100dvh - 40px); display: grid; place-items: center; padding: 32px var(--gutter) 48px; }
.auth-card { width: 100%; max-width: 400px; display: grid; gap: 18px; }
.auth-card .brand { justify-content: center; margin-bottom: 8px; }
.auth-card h1 { font-family: var(--serif); font-weight: 600; font-size: 34px; line-height: 1.1; margin: 0; text-align: center; }
.auth-card .lede { text-align: center; color: var(--ink-2); margin: -6px 0 6px; }
.auth-card form { display: grid; gap: 14px; }
.auth-foot { text-align: center; font-size: 13px; color: var(--ink-3); }

/* Sheets (dialog) */
dialog.sheet {
  padding: 0; border: 0; margin: 0; max-width: none; max-height: none;
  width: 100%; height: 100%; background: transparent; color: var(--ink); overflow: hidden;
}
dialog.sheet::backdrop { background: transparent; }
.sheet-scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity .22s ease; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  padding-bottom: env(safe-area-inset-bottom);
}
dialog.sheet.open .sheet-scrim { opacity: 1; }
dialog.sheet.open .sheet-panel { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px var(--gutter) 10px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 0; line-height: 1.2; }
.sheet-grip { position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--line-strong); }
.sheet-body { overflow-y: auto; padding: 16px var(--gutter) 20px; overscroll-behavior: contain; }
.sheet-foot { display: flex; gap: 10px; padding: 12px var(--gutter) 14px; border-top: 1px solid var(--line); background: var(--surface); }
.sheet-foot .btn { flex: 1; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; border: 1px solid var(--line); background: var(--surface); color: var(--ink); flex: none; }
.icon-btn svg { width: 18px; height: 18px; }
@media (min-width: 760px) {
  .sheet-panel {
    left: 50%; top: 50%; bottom: auto; right: auto; width: min(640px, calc(100vw - 48px)); max-height: min(86dvh, 860px);
    border-radius: 20px; transform: translate(-50%, -46%) scale(.98); opacity: 0; transition: transform .22s ease, opacity .22s ease;
  }
  dialog.sheet.open .sheet-panel { transform: translate(-50%, -50%); opacity: 1; }
  .sheet-grip { display: none; }
  .sheet-panel.wide { width: min(920px, calc(100vw - 48px)); }
}

/* Confirm dialog */
dialog.confirm {
  border: 0; padding: 22px; border-radius: 18px; width: min(380px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.confirm::backdrop { background: var(--scrim); }
dialog.confirm h2 { font-family: var(--serif); font-size: 24px; margin: 0 0 8px; font-weight: 600; line-height: 1.2; }
dialog.confirm p { color: var(--ink-2); margin: 0 0 18px; }
dialog.confirm .row { display: flex; gap: 10px; }
dialog.confirm .row .btn { flex: 1; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Skeleton */
.skel { background: linear-gradient(90deg, var(--surface-2), color-mix(in srgb, var(--surface-2) 50%, var(--surface)), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s infinite linear; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

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

.sheet-head.bare { border-bottom: 0; padding-bottom: 0; }
.sheet-head.bare + .sheet-body { padding-top: 6px; }
.badge { white-space: nowrap; }
body.has-bar #toast { bottom: calc(150px + env(safe-area-inset-bottom)); }
@media (min-width: 760px) { body.has-bar #toast { bottom: 96px; } }
