/* Vexelgrid: ceramic-tile palette (ultramarine, saffron, grout grey), Reem Kufi for display, IBM Plex Sans Arabic for UI. */
:root {
  --bg: #e9edf6;
  --tile: #f7f9fd;
  --grout: #d3daeb;
  --paper: #ffffff;
  --ink: #101735;
  --ink-2: #4a5478;
  --line: #d9dfee;
  --blue: #2342c9;
  --blue-ink: #ffffff;
  --gold: #ffb21a;
  --gold-ink: #3a2600;
  --red: #d9363e;
  --claimed: #aab6d9;
  --shadow: 0 1px 2px rgba(16, 23, 53, .08), 0 10px 28px rgba(16, 23, 53, .12);
  --font-ui: "IBM Plex Sans Arabic", system-ui, "Segoe UI", Tahoma, sans-serif;
  --font-display: "Reem Kufi", "IBM Plex Sans Arabic", system-ui, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #070c1c;
  --tile: #111a36;
  --grout: #1e2950;
  --paper: #0f1730;
  --ink: #e9edfb;
  --ink-2: #9aa6cf;
  --line: #242f57;
  --blue: #7c97ff;
  --blue-ink: #0a1230;
  --gold: #ffc23d;
  --red: #ff6b72;
  --claimed: #34417a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.6 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- top bar ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--paper);
  border-block-end: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.mark { width: 30px; height: 30px; flex: none; }
.wordmark { font: 700 23px/1 var(--font-display); }

.search { position: relative; flex: 1 1 280px; max-width: 440px; margin-inline: auto; }
.search input {
  width: 100%;
  height: 40px;
  padding-inline: 14px;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 6px;
}
.search input:focus { border-color: var(--blue); outline: none; background: var(--paper); }
#searchResults {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 6px);
  z-index: 5;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
#searchResults button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: 0;
  border-radius: 5px;
  text-align: start;
}
#searchResults button:hover, #searchResults button[aria-selected="true"] { background: var(--bg); }
#searchResults small { color: var(--ink-2); direction: ltr; }
#searchResults .empty { padding: 8px 10px; color: var(--ink-2); }

.bar-actions { display: flex; align-items: center; gap: 8px; }

.cta {
  height: 40px;
  padding-inline: 18px;
  background: var(--blue);
  color: var(--blue-ink);
  border: 0;
  border-radius: 6px;
  font-weight: 600;
  white-space: nowrap;
}
.cta:hover { filter: brightness(1.08); }
.cta:disabled { opacity: .55; cursor: progress; }
.cta[aria-pressed="true"] { background: var(--gold); color: var(--gold-ink); }
.cta.wide { flex: 1; }

.chip, .ghost {
  height: 40px;
  padding-inline: 14px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.chip:hover, .ghost:hover, .icon-btn:hover { background: var(--bg); }
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 20px;
  line-height: 1;
}

/* ---------- stage ---------- */
.stage { position: relative; overflow: hidden; min-height: 0; background: var(--bg); }
#wall {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  outline-offset: -3px;
}
#wall.dragging { cursor: grabbing; }
.stage.claiming #wall { cursor: crosshair; }
.stage.over-ad #wall { cursor: pointer; }

.tip {
  position: absolute;
  z-index: 3;
  max-width: 260px;
  padding: 6px 10px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 5px;
  font-size: 13px;
  line-height: 1.4;
  pointer-events: none;
}
.tip small { display: block; opacity: .75; direction: ltr; text-align: start; }

.guide {
  position: absolute;
  inset-block-start: 12px;
  inset-inline-start: 12px;
  z-index: 2;
  max-width: min(340px, calc(100% - 24px));
  padding: 10px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.guide p { margin: 0 0 8px; font-size: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--grout); }
.sw-free { background: var(--tile); }
.sw-held {
  background: repeating-linear-gradient(135deg, var(--gold) 0 3px, color-mix(in srgb, var(--gold) 30%, transparent) 3px 6px);
  border-color: var(--gold);
}
.sw-sold { background: var(--claimed); border-color: var(--claimed); }

.nav {
  position: absolute;
  inset-block-end: 12px;
  inset-inline-start: 12px;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.mini {
  width: 144px;
  height: 144px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: none;
}
.zoom { display: flex; flex-direction: column; gap: 6px; }
.zoom .icon-btn { width: 36px; height: 36px; box-shadow: var(--shadow); }

/* ---------- side sheet ---------- */
.sheet {
  position: absolute;
  inset-block-start: 12px;
  inset-inline-end: 12px;
  z-index: 4;
  width: min(380px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 20px;
  overflow: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  animation: sheet-in .22s ease-out;
}
@keyframes sheet-in { from { transform: translateX(calc(var(--dir, 1) * 18px)); opacity: 0; } }
[dir="rtl"] .sheet { --dir: -1; }
.sheet h2 { margin: 0 0 14px; font: 700 24px/1.2 var(--font-display); }
.sheet section > * + * { margin-block-start: 14px; }
.sheet h2 + * { margin-block-start: 0; }

.sheet form { display: flex; flex-direction: column; gap: 14px; }

.facts { margin: 0; padding: 0; }
.facts > div { display: flex; justify-content: space-between; gap: 12px; padding-block: 8px; border-block-end: 1px solid var(--line); }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }
.facts .total dd { font: 700 22px/1.2 var(--font-display); }
.facts .timer { font-variant-numeric: tabular-nums; }

.note { margin: 0; font-size: 13.5px; color: var(--ink-2); }
.note.demo { padding: 10px 12px; background: color-mix(in srgb, var(--gold) 18%, transparent); border-radius: 6px; color: var(--ink); }
.note.ok { color: var(--blue); font-weight: 500; }
.err { margin: 0; min-height: 0; color: var(--red); font-size: 14px; font-weight: 500; }
.err:empty, .note.ok:empty { display: none; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-weight: 500; font-size: 14px; }
.field small { color: var(--ink-2); }
.field input:not([type="file"]) {
  height: 42px;
  padding-inline: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.field input:not([type="file"]):focus { border-color: var(--blue); outline: 2px solid color-mix(in srgb, var(--blue) 30%, transparent); }
.field input[readonly] { background: var(--bg); }

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px;
  border: 1.5px dashed var(--grout);
  border-radius: 6px;
  text-align: center;
  cursor: pointer;
}
.drop:hover, .drop:focus-within { border-color: var(--blue); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop canvas { max-width: 100%; max-height: 180px; border: 1px solid var(--line); image-rendering: auto; background: var(--bg); }
.drop b { color: var(--blue); font-weight: 600; }
.drop small { color: var(--ink-2); }

.row { display: flex; gap: 8px; }


/* ---------- account ---------- */
.acct { position: relative; }
.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  overflow: hidden;
  background: var(--blue);
  color: var(--blue-ink);
  border: 2px solid var(--line);
  border-radius: 50%;
  font-weight: 600;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.menu {
  position: absolute;
  inset-block-start: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 8;
  min-width: 220px;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.menu .who { margin: 0; padding: 8px 10px 10px; border-block-end: 1px solid var(--line); color: var(--ink-2); font-size: 13px; overflow-wrap: anywhere; }
.menu button { display: block; width: 100%; padding: 9px 10px; background: none; border: 0; border-radius: 5px; text-align: start; }
.menu button:hover { background: var(--bg); }

/* ---------- sheet extras ---------- */
.lead { margin: 0; color: var(--ink-2); }
.gsi { display: flex; justify-content: center; min-height: 44px; }
.demo-login { display: flex; flex-direction: column; gap: 12px; }
.linkbtn { display: inline-grid; place-items: center; text-decoration: none; }

.adcard {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 10px;
  background: repeating-conic-gradient(var(--bg) 0 25%, var(--tile) 0 50%) 0 0 / 16px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.adcard img { max-width: 100%; max-height: 260px; image-rendering: auto; }
#a-title { margin: 0; overflow-wrap: anywhere; }

.mine { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.mine li { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 4px 12px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.mine .thumb { grid-row: span 2; width: 56px; height: 56px; object-fit: contain; background: var(--bg); border-radius: 4px; }
.mine .info { min-width: 0; }
.mine .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mine .info small { display: block; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mine .acts { display: flex; gap: 6px; }
.mine .acts button { height: 32px; padding-inline: 12px; background: transparent; border: 1px solid var(--line); border-radius: 6px; font-size: 13.5px; }
.mine .acts button:hover { background: var(--bg); }

.zoomlevel {
  align-self: flex-end;
  margin: 0;
  padding: 2px 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 99px;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  direction: ltr;
}

/* ---------- toast ---------- */
.toast {
  position: absolute;
  inset-block-end: 16px;
  inset-inline: 0;
  z-index: 6;
  width: fit-content;
  max-width: calc(100% - 32px);
  margin-inline: auto;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

/* ---------- footer ---------- */
.foot {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 16px;
  background: var(--paper);
  border-block-start: 1px solid var(--line);
  font-size: 14px;
  flex-wrap: wrap;
}
.foot p { margin: 0; }
.foot .copy {
  flex: 0 0 100%;
  display: flex; justify-content: center; align-items: center; gap: 10px;
  padding-block-start: 8px;
  border-block-start: 1px solid var(--line);
  font-size: 13px; color: var(--ink-2);
}
.legal-nav {
  flex: 0 0 100%;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  padding-block-start: 10px;
  border-block-start: 1px solid var(--line);
}
.legal-nav a {
  display: inline-flex; align-items: center;
  height: 32px; padding-inline: 14px;
  border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink-2); font-size: 13px; font-weight: 500; text-decoration: none;
  transition: color .15s, border-color .15s, background-color .15s;
}
.legal-nav a:hover, .legal-nav a:focus-visible {
  color: var(--blue); border-color: var(--blue);
  background: color-mix(in srgb, var(--blue) 10%, transparent);
}
.legal-nav + .copy { border-block-start: 0; padding-block-start: 0; }
.copy-link { display: inline-flex; align-items: center; gap: 5px; color: var(--ink); font-weight: 600; text-decoration: none; }
.copy-link:hover, .copy-link:focus-visible { color: var(--blue); text-decoration: underline; }
.copy-link svg { color: #e62117; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.progress { display: flex; align-items: center; gap: 14px; flex: 1 1 auto; min-width: 0; }
.meter {
  --seg: 6px;
  --gap: 3px;
  position: relative;
  flex: 0 1 280px;
  min-width: 120px;
  height: 12px;
  overflow: hidden;
  background: repeating-linear-gradient(90deg, var(--grout) 0 var(--seg), transparent var(--seg) calc(var(--seg) + var(--gap)));
  border-radius: 2px;
}
.meter::after {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: calc(var(--p) * 100%);
  background: repeating-linear-gradient(90deg, var(--blue) 0 var(--seg), transparent var(--seg) calc(var(--seg) + var(--gap)));
  transition: width .6s ease;
}
#meterText { font: 700 16px/1.2 var(--font-display); font-variant-numeric: tabular-nums; white-space: nowrap; }
.adv { color: var(--ink-2); white-space: nowrap; }
.recent { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--ink-2); }
.recent ul { display: flex; gap: 6px; margin: 0; padding: 0; list-style: none; overflow: hidden; }
.recent button {
  max-width: 150px;
  padding: 2px 10px;
  overflow: hidden;
  background: var(--bg);
  border: 0;
  border-radius: 99px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.recent button:hover { background: var(--grout); }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .bar { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px; }
  .brand { order: 1; }
  .bar-actions { order: 2; margin-inline-start: auto; gap: 6px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .chip { padding-inline: 10px; }
  .zoomlevel { display: none; }
  .cta { padding-inline: 14px; }

  .sheet {
    inset-block: auto 0;
    inset-inline: 0;
    width: auto;
    max-height: 78%;
    border-radius: 14px 14px 0 0;
    border-inline: 0;
    border-block-end: 0;
    animation-name: sheet-up;
  }
  @keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }
  .nav { inset-block-end: 8px; inset-inline-start: 8px; }
  .mini { width: 96px; height: 96px; }
  .stage.sheet-open .nav { display: none; }
  .guide { padding: 8px 10px; }
  .guide p { font-size: 13px; }
  .foot { gap: 14px; }
  .adv, .recent { display: none; }
  .progress { gap: 10px; }
  .meter { flex: 1 1 60px; min-width: 60px; }
  #meterText { font-size: 14px; white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  .meter::after { transition: none; }
}
