:root {
  --amber: #ffb24a;
  --amber-2: #ff9a2e;
  --ink: #2b1405;
  --panel: rgba(28, 18, 30, 0.78);
  --panel-line: rgba(255, 190, 120, 0.25);
  --text: #fff4e6;
  --muted: #e6c9a8;
  --font: "Tajawal", "Tahoma", "Segoe UI", system-ui, sans-serif;
  --top: env(safe-area-inset-top);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a1a2e; color: var(--text); font-family: var(--font); }
body { position: fixed; inset: 0; overscroll-behavior: none; }
#c { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; outline: none; }
body.driving #searchbar, body.driving #help-btn, body.driving #help, body.driving #t-follow { display: none; }
/* studio (?studio=1): the picture only */
body.studio #top, body.studio #searchbar, body.studio #help-btn, body.studio #help, body.studio #card, body.studio #labels,
body.studio #coach, body.studio #hud, body.studio #story { display: none !important; }

/* ---------- header: one line, the count beside the name */
#top {
  position: fixed; top: 0; inset-inline: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(8px + var(--top)) 16px 8px;
  background: linear-gradient(to bottom, rgba(20, 12, 24, 0.72), rgba(20, 12, 24, 0));
  pointer-events: none;
}
.title { font-weight: 800; font-size: 18px; letter-spacing: 0; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5); white-space: nowrap; }
.count { font-size: 13px; color: var(--muted); font-weight: 500; }
.count b { color: var(--amber); font-weight: 800; }
.follow {
  pointer-events: auto; direction: ltr; unicode-bidi: isolate;
  font-weight: 800; font-size: 14px; color: var(--ink); text-decoration: none;
  background: linear-gradient(180deg, #ffc56a, var(--amber-2)); padding: 7px 13px; border-radius: 999px;
  box-shadow: 0 2px 10px rgba(255, 140, 40, 0.35);
}

/* ---------- search */
#searchbar {
  position: fixed; z-index: 6; top: calc(52px + var(--top)); inset-inline: 16px;
  display: flex; gap: 8px; max-width: 520px; margin-inline: auto;
}
#q {
  flex: 1; min-width: 0; height: 44px; border-radius: 22px; border: 1px solid var(--panel-line);
  background: var(--panel); color: var(--text); font: 500 16px var(--font); padding: 0 18px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); outline: none;
  unicode-bidi: plaintext;
}
#q::placeholder { color: rgba(255, 230, 200, 0.7); }
#q:focus { border-color: var(--amber); }
#q.pulse { animation: pulse 0.6s ease-in-out 2; }
@keyframes pulse { 50% { border-color: var(--amber); box-shadow: 0 0 0 4px rgba(255, 178, 74, 0.35); } }
#landmarks-btn {
  width: 44px; height: 44px; flex: none; border-radius: 22px; border: 1px solid var(--panel-line); background: var(--panel);
  color: var(--amber); font-size: 19px; cursor: pointer; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#results, #landmarks {
  position: absolute; top: 50px; inset-inline: 0; margin: 0; padding: 6px; list-style: none;
  background: rgba(28, 18, 30, 0.95); border: 1px solid var(--panel-line); border-radius: 16px;
  max-height: min(62vh, 460px); overflow-y: auto; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
#results li {
  min-height: 44px; padding: 12px; border-radius: 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
#results li:hover, #results li.on { background: rgba(255, 178, 74, 0.16); }
#results .main { font-weight: 800; font-size: 15px; unicode-bidi: plaintext; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#results .sub { font-size: 14px; color: var(--muted); white-space: nowrap; unicode-bidi: plaintext; }
#results .mine { font: 800 12px var(--font); color: var(--ink); background: var(--amber); border-radius: 999px; padding: 2px 8px; margin-inline-start: 6px; }
#results .none { color: var(--muted); cursor: default; display: block; line-height: 1.5; }
#results .none small { display: block; font-size: 13px; opacity: 0.8; margin-top: 4px; }
#coach {
  position: absolute; top: 52px; inset-inline: 0; text-align: center; font-size: 14px; color: #ffe2b8; pointer-events: none;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7); animation: fadein 0.6s ease-out;
}
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }

/* landmarks: the city's granted buildings as a grid of their story tiles */
.lm-head { font-weight: 800; font-size: 16px; color: var(--amber); padding: 6px 8px 8px; }
#lm-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#lm-list li { border-radius: 12px; cursor: pointer; padding: 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
#lm-list li:hover { background: rgba(255, 178, 74, 0.14); }
#lm-list img, #lm-list .ph { width: 96px; height: 96px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); object-fit: cover; }
#lm-list .main { font-weight: 800; font-size: 14px; }
#lm-list .sub { font-size: 12.5px; color: var(--muted); unicode-bidi: plaintext; }
#lm-list li.teaser { grid-column: 1 / -1; flex-direction: row; justify-content: center; background: rgba(255, 178, 74, 0.12); font-weight: 800; color: var(--amber); padding: 10px; }
@media (min-width: 700px) { #lm-list { grid-template-columns: 1fr 1fr 1fr; } }

/* ---------- name tags over houses (the films' amber plates) */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.tag {
  position: absolute; left: 0; top: 0; transform-origin: 50% 100%; will-change: transform;
  font: 800 13px/1 var(--font); color: var(--ink); white-space: nowrap; unicode-bidi: plaintext;
  background: linear-gradient(180deg, #ffcf7f, var(--amber)); padding: 5px 10px 6px; border-radius: 999px;
  box-shadow: 0 0 12px rgba(255, 160, 60, 0.55), 0 2px 4px rgba(0, 0, 0, 0.35);
}
.tag::after {
  content: ""; position: absolute; left: 50%; bottom: -5px; margin-left: -5px;
  border: 5px solid transparent; border-bottom: 0; border-top-color: var(--amber);
}
.tag.grant { font-size: 14px; background: linear-gradient(180deg, #fff0c8, #ffc35c); }
.tag.small { font-size: 11px; padding: 4px 8px 5px; opacity: 0.92; }
.tag.sign { background: linear-gradient(180deg, #ffe08a, #f5b300); font-size: 16px; }
.tag.hero { font-size: 17px; padding: 7px 14px 8px; box-shadow: 0 0 24px rgba(255, 180, 70, 0.9), 0 2px 6px rgba(0, 0, 0, 0.4); }
.tag.empty { background: linear-gradient(180deg, #fff8ea, #f0e2c8); }

/* ---------- info card */
#card {
  position: fixed; z-index: 7; inset-inline: 12px; bottom: calc(14px + env(safe-area-inset-bottom));
  max-width: 460px; margin-inline: auto; padding: 16px 18px 12px; border-radius: 20px;
  background: rgba(28, 18, 30, 0.92); border: 1px solid var(--panel-line); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: rise 0.35s ease-out;
}
#card.still { animation: none; }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
#card-close {
  position: absolute; top: 2px; inset-inline-end: 4px; width: 44px; height: 44px;
  background: none; border: 0; color: var(--muted); font-size: 26px; cursor: pointer; line-height: 1;
}
#card-title { font-weight: 800; font-size: 21px; color: var(--amber); margin-inline-end: 34px; text-align: right; unicode-bidi: plaintext; }
#card-sub { font-size: 15px; color: var(--muted); margin-top: 3px; text-align: right; unicode-bidi: plaintext; }
#card-note { font-size: 15px; margin-top: 10px; line-height: 1.55; unicode-bidi: plaintext; }
#card-note:empty { display: none; }
#card-owns { margin-top: 8px; font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#card-owns button { font: 800 13px var(--font); color: var(--amber); background: rgba(255, 178, 74, 0.14); border: 1px solid var(--panel-line); border-radius: 999px; padding: 5px 10px; cursor: pointer; }
#card .primary {
  display: block; width: 100%; height: 48px; margin-top: 12px; border: 0; border-radius: 999px; cursor: pointer; text-align: center;
  font: 800 16px/48px var(--font); text-decoration: none; background: linear-gradient(180deg, #ffc56a, var(--amber-2)); color: var(--ink);
}
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; justify-content: center; align-items: center; }
/* the house's level and the way to the next one: proud, small, opens the levels panel */
#card-level {
  font: 800 13px var(--font); color: #ffe2b8; background: rgba(255, 178, 74, 0.14); border: 1px solid var(--panel-line);
  border-radius: 999px; padding: 7px 12px; min-height: 36px; cursor: pointer; unicode-bidi: plaintext; text-align: center;
}
#card-level b { color: var(--amber); }
.card-actions .text { font: 800 14px var(--font); background: none; border: 0; color: var(--amber); padding: 10px 12px; min-height: 44px; cursor: pointer; }
.card-actions .text + .text::before { content: "·"; color: var(--muted); margin-inline-end: 12px; }
@media (min-width: 700px) {
  #card .primary { display: inline-block; width: auto; padding: 0 26px; }
  .card-actions { justify-content: flex-start; display: inline-flex; margin-inline-start: 8px; }
}

/* ---------- loader: the film's first frame, blurred */
#loader {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: #2a1a2e url("img/loader.jpg") center / cover no-repeat; transition: opacity 0.8s ease;
}
#loader::before { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(5, 8, 22, 0.7), rgba(42, 26, 46, 0.45) 50%, rgba(90, 40, 15, 0.55)); }
#loader > * { position: relative; }
#loader.gone { opacity: 0; pointer-events: none; }
#loader.done { display: none; }
.loader-title { font-weight: 800; font-size: 30px; color: #ffe2b8; text-shadow: 0 0 20px rgba(255, 150, 60, 0.6); }
.loader-bar { width: min(240px, 60vw); height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.loader-bar i { display: block; height: 100%; width: 0; background: var(--amber); transition: width 0.3s ease; }
.loader-msg { font-size: 15px; color: var(--muted); }
.loader-fail { display: flex; gap: 12px; align-items: center; }
.loader-fail button { font: 800 15px var(--font); border: 0; border-radius: 999px; padding: 10px 20px; background: linear-gradient(180deg, #ffc56a, var(--amber-2)); color: var(--ink); cursor: pointer; }
.loader-fail a { color: var(--amber); font-weight: 800; direction: ltr; }

/* ---------- ? controls panel: under the follow pill */
#help-btn {
  position: fixed; z-index: 6; left: 16px; top: calc(52px + var(--top));
  width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--panel-line); background: var(--panel);
  color: var(--amber); font: 800 20px var(--font); cursor: pointer; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#help-btn[aria-expanded="true"] { background: linear-gradient(180deg, #ffc56a, var(--amber-2)); color: var(--ink); }
#help-btn.nudge { animation: nudge 1.4s ease-in-out 3; }
@keyframes nudge { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 178, 74, 0); } 50% { box-shadow: 0 0 0 8px rgba(255, 178, 74, 0.35); } }
#help {
  position: fixed; z-index: 8; left: 16px; top: calc(104px + var(--top)); width: min(360px, calc(100vw - 32px)); padding: 16px 18px; border-radius: 18px;
  background: rgba(28, 18, 30, 0.95); border: 1px solid var(--panel-line); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  max-height: calc(100vh - 130px - var(--top)); overflow: auto;
}
#help-close {
  position: absolute; top: 2px; inset-inline-end: 4px; width: 44px; height: 44px;
  border: 0; background: none; color: var(--muted); font-size: 26px; cursor: pointer;
}
.help-title { font-weight: 800; font-size: 18px; color: var(--amber); margin: 6px 0 12px; }
/* narrow screens: the search bar spans the top, so the ? sits in the bottom corner (a card slides over it) and opens upward */
@media (max-width: 899px) {
  #help-btn { top: auto; bottom: calc(16px + env(safe-area-inset-bottom)); }
  #help { top: auto; bottom: calc(70px + env(safe-area-inset-bottom)); max-height: calc(100vh - 200px); }
}
#help-levels { margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--panel-line); }
.lv-rule { font-size: 14px; line-height: 1.6; color: var(--text); margin-bottom: 10px; }
#lv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#lv-list li { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
#lv-list li.mine { background: rgba(255, 178, 74, 0.16); outline: 1px solid var(--panel-line); }
#lv-list .ic { font-size: 20px; text-align: center; }
#lv-list .nm { font-weight: 800; color: var(--amber); }
#lv-list .nt { display: block; font-weight: 500; font-size: 12.5px; color: var(--muted); }
#lv-list .th { font-size: 13px; color: var(--text); white-space: nowrap; }
.lv-soon { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
#help-rows { display: grid; grid-template-columns: auto 1fr; gap: 9px 14px; margin: 0; align-items: center; }
#help-rows dt { font-size: 14px; color: var(--muted); white-space: nowrap; }
#help-rows dd { margin: 0; font-size: 13.5px; color: var(--text); line-height: 1.7; }
.help-car { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--panel-line); font-size: 13.5px; line-height: 1.8; color: var(--text); }
.help-car:empty { display: none; }
#help .caps { unicode-bidi: isolate; white-space: nowrap; }
#help kbd {
  display: inline-block; min-width: 24px; text-align: center; direction: ltr; unicode-bidi: isolate; margin: 0 2px;
  font: 700 12px ui-monospace, monospace; color: #fff4e6; background: rgba(255, 255, 255, 0.10); border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px;
}

/* ---------- story picture preview */
#story { position: fixed; inset: 0; z-index: 11; display: flex; align-items: center; justify-content: center; background: rgba(8, 6, 14, 0.82); padding: 16px; }
.story-box { position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; max-height: 100%; }
#story-close { position: absolute; top: -10px; inset-inline-end: -10px; z-index: 2; width: 44px; height: 44px; border-radius: 22px; border: 0; background: rgba(28, 18, 30, 0.92); color: var(--text); font-size: 24px; cursor: pointer; }
.story-frame { position: relative; height: min(66vh, 760px); aspect-ratio: 9 / 16; border-radius: 14px; overflow: hidden; box-shadow: 0 16px 50px rgba(0, 0, 0, 0.6);
  background: linear-gradient(110deg, #2a1a2e 30%, #3a2440 50%, #2a1a2e 70%) 0 0 / 300% 100%; animation: shimmer 1.6s linear infinite; }
.story-frame.ready { animation: none; background: #2a1a2e; }
@keyframes shimmer { to { background-position: -300% 0; } }
#story-img { display: block; width: 100%; height: 100%; }
#story-img:not([src]) { visibility: hidden; }
#story-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 15px; }
#story-msg:empty { display: none; }
#story-ig { max-width: 360px; text-align: center; font-size: 15px; line-height: 1.5; color: var(--amber); unicode-bidi: plaintext; }
.story-actions { display: flex; gap: 10px; }
.story-actions button, .story-actions a { font: 800 15px var(--font); border-radius: 999px; padding: 12px 22px; cursor: pointer; text-decoration: none; border: 0; }
#story-share { background: linear-gradient(180deg, #ffc56a, var(--amber-2)); color: var(--ink); }
#story-save { background: rgba(255, 178, 74, 0.16); color: var(--amber); border: 1px solid var(--panel-line); }
#story-save:empty { display: none; }
#story-hint { color: var(--muted); font-size: 13.5px; text-align: center; max-width: 360px; unicode-bidi: plaintext; }

/* ---------- driving: out of the way of the street */
#drive-exit {
  position: fixed; z-index: 7; left: 16px; top: calc(12px + var(--top)); height: 36px; padding: 0 16px;
  font: 800 14px var(--font); border-radius: 999px; border: 0; cursor: pointer; background: linear-gradient(180deg, #ffc56a, var(--amber-2)); color: var(--ink);
}
#drive-speed { position: fixed; z-index: 7; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); direction: ltr; font: 800 22px var(--font); color: #fff4e6; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); pointer-events: none; }
#drive-speed b { color: var(--amber); }
#drive-hint { position: fixed; z-index: 7; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom)); font-size: 13.5px; color: var(--text); background: var(--panel); padding: 6px 12px; border-radius: 999px; pointer-events: none; white-space: nowrap; }
#drive-hint:empty { display: none; }
#joy {
  position: fixed; z-index: 7; left: 28px; bottom: calc(28px + env(safe-area-inset-bottom)); width: 132px; height: 132px; border-radius: 50%;
  background: rgba(28, 18, 30, 0.45); border: 2px solid rgba(255, 190, 120, 0.45); touch-action: none;
}
#joy-knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: linear-gradient(180deg, #ffc56a, var(--amber-2)); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); }

#hud {
  position: fixed; right: 8px; bottom: 8px; z-index: 9; direction: ltr; font: 12px/1.35 ui-monospace, monospace;
  background: rgba(0, 0, 0, 0.55); color: #cfe; padding: 6px 8px; border-radius: 6px; pointer-events: none; white-space: pre;
}
@media (min-width: 900px) {
  .title { font-size: 21px; }
  #searchbar { top: calc(16px + var(--top)); max-width: 440px; }
  #help-btn { top: calc(60px + var(--top)); }
  #help { top: calc(112px + var(--top)); }
}
@media (prefers-reduced-motion: reduce) {
  #card, #coach, #q.pulse, #help-btn.nudge { animation: none; }
}
