:root {
  --ink: #f4ecd8;
  --ink-dim: #b9b09a;
  --panel: rgba(18, 22, 34, 0.86);
  --panel-edge: #3a4460;
  --accent: #ffcf4a;
  --bg: #14213a;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pixelify Sans", ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 15px;
}

#screen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

.pixel-box {
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
}

#topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 250px; /* leave room for the panel on the right; wraps on narrower windows */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  pointer-events: none;
}

#brand {
  font-family: "Silkscreen", ui-monospace, monospace;
  font-size: 18px;
  color: var(--accent);
  text-shadow: 2px 2px 0 #000;
  letter-spacing: 1px;
}

#search {
  position: relative;
  pointer-events: auto;
}

#search input {
  font: inherit;
  width: 240px;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  padding: 4px 10px;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
  outline: none;
}

#search input:focus { border-color: var(--accent); }
#search input::placeholder { color: var(--ink-dim); }

#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 320px;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
  z-index: 40;
}

#search-results li {
  display: flex;
  flex-direction: column;
  padding: 5px 10px;
  cursor: pointer;
}

#search-results li small { color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#search-results li[aria-selected="true"],
#search-results li:hover { background: #2c3550; }
#search-results li[aria-selected="true"] span { color: var(--accent); }

#crumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  pointer-events: auto;
}

#crumbs:empty { display: none; }

#crumbs button,
#crumbs span {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  padding: 4px 10px;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
}

#crumbs button { cursor: pointer; }
#crumbs button:hover { color: var(--accent); border-color: var(--accent); }
#crumbs span { color: var(--accent); }
#crumbs .sep { background: none; border: none; box-shadow: none; padding: 0 2px; color: var(--ink-dim); }

#hint {
  position: fixed;
  top: 56px;
  left: 12px;
  padding: 2px 8px;
  color: var(--ink);
  background: rgba(18, 22, 34, 0.7);
  pointer-events: none;
}

#hint:empty { display: none; }

#tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  padding: 3px 8px;
  background: var(--panel);
  border: 2px solid var(--accent);
  color: var(--ink);
  white-space: nowrap;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
}

#tooltip small { color: var(--ink-dim); }

#status {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
  z-index: 20;
}

.spinner {
  width: 12px;
  height: 12px;
  background: var(--accent);
  animation: blink 0.8s steps(2, jump-none) infinite;
}

@keyframes blink {
  0% { transform: translate(0, 0); }
  25% { transform: translate(4px, 0); }
  50% { transform: translate(4px, 4px); }
  75% { transform: translate(0, 4px); }
}

#error {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: min(460px, 90vw);
  padding: 16px 18px;
  background: var(--panel);
  border: 2px solid #d9534f;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
  z-index: 30;
}

#error p { margin: 0 0 12px; line-height: 1.4; }
#error .row { display: flex; gap: 8px; }

button.px,
#error button,
#hud button {
  font: inherit;
  color: var(--ink);
  background: #252c40;
  border: 2px solid var(--panel-edge);
  padding: 4px 10px;
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

#error button:hover,
#hud button:hover { border-color: var(--accent); color: var(--accent); }

#hud button[aria-pressed="true"] {
  background: var(--accent);
  color: #1b1b1b;
  border-color: var(--accent);
}

#hud {
  position: fixed;
  right: 12px;
  top: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#hud:empty { display: none; }

#hud .panel {
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

#hud .panel.compact { min-width: 0; }
#hud .panel .row { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
#hud .panel .row.head { justify-content: space-between; flex-wrap: nowrap; gap: 10px; }
#hud .panel.collapsed > :not(.head):not(.keep) { display: none; }
#hud .clock { color: var(--ink); min-width: 64px; }
#hud .label { color: var(--ink-dim); font-size: 13px; }
#hud .big { font-family: "Silkscreen", ui-monospace, monospace; color: var(--accent); font-size: 16px; }

#credits {
  position: fixed;
  right: 8px;
  bottom: 6px;
  font-size: 12px;
  color: var(--ink-dim);
  text-shadow: 1px 1px 0 #000;
}

#credits a { color: var(--ink); }

#screen3d {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
  z-index: 1;
}

#view3d {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(30px + env(safe-area-inset-bottom));
  z-index: 16;
  font: inherit;
  font-family: "Silkscreen", ui-monospace, monospace;
  font-size: 13px;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
}

#view3d:hover { border-color: var(--accent); color: var(--accent); }
#view3d[aria-pressed="true"] { background: var(--accent); color: #1b1b1b; border-color: var(--accent); }

/* --- Walking arrows (touch screens) -------------------------------------------------- */

#pad {
  position: fixed;
  left: calc(10px + env(safe-area-inset-left));
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 4px;
  z-index: 15;
  touch-action: none;
}

#pad button {
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  background: rgba(18, 22, 34, 0.72);
  border: 2px solid var(--panel-edge);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
  cursor: pointer;
  user-select: none;
}

#pad button:active { background: var(--accent); color: #1b1b1b; }
#pad [data-dir="up"] { grid-column: 2; grid-row: 1; }
#pad [data-dir="left"] { grid-column: 1; grid-row: 2; }
#pad [data-dir="down"] { grid-column: 2; grid-row: 2; }
#pad [data-dir="right"] { grid-column: 3; grid-row: 2; }

/* --- Landmark info card ------------------------------------------------------------- */

#card {
  position: fixed;
  left: 12px;
  bottom: 32px;
  width: min(340px, calc(100vw - 24px));
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  background: var(--panel);
  border: 2px solid var(--accent);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5);
  z-index: 25;
}

#card-close {
  position: absolute;
  top: 6px;
  right: 6px;
  font: inherit;
  font-size: 20px;
  line-height: 1;
  width: 32px;
  height: 32px;
  color: var(--ink);
  background: rgba(18, 22, 34, 0.85);
  border: 2px solid var(--panel-edge);
  cursor: pointer;
}

#card-img {
  display: block;
  width: 100%;
  max-height: 190px;
  object-fit: cover;
  image-rendering: auto;
  border-bottom: 2px solid var(--panel-edge);
}

#card .card-body { padding: 10px 12px 12px; }
#card-kind { font-family: "Silkscreen", ui-monospace, monospace; font-size: 11px; color: var(--accent); letter-spacing: 1px; }
#card h2 { margin: 2px 36px 4px 0; font-size: 20px; font-weight: 600; line-height: 1.15; }
#card p { margin: 0 0 8px; line-height: 1.4; }
#card-desc { color: var(--ink-dim); font-size: 13px; }
#card-text { font-size: 14px; }
#card .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#card-link { color: var(--ink); font-size: 13px; }

#card-explore {
  font: inherit;
  color: #1b1b1b;
  background: var(--accent);
  border: 2px solid var(--accent);
  padding: 5px 10px;
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

/* --- Touch screens: bigger buttons, no double-tap page zoom on controls ---------------- */

html { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

@media (pointer: coarse) {
  #hud button,
  #crumbs button,
  #error button {
    min-width: 40px;
    min-height: 40px;
  }
  #search-results li { padding: 9px 12px; }
}

/* --- Phones ---------------------------------------------------------------------------- */

@media (max-width: 700px) {
  #topbar {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    right: calc(8px + env(safe-area-inset-right));
    gap: 6px;
  }
  #brand { display: none; }
  #search { flex: 1 1 100%; }
  /* 16px stops iPhones from zooming the page when the search box is tapped */
  #search input { width: 100%; font-size: 16px; padding: 8px 10px; }
  #search-results { width: 100%; max-height: 60vh; overflow-y: auto; }
  #crumbs { flex-wrap: wrap; font-size: 14px; }

  #hint {
    top: auto;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(150px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 24px);
    text-align: center;
    font-size: 13px;
  }

  #hud {
    top: auto;
    right: calc(8px + env(safe-area-inset-right));
    bottom: calc(40px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 16px);
  }
  #hud .panel { min-width: 0; padding: 6px 8px; }
  #hud [data-utc] { display: none; }

  #status {
    bottom: auto;
    top: calc(104px + env(safe-area-inset-top));
    max-width: calc(100vw - 16px);
    font-size: 13px;
  }

  #card {
    left: 8px;
    right: 8px;
    width: auto;
    bottom: calc(8px + env(safe-area-inset-bottom));
    max-height: 55vh;
    z-index: 30;
  }
  #card-img { max-height: 140px; }

  #credits {
    left: calc(8px + env(safe-area-inset-left));
    right: auto;
    bottom: calc(4px + env(safe-area-inset-bottom));
    font-size: 10px;
  }
}
