:root {
  --cream: #fbf6ea;
  --cream-2: #f1e7d2;
  --ink: #2a2016;
  --muted: #6d5d4a;
  --gold: #e8c35a;
  --gold-ink: #3a2a12;
  --badge: rgba(28, 21, 14, 0.86);
  --badge-ink: #fff7e6;
  --focus: #2f7de1;
  --radius: 16px;
  font-family: 'Tajawal', system-ui, 'Segoe UI', Tahoma, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: linear-gradient(#8fb0cc, #e9c79a 45%, #f0b47a 70%, #d99a62); }
body[data-theme='night'] {
  background:
    radial-gradient(1.5px 1.5px at 12% 8%, #fff, transparent), radial-gradient(1px 1px at 28% 18%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 47% 6%, #fff, transparent), radial-gradient(1px 1px at 63% 14%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 78% 9%, #fff, transparent), radial-gradient(1px 1px at 90% 20%, #fff, transparent),
    radial-gradient(1px 1px at 35% 4%, #fff, transparent), radial-gradient(1px 1px at 7% 22%, #fff, transparent),
    linear-gradient(#050a1a, #142344 55%, #22345a);
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button, input, select, a { font: inherit; }

.badge, .icon-btn, .btn, select, input {
  border-radius: 999px; border: 1px solid rgba(0, 0, 0, .08);
}
.badge { background: var(--badge); color: var(--badge-ink); padding: 4px 12px; font-size: 14px; font-weight: 700; }
.badge.warn { background: #f3d27a; color: #3b2b05; }
.icon-btn { width: 42px; height: 42px; display: grid; place-items: center; background: var(--cream); color: var(--ink); cursor: pointer; text-decoration: none; font-size: 20px; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.btn { padding: 10px 18px; background: var(--cream); color: var(--ink); cursor: pointer; font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; }
.btn.primary { background: var(--gold); color: var(--gold-ink); }
.btn:hover, .icon-btn:hover { filter: brightness(1.05); }

.top { position: fixed; top: 0; inset-inline: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: max(12px, env(safe-area-inset-top)) 16px 0; pointer-events: none; }
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 26px; font-weight: 800; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.45); }
.actions { display: flex; gap: 8px; }

#search { position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 54px); inset-inline-start: 16px; display: flex; flex-wrap: wrap; gap: 6px; width: min(360px, calc(100% - 32px)); }
#search input { flex: 1; min-width: 0; padding: 10px 16px; background: var(--cream); color: var(--ink); min-height: 44px; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.msg { flex-basis: 100%; margin: 0; font-size: 14px; font-weight: 700; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.7); }
.msg:empty { display: none; }

#card { position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 110px); inset-inline-start: 16px; width: min(300px, calc(100% - 32px)); background: var(--cream); border-radius: var(--radius); padding: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
#card h2 { margin: 0 0 4px; font-size: 22px; overflow-wrap: anywhere; }
#card p { margin: 0 0 8px; }
.eyebrow { font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); font-size: 14px; }
.muted:empty { display: none; }
.close { position: absolute; inset-inline-end: 12px; top: 12px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--cream-2); cursor: pointer; font-size: 16px; }

.bottom { position: fixed; bottom: 0; inset-inline: 0; padding: 0 16px max(12px, env(safe-area-inset-bottom)); display: grid; gap: 8px; pointer-events: none; }
.bottom > * { pointer-events: auto; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px; scrollbar-width: none; }
.chips button { flex: none; padding: 8px 14px; border-radius: 999px; border: 0; background: var(--badge); color: var(--badge-ink); font-weight: 700; cursor: pointer; min-height: 40px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
select { padding: 10px 16px; background: var(--cream); color: var(--ink); min-height: 44px; }
.hint { margin: 0; font-size: 13px; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.8); pointer-events: none !important; }

.cam { position: fixed; inset-inline-end: 16px; top: 50%; transform: translateY(-50%); display: grid; gap: 8px; }
.cam .icon-btn { font-size: 22px; font-weight: 800; }
@media (max-width: 600px) { .cam { top: 38%; } .cam .icon-btn { width: 40px; height: 40px; } }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.lm, .plaque { position: absolute; left: 0; top: 0; white-space: nowrap; will-change: transform; }
.lm { background: var(--badge); color: var(--badge-ink); padding: 4px 12px; border-radius: 10px; font-weight: 700; font-size: 15px; pointer-events: auto; cursor: pointer; border: 1px solid rgba(255, 215, 150, .35); }
.plaque { background: rgba(251, 246, 234, .92); color: var(--ink); padding: 1px 7px; border-radius: 6px; font-size: 12px; font-weight: 700; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.plaque.sel { background: var(--gold); font-size: 15px; padding: 3px 10px; max-width: 220px; }

#status { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; background: rgba(28, 21, 14, .78); color: var(--badge-ink); text-align: center; padding: 24px; font-size: 18px; font-weight: 700; }
#status[hidden] { display: none; }
#status p { margin: 0; max-width: 420px; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid rgba(255,255,255,.25); border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.noscript { position: fixed; inset: 0; display: grid; place-content: center; background: var(--cream); font-size: 20px; }

dialog#help { width: min(400px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto; border: 0; border-radius: 20px; padding: 20px; background: var(--cream); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog#help::backdrop { background: rgba(20, 14, 8, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.dlg-head h2 { margin: 0; font-size: 21px; }
.dlg-head .close { position: static; flex: none; }
.steps { list-style: none; counter-reset: s; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; }
.steps li { counter-increment: s; display: flex; gap: 10px; align-items: flex-start; font-size: 17px; font-weight: 700; line-height: 1.5; }
.steps li::before { content: counter(s, arabic-indic); flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: var(--gold); display: grid; place-items: center; font-size: 15px; }
.note { font-size: 14px; color: var(--muted); margin: 0 0 8px; line-height: 1.6; }
.note:empty { display: none; }
.dlg-actions { display: flex; gap: 10px; margin-top: 14px; }
.dlg-actions .btn { flex: 1; border-radius: 14px; }

@media (max-width: 600px) {
  .brand h1 { font-size: 22px; }
  #card { top: auto; bottom: calc(150px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  * { transition: none !important; }
}
