/* Palette lifted from the 1999 original: #666 stage, yellow/orange streets,
   the green gradient off the applet's zoom slider, DNT red. */
:root {
  --stage:   #666666;
  --panel:   #2b2b2b;
  --panel-2: #383838;
  --edge:    #1c1c1c;
  --ink:     #e8e6e0;
  --dim:     #9a958c;
  --yellow:  #ffcc00;
  --orange:  #ff9900;
  /* sampled from the applet's own panel art, code/images/back.jpg */
  --green-1: #8ced7a;   /* zoom bar, top    */
  --green-2: #deda8c;   /* zoom bar, middle */
  --green-3: #986818;   /* zoom bar, bottom */
  --maroon:  #8c1b41;   /* button plate border */
  --red:     #ff0000;
  --panel-w: 250px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  /* dvh follows iOS's shrinking toolbar; the percentage above is the fallback */
  height: 100dvh;
  /* The whole map page is stage grey, so the page behind it is too. Anything
     else shows as a dark sliver wherever a sub-pixel gap opens up -- a
     fractional device pixel ratio, an iOS rubber-band, a rounding error at
     some window height. There is no size at which a dark edge is wanted. */
  background: var(--stage);
  color: var(--ink);
  font: 13px/1.45 "Helvetica Neue", Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}

#app {
  display: flex;
  height: 100dvh;
  /* The 1999 page put the Flash movie in a rowspan=2 left cell and the
     zoom3 applet in the columns to its right. Same here. */
  flex-direction: row-reverse;
  height: 100%;
  min-height: 0;
}

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

/* The 1999 page was bgcolor="#666666" -- the same grey as the Flash stage --
   and the applet's raised bevel (light on the top-left, shadowed on the
   bottom-right) was painted to sit on it. Using that grey here means the
   artwork needs no border of its own: its own edge is the edge. */
#panel {
  width: var(--panel-w);
  flex: 0 0 var(--panel-w);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--stage);
  overflow: hidden;
}

#brand { margin: -4px 0 -2px; }
#brand a { display: block; line-height: 0; }
#brand img {
  width: 100%;
  height: auto;
  /* The GIF carries its own transparency around the slab, so it needs no
     blend mode -- screen just lit the grey slab into a box. */
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .5));
}

/* ---------- the applet's face --------------------------------------------
   code/images/back.jpg is 165 x 380. Every control below is placed as a
   percentage of that image, over the region the applet drew it in, so the
   panel scales without the controls drifting off their painted furniture.
   Percentages come from edge-detecting the image itself, not from guesses.  */

#face {
  position: relative;
  container-type: inline-size;
  width: 100%;
  aspect-ratio: 165 / 380;
  background: url("art/panel.jpg") no-repeat 0 0 / 100% 100%;
  flex: 0 0 auto;
  user-select: none;
}

/* the city thumbnail, live -- replaces the one baked into the picture */
#thumb {
  position: absolute;
  left: 2.121%; top: 1.184%; width: 92.121%; height: 25.921%;
  background: var(--stage);
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}
#thumb-map, #thumb-map svg { width: 100%; height: 100%; display: block; }

/* "Dreptunghiul rosu" / "piros keret" -- the 1999 help calls it red in both
   languages it was written in, so it is red. */
#viewrect {
  position: absolute;
  border: 1px solid #ff2020;
  background: rgba(255, 40, 40, .14);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(255,255,255,.25);
  pointer-events: none;
}

/* Measured off the artwork itself (scanlines through art/panel.jpg), not
   guessed:

     thumbnail    x4..157   y4..104
     ladder bar   x8..30    y120..232   (its green ramp, not the bezel)
     readout box  x50..85   y120..140
     wind rose    centre (109.3, 189.2), r ~37
     buttons      cols x3..85 / x89..160, gap x85.3..89.5
                  rows y245..272 / 275..302 / 305..332

   all in the original 165 x 380 coordinate space.                          */

#zoombar {
  position: absolute;
  left: 3.030%; top: 31.579%; width: 18.182%; height: 30.395%;
}
/* The whole painted ladder is the slider. It used to carry invisible +/-
   zones at its ends, which took the pointer cursor and a click-to-zoom and
   made the top and bottom of the bar undraggable. */
#zoom {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 100%; height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ns-resize;
}
#zoombar { cursor: ns-resize; }

/* the white marker riding the ladder */
#zoomknob {
  position: absolute;
  left: -2px; right: -2px;
  height: 5px;
  background: #fff;
  border: 1px solid #1a1a1a;
  border-radius: 1px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .7);
  pointer-events: none;
}

/* the little green readout box */
#zoomshow {
  position: absolute;
  left: 30.303%; top: 31.579%; width: 21.212%; height: 5.263%;
  display: grid;
  place-items: center;
  color: #0d3a10;
  font: 700 clamp(8px, 5.2cqw, 13px)/1 "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: -.02em;
  pointer-events: none;
}

/* The blue bullet in the middle of the wind rose. Dragging it off centre pans
   the map continuously, at a speed set by how far it is pushed -- the
   applet's plotChanged() -> moveThread -> smallMove() loop, and exactly what
   the 1999 help describes as "a speed proportional to the distance from the
   centre of the disc". */
#joystick {
  position: absolute;
  left: 48.061%; top: 41.895%;
  width: 36.364%; height: 15.789%;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
}
#joystick.dragging { cursor: grabbing; }
#bullet {
  position: absolute;
  left: 50%; top: 50%;
  width: 26%; height: 26%;
  margin: -13% 0 0 -13%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #9fd0ff 0%, #2f7fe0 45%, #12386f 100%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .65), inset 0 0 2px rgba(255, 255, 255, .5);
  pointer-events: none;
}
#joystick.dragging #bullet { box-shadow: 0 0 0 2px rgba(255,255,255,.75), 0 2px 6px rgba(0,0,0,.7); }

/* six buttons over the six painted plates. The picture supplies the label,
   so the text here is transparent -- still there for screen readers. */
#layers button {
  position: absolute;
  border: 0;
  padding: 0;
  background: transparent;
  color: transparent;
  font: inherit;
  cursor: pointer;
  border-radius: 1px;
}
/* Placed by hand in calibrate.html against the artwork. The plates are
   not perfectly uniform -- 1999 hand-placed art -- so each gets its own
   rule rather than being averaged into shared row/column rules. */
#layers button[data-slot="r1c1"] {
  left: 0.000%; top: 64.474%;
  width: 54.545%; height: 7.895%;
}
#layers button[data-slot="r1c2"] {
  left: 54.545%; top: 64.474%;
  width: 42.424%; height: 7.895%;
}
#layers button[data-slot="r2c1"] {
  left: 0.000%; top: 72.368%;
  width: 54.545%; height: 7.895%;
}
#layers button[data-slot="r2c2"] {
  left: 54.545%; top: 72.368%;
  width: 42.424%; height: 7.895%;
}
#layers button[data-slot="r3c1"] {
  left: 0.000%; top: 80.263%;
  width: 54.545%; height: 7.895%;
}
#layers button[data-slot="r3c2"] {
  left: 54.545%; top: 80.263%;
  width: 42.424%; height: 7.895%;
}

#layers button:hover {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85);
}
/* Closing a sheet returns focus to the button that opened it. Keep a visible
   ring for keyboard users, but use the same inset white as hover so it lands
   on the plate rather than boxing it in. */
#layers button:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85);
}
/* a toggle that is off gets the painted plate dimmed */
#layers button[data-layer]:not(.on) { background: rgba(0, 0, 0, .55); }
#layers button[data-layer].on::after {
  content: "";
  position: absolute;
  right: 3px; top: 50%;
  width: 5px; height: 5px;
  margin-top: -2.5px;
  border-radius: 50%;
  background: #7dff5a;
  box-shadow: 0 0 4px #4f0;
}

/* ---------- drawers under the face ---------------------------------------- */

#drawers {
  display: flex; flex-direction: column;
  min-height: 0; flex: 1 1 auto; gap: 8px;
}
/* an id rule setting display would out-specify a plain [hidden], and did */
.drawer[hidden] { display: none !important; }
.drawer {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid rgba(0, 0, 0, .5);
  border-radius: 2px;
  background: rgba(24, 24, 24, .82);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  padding: 7px 8px 8px;
}
#find { flex: 1 1 auto; }
#options { flex: 0 0 auto; padding-bottom: 7px; }
.drawer > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -1px 0 6px;
}
.drawer h2 {
  margin: 0;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--dim);
}
/* the small X that closes a drawer */
.x {
  width: 17px; height: 17px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 2px;
  background: none;
  color: var(--dim);
  font: 15px/1 "Helvetica Neue", Helvetica, Arial, sans-serif;
  cursor: pointer;
  padding: 0 0 1px;
}
.x:hover {
  color: #fff;
  background: var(--maroon);
  border-color: #000;
}
#reset {
  width: 100%;
  margin-top: 7px;
  padding: 6px;
  border: 1px solid var(--edge);
  border-radius: 2px;
  background: linear-gradient(180deg, #4a4340, #332e2c);
  color: var(--dim);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
#reset:hover { color: var(--ink); }

/* search */
#q {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--edge);
  border-radius: 2px;
  background: #1f1f1f;
  color: var(--ink);
  font: inherit;
}
#q:focus { outline: 2px solid var(--yellow); outline-offset: -2px; }

#results {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: thin;
}
#results li {
  padding: 5px 8px;
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#results li {
  display: flex;
  align-items: center;
  gap: 6px;
}
#results li > .name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#results li:hover, #results li[aria-selected="true"] {
  background: var(--yellow);
  color: #1a1a1a;
}
#results li .clear {
  flex: 0 0 auto;
  display: none;
  width: 15px; height: 15px;
  place-items: center;
  border: 0;
  border-radius: 2px;
  background: rgba(0,0,0,.18);
  color: #1a1a1a;
  font: 13px/1 "Helvetica Neue", Helvetica, Arial, sans-serif;
  cursor: pointer;
  padding: 0 0 1px;
}
#results li[aria-selected="true"] .clear { display: grid; }
#results li .clear:hover { background: var(--maroon); color: #fff; }
#results li .was {
  color: var(--dim);
  font-size: 11px;
  font-style: italic;
}
#results li:hover .was, #results li[aria-selected="true"] .was { color: #6b5a00; }
#results .none { color: var(--dim); cursor: default; font-style: italic; }
#results .none:hover { background: none; color: var(--dim); }

#credit { color: #333130; font-size: 10.5px; }
#credit p { margin: 0; }
#credit #status { color: #474443; }

/* ---------- map ----------------------------------------------------------- */

#stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background: var(--stage);
  overflow: hidden;
}
#map, #map svg {
  width: 100%;
  height: 100%;
  display: block;
}
#map svg { touch-action: none; cursor: grab; }
#map svg.dragging { cursor: grabbing; }
#map #stage-bg { display: none; }

#hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  padding: 4px 9px;
  border-radius: 2px;
  background: rgba(0, 0, 0, .45);
  color: #ddd;
  font-size: 11px;
  letter-spacing: .04em;
  pointer-events: none;
  transition: opacity .5s;
}
#hint.gone { opacity: 0; }

/* search result marker: the applet drew a plot cross, the DNT sprite pinged */
#ping circle { fill: none; stroke: var(--red); stroke-width: 1.5; }
#ping .halo { animation: ping 1.6s ease-out infinite; }
#ping .dot  { fill: var(--red); stroke: none; }
#ping .pinlabel {
  fill: #fff;
  stroke: rgba(0, 0, 0, .85);
  stroke-width: 3;
  paint-order: stroke;
  font: 700 7px/1 "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-anchor: middle;
}
@keyframes ping {
  0%   { r: 3;  opacity: 1; }
  100% { r: 26; opacity: 0; }
}

/* ---------- about --------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 10;
}
.modal[hidden] { display: none; }
.sheet {
  position: relative;
  max-width: 620px;
  max-height: 82vh;
  overflow-y: auto;
  padding: 26px 30px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 3px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  line-height: 1.6;
}
.sheet h2 {
  margin: 22px 0 8px;
  font-size: 14px;
  color: var(--yellow);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.sheet h2:first-of-type { margin-top: 0; }
.sheet p, .sheet li { color: #d5d1ca; }
.sheet code {
  background: #1c1c1c;
  padding: 1px 5px;
  border-radius: 2px;
  font-size: 12px;
  color: var(--yellow);
}
.sheet strong { color: #fff; }
.sheet .fine { color: var(--dim); font-size: 11.5px; margin-bottom: 0; }
.sheet .close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: 0;
  background: none;
  color: var(--dim);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.sheet .close:hover { color: #fff; }
.sheet.narrow { max-width: 460px; }

/* links were falling back to the browser's visited purple on a dark sheet */
.sheet a { color: var(--yellow); text-decoration: underline; }
.sheet a:visited { color: var(--yellow); }
.sheet a:hover { color: #fff; }

.sheet h3 {
  margin: 18px 0 4px;
  font-size: 13px;
  color: #fff;
  letter-spacing: .02em;
}
.sheet .note-line {
  margin: 0 0 4px;
  padding: 7px 10px;
  background: rgba(255, 204, 0, .1);
  border-left: 2px solid var(--yellow);
  font-size: 12.5px;
  color: #cfcabf;
}
/* language tabs on the help sheet */
.langs { display: flex; gap: 5px; margin: 0 0 16px; }
.langs button {
  padding: 5px 12px;
  border: 1px solid var(--edge);
  border-radius: 2px;
  background: linear-gradient(180deg, #3a3532, #2c2826);
  color: var(--dim);
  font: inherit; font-size: 12px;
  cursor: pointer;
}
.langs button.on {
  color: #1a1a1a;
  font-weight: 600;
  background: linear-gradient(180deg, var(--green-2), var(--green-3));
  border-color: #000;
}
.lang[hidden] { display: none; }

/* ---------- narrow screens ------------------------------------------------ */

/* ---------- phones and short windows --------------------------------------
   The applet's face is a 165 x 380 portrait panel with a fixed aspect ratio.
   At full phone width that is ~860px tall: it pushes the map off the screen.
   So on a narrow screen the artwork steps aside -- it is on the intro page as
   an exhibit -- and the six buttons become what they always were underneath,
   ordinary buttons with text, docked at the bottom where a thumb can reach.

   #layers lives inside #face, so #face cannot simply be hidden or the buttons
   go with it. Both it and #panel become display:contents, which drops their
   boxes but keeps their children, letting #app order the three things that
   matter directly: logo, map, controls.                                    */

@media (max-width: 720px), (max-height: 460px) {
  #app { flex-direction: column; }
  #panel, #face { display: contents; }
  #thumb, #zoombar, #zoomshow, #joystick, #credit { display: none; }

  #brand {
    order: 1;
    margin: 0;
    padding: 5px 10px;
    background: #262626;
    border-bottom: 1px solid #111;
    text-align: center;
  }
  #brand img {
    width: auto;
    max-height: 34px;
    filter: none;
  }

  #stage { order: 2; flex: 1 1 auto; min-height: 0; }

  #layers {
    order: 3;
    position: static;
    /* six buttons will not fit one phone-width row at a tappable size, so
       3 x 2 -- the original's 2 x 3 grid, turned for a landscape screen */
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    padding: 6px 7px calc(6px + env(safe-area-inset-bottom));
    background: #262626;
    border-top: 1px solid #111;
    z-index: 4;
  }
  /* [data-slot] to match the specificity of the per-plate desktop rules,
     which would otherwise keep imposing their percentage widths here */
  #layers button[data-slot] {
    position: static;
    left: auto; top: auto; width: auto; height: auto;
    padding: 11px 4px;
    color: var(--ink);
    background: linear-gradient(180deg, #4a4340, #332e2c);
    border: 1px solid #151515;
    border-radius: 3px;
    font-size: 12.5px;
    box-shadow: none;
  }
  #layers button::after { display: none; }
  #layers button:hover { box-shadow: none; }
  #layers button[data-layer]:not(.on) {
    background: linear-gradient(180deg, #343030, #262323);
    color: #857f78;
  }
  #layers button[data-layer].on {
    background: linear-gradient(180deg, #a52a4d, #5e1028);
    border-color: var(--maroon);
    color: #fff;
  }
  #layers button[data-panel].on {
    background: linear-gradient(180deg, #55504a, #3a3532);
    color: #fff;
  }

  /* drawers rise from the button bar and float over the map */
  #drawers {
    order: 4;
    position: fixed;
    left: 7px; right: 7px; bottom: 0;
    margin-bottom: calc(var(--barh, 96px) + 6px);
    z-index: 6;
    gap: 6px;
    pointer-events: none;
  }
  #drawers > * { pointer-events: auto; }
  #find { max-height: 50vh; }
  #results { max-height: 38vh; }
  .drawer { box-shadow: 0 10px 28px rgba(0, 0, 0, .6); }

  /* "scroll to zoom" is desktop advice, and it sits under the drawers */
  #hint { display: none; }
  .sheet { padding: 20px 18px; max-height: 84vh; }
  .langs { flex-wrap: wrap; }
}
}

/* ---------- 1999 / Today switch ------------------------------------------- */

#mode { display: flex; flex-wrap: wrap; gap: 5px; }
#mode button {
  flex: 1 1 0;
  padding: 6px 4px;
  border: 1px solid var(--edge);
  border-radius: 2px;
  background: linear-gradient(180deg, #3a3532, #2c2826);
  color: var(--dim);
  font: inherit;
  font-size: 12px;
  letter-spacing: .04em;
  cursor: pointer;
}
#mode button.on {
  color: #1a1a1a;
  background: linear-gradient(180deg, var(--green-2), var(--green-3));
  border-color: #000;
  font-weight: 600;
}
#mode-note {
  flex: 1 0 100%;
  margin: 6px 0 0;
  color: #6f6a63;
  font-size: 10.5px;
  line-height: 1.35;
  font-style: italic;
}

@media (max-width: 720px) {
  #mode-note { display: none; }
}

/* shown only when the data files could not be fetched at all */
#loadfail {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  max-width: 430px;
  padding: 22px 26px;
  background: #fffbe6;
  border: 1px solid #000;
  border-left: 5px solid var(--maroon);
  border-radius: 3px;
  color: #221f1a;
  font-size: 13.5px;
  line-height: 1.55;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
}
#loadfail b { display: block; margin-bottom: 8px; font-size: 15px; }
#loadfail p { margin: 8px 0; }
#loadfail code {
  display: block;
  margin: 6px 0;
  padding: 8px 10px;
  background: #23211e;
  color: #ffd95e;
  border-radius: 2px;
  font-family: Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-x: auto;
}

/* nothing to pan to: don't offer a grab hand that cannot deliver */
#map svg.nopan { cursor: default; }
#thumb.nopan { cursor: default; }
#thumb.nopan #viewrect { opacity: .45; }

