/* Own Bahrain — map shell.
   Single visual world (dark), deliberately: the map IS the page, and a light
   theme would fight the tile palette. Everything is painted explicitly. */

:root {
  --bg:      #0B0B0D;
  --stone:   #4E4B40;   /* unclaimed tile */
  --stone-hi:#6B675A;   /* unclaimed, hovered */
  --gold:    #C89B3C;   /* claimed tile + accent */
  --gold-hi: #E6BE63;
  --cream:   #EFEADD;
  --muted:   #8B887E;
  --line:    #26262A;
  --panel:   #111114;
  --red:     #C8102E;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--cream);
  font-family: "Karla", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#map {
  position: fixed; inset: 0; width: 100%; height: 100%;
  display: block; cursor: grab; touch-action: none;
}
#map.dragging { cursor: grabbing; }

/* ---------------------------------------------------------------- brand */

#brand {
  position: fixed; top: 0; left: 0; z-index: 5;
  padding: clamp(1rem, 3vw, 2rem);
  pointer-events: none;
  max-width: 20rem;
}
.wordmark {
  font-family: "Bodoni Moda", Didot, "Times New Roman", serif;
  font-weight: 400; font-size: clamp(1.9rem, 5.5vw, 3rem);
  line-height: .9; letter-spacing: -.01em; margin: 0;
}
.wordmark .dot { color: var(--gold); }
.tag {
  font-style: italic; color: var(--muted);
  font-size: .85rem; margin: .5rem 0 0;
}
.counter { margin-top: 1.4rem; }
.counter p {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .68rem; letter-spacing: .06em; color: var(--muted);
  margin: .5rem 0 0; font-variant-numeric: tabular-nums;
}
.counter p b { color: var(--cream); font-weight: 500; }
#left-n { display: block; margin-top: .15rem; }
.counter-bar {
  width: 11rem; max-width: 45vw; height: 3px;
  background: var(--line); border-radius: 2px; overflow: hidden;
}
.counter-bar span {
  display: block; height: 100%; width: 0%;
  background: var(--gold); transition: width .5s ease;
}

/* ---------------------------------------------------------------- search */

#searchwrap {
  position: fixed; top: clamp(1rem, 3vw, 2rem); right: clamp(1rem, 3vw, 2rem);
  z-index: 6; width: min(20rem, calc(100vw - 2rem));
}
#search {
  width: 100%; padding: .62rem .85rem;
  background: rgba(17,17,20,.92); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 2px;
  color: var(--cream); font-family: inherit; font-size: .88rem;
}
#search::placeholder { color: #6C6960; }
#search:focus { outline: none; border-color: var(--gold); }
#results {
  list-style: none; margin: .35rem 0 0; padding: 0;
  background: rgba(17,17,20,.97); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 2px;
  max-height: 15rem; overflow-y: auto;
}
#results li {
  padding: .5rem .85rem; font-size: .85rem; cursor: pointer;
  display: flex; justify-content: space-between; gap: .8rem;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
#results li:last-child { border-bottom: 0; }
#results li:hover, #results li[aria-selected="true"] { background: rgba(200,155,60,.14); }
#results .n {
  font-family: "JetBrains Mono", monospace; font-size: .7rem;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
#results .ar { color: var(--muted); font-size: .78rem; }

/* ---------------------------------------------------------------- zoom */

#zoomctl {
  position: fixed; right: clamp(1rem, 3vw, 2rem); bottom: clamp(4.2rem, 9vw, 5rem);
  z-index: 5; display: flex; flex-direction: column; gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 2px;
}
#zoomctl button {
  width: 2.1rem; height: 2.1rem; border: 0; cursor: pointer;
  background: rgba(17,17,20,.94); color: var(--cream);
  font-size: 1rem; line-height: 1; font-family: inherit;
}
#zoomctl button:hover { background: rgba(200,155,60,.2); color: var(--gold-hi); }
/* The detail panel is anchored bottom-right and would sit on top of these. */
body.panel-open #zoomctl { right: calc(clamp(1rem, 3vw, 2rem) + 21.6rem); }
#zoomctl button#hawar { font-size: .55rem; letter-spacing: .06em; font-family: "JetBrains Mono", monospace; }

/* ---------------------------------------------------------------- tooltip */

#tip {
  position: fixed; z-index: 7; pointer-events: none;
  background: rgba(11,11,13,.95); border: 1px solid var(--line);
  border-left: 2px solid var(--gold);
  padding: .4rem .6rem; border-radius: 2px;
  font-size: .78rem; line-height: 1.35; white-space: nowrap;
  transform: translate(.7rem, .7rem);
}
#tip .c {
  font-family: "JetBrains Mono", monospace; font-size: .68rem;
  color: var(--gold); display: block;
}
#tip .o { color: var(--muted); }

/* ---------------------------------------------------------------- panel */

#panel {
  position: fixed; z-index: 8;
  right: clamp(1rem, 3vw, 2rem); bottom: clamp(1rem, 3vw, 2rem);
  width: min(21rem, calc(100vw - 2rem));
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 2px; padding: 1.3rem 1.4rem 1.4rem;
}
#close {
  position: absolute; top: .45rem; right: .55rem;
  background: none; border: 0; color: var(--muted);
  font-size: 1.3rem; line-height: 1; cursor: pointer; padding: .2rem .35rem;
}
#close:hover { color: var(--cream); }
#panel .code {
  font-family: "JetBrains Mono", monospace; font-size: .7rem;
  letter-spacing: .12em; color: var(--gold); margin: 0 0 .35rem;
}
#panel h2 {
  font-family: "Bodoni Moda", Didot, serif; font-weight: 400;
  font-size: 1.7rem; line-height: 1.1; margin: 0; text-wrap: balance;
}
#panel .gov { color: var(--muted); font-size: .82rem; margin: .2rem 0 1rem; }
#panel dl {
  margin: 0 0 1.1rem; display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: .1rem 1rem; border-top: 1px solid var(--line); padding-top: .8rem;
}
#panel dt {
  font-family: "JetBrains Mono", monospace; font-size: .58rem;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
#panel dd {
  margin: .15rem 0 0; font-size: .88rem; font-variant-numeric: tabular-nums;
}
.claim {
  display: block; width: 100%; padding: .72rem 1rem;
  background: var(--gold); color: #17130A; border: 0; border-radius: 2px;
  font-family: inherit; font-size: .92rem; font-weight: 600; cursor: pointer;
}
.claim:hover { background: var(--gold-hi); }
.claim[disabled] { background: var(--line); color: var(--muted); cursor: default; }
#panel .note {
  font-size: .68rem; color: var(--muted); line-height: 1.45; margin: .7rem 0 0;
}
.owner-label {
  font-family: "JetBrains Mono", monospace; font-size: .58rem;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0;
}
.owner {
  font-family: "Bodoni Moda", Didot, serif; font-size: 1.25rem; margin: .2rem 0 0;
}
.owner-msg { font-size: .85rem; color: var(--muted); margin: .4rem 0 0; font-style: italic; }

/* ---------------------------------------------------------------- chrome */

#legal {
  position: fixed; left: 0; bottom: 0; z-index: 4;
  padding: clamp(.7rem, 2vw, 1.1rem) clamp(1rem, 3vw, 2rem);
  font-size: .67rem; color: var(--muted); line-height: 1.5;
  display: flex; align-items: center; gap: .55rem; flex-wrap: wrap;
  max-width: min(42rem, calc(100vw - 5rem)); pointer-events: none;
}
.key { display: inline-flex; align-items: center; gap: .35rem; }
.key i { width: 9px; height: 9px; border-radius: 1px; display: inline-block; }
.k-free  { background: var(--stone); }
.k-taken { background: var(--gold); }
.sep { opacity: .5; }

#shapeswitch {
  position: fixed; z-index: 5;
  left: clamp(1rem, 3vw, 2rem); bottom: clamp(3.1rem, 7vw, 3.6rem);
  display: flex; gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 2px; overflow: hidden;
}
#shapeswitch a {
  padding: .34rem .7rem; background: rgba(17,17,20,.94);
  color: var(--muted); text-decoration: none;
  font-family: "JetBrains Mono", monospace; font-size: .62rem;
  letter-spacing: .1em; text-transform: uppercase;
}
#shapeswitch a:hover { color: var(--cream); }
#shapeswitch a.on { background: var(--gold); color: #17130A; }

#density {
  position: fixed; z-index: 5;
  left: clamp(1rem, 3vw, 2rem); bottom: clamp(5.2rem, 11vw, 5.9rem);
  display: flex; gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 2px; overflow: hidden;
  font-family: "JetBrains Mono", monospace; font-size: .62rem; letter-spacing: .08em;
}
#density span, #density a {
  padding: .34rem .55rem; background: rgba(17,17,20,.94);
  color: var(--muted); text-decoration: none;
}
#density span { text-transform: uppercase; opacity: .65; }
#density a:hover { color: var(--cream); }
#density a.on { background: var(--gold); color: #17130A; }

#loading {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: var(--bg); color: var(--muted);
  font-family: "JetBrains Mono", monospace; font-size: .75rem; letter-spacing: .14em;
  transition: opacity .4s ease;
}
#loading.gone { opacity: 0; pointer-events: none; }

#demo-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  background: var(--red); color: #fff; text-align: center;
  padding: .35rem 1rem; font-size: .72rem; letter-spacing: .04em;
}
/* The banner is fixed at y=0, so anything else anchored to the top must move. */
body.has-banner #brand { padding-top: 2.6rem; }
body.has-banner #searchwrap { top: calc(clamp(1rem, 3vw, 2rem) + 1.6rem); }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

@media (max-width: 640px) {
  #panel {
    left: 0; right: 0; bottom: 0; width: 100%;
    border-radius: 6px 6px 0 0; border-left: 0; border-right: 0; border-bottom: 0;
    padding-bottom: max(1.4rem, env(safe-area-inset-bottom));
  }
  #legal { max-width: calc(100vw - 4rem); font-size: .62rem; }
  /* Keep clear of the wordmark, which owns the top-left on small screens. */
  #searchwrap { width: 48vw; }
  #search { font-size: .8rem; padding: .5rem .65rem; }
  #zoomctl { bottom: 5.5rem; }
  #shapeswitch { bottom: 3.6rem; }
  /* On mobile the panel is a full-width sheet, so step out of the way entirely
     rather than trying to dodge it; pinch zoom still works. */
  body.panel-open #zoomctl { display: none; }
  body.panel-open #shapeswitch { display: none; }
  body.panel-open #density { display: none; }
  body.panel-open #legal { display: none; }
  .counter-bar { width: 8rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
