/* Drop Point Simulator — dark chrome over a desert map, mobile first. */

:root {
  --bg: #171310;
  --panel: #241c17;
  --panel-2: #2f2620;
  --line: #453931;
  --ink: #f0e6da;
  --ink-dim: #b3a293;
  --accent: #d9822b;
  --danger: #c0392b;
  --ok: #57d97e;
  --bar: 52px;
  --pal: 74px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;          /* we handle pan/zoom ourselves */
  cursor: crosshair;
}

/* ---- top bar ---------------------------------------------------------- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--bar) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(180deg, rgba(23,19,16,0.96), rgba(23,19,16,0.72));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.14em;
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
}

.spacer { flex: 1; }

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 13px;
  padding: 7px 11px;
  cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: #1a1208; font-weight: 700; }

.icon-btn {
  appearance: none;
  width: 36px; height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn:active { background: var(--panel-2); }

/* ---- building palette -------------------------------------------------- */

.palette {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom)) 8px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  background: linear-gradient(0deg, rgba(23,19,16,0.97), rgba(23,19,16,0.75));
  border-top: 1px solid var(--line);
  z-index: 10;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.chip {
  flex: 0 0 auto;
  min-width: 78px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--chip, var(--accent));
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
  padding: 6px 10px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  line-height: 1.25;
}
.chip[aria-pressed="true"] {
  background: var(--panel-2);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.chip .glyph { font-size: 16px; }
.chip .nm { display: block; font-weight: 600; font-size: 13px; }
.chip .tiles { display: block; font-size: 11px; color: var(--ink-dim); }

/* ---- panels ------------------------------------------------------------ */

.panel {
  position: fixed;
  top: calc(var(--bar) + env(safe-area-inset-top) + 6px);
  right: 6px;
  width: min(330px, calc(100vw - 12px));
  max-height: calc(100vh - var(--bar) - var(--pal) - env(safe-area-inset-top) - 24px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  z-index: 20;
}
/* Panels animate in and out, so they can't use display:none. visibility is
   transitioned with a delay so it flips only once the fade has finished, which
   keeps them out of the tab order while closed. */
.panel {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px) scale(0.985);
  transform-origin: top right;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0s linear 0.16s;
}
.panel.open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0s;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 14px; flex: 1; letter-spacing: 0.02em; }

.panel-body {
  padding: 12px 14px 16px;
  overflow-y: auto;
}
.panel-body h3 {
  margin: 16px 0 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.panel-body h3:first-child { margin-top: 0; }

label {
  display: block;
  margin: 8px 0;
  font-size: 12px;
  color: var(--ink-dim);
}
label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
}
label .val { color: var(--ink); float: right; }

input[type="text"], input[type="number"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #1c1611;
  color: var(--ink);
  font: inherit;
  font-size: 14px;    /* >=16px avoids iOS zoom-on-focus; 14 + user-scalable=no is fine */
}
input[type="range"] { width: 100%; margin-top: 6px; accent-color: var(--accent); }
input[type="file"] { width: 100%; font-size: 12px; color: var(--ink-dim); }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }

.btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:active { background: #3a2f27; }
.btn.danger { border-color: #6d3128; color: #ff9d90; }
.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #201509;
  font-weight: 650;
}
.btn.primary:active { background: #b96b1f; }

.disclaimer { margin-top: 18px; font-size: 11px; color: #8d7f73; }

.panel-body a { color: var(--accent); text-decoration-color: rgba(217,130,43,0.5); }
.panel-body a:active { color: #f0a055; }

/* ---- first-run welcome ------------------------------------------------- */

.welcome-wrap {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10,8,6,0.72);
  animation: fade-in 0.2s ease;
}
.welcome-wrap[hidden] { display: none; }

.welcome {
  width: min(420px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px 22px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(0,0,0,0.6);
}
.welcome h2 {
  margin: 0 0 10px;
  font-size: 18px;
  letter-spacing: 0.02em;
  color: var(--accent);
}
.welcome p { margin: 0 0 12px; color: var(--ink-dim); }
.welcome ul { margin: 0 0 14px; padding-left: 20px; color: var(--ink-dim); }
.welcome li { margin-bottom: 7px; }
.welcome b { color: var(--ink); }
.welcome .fine { font-size: 12px; }
.welcome .btn { margin-top: 4px; padding: 11px 10px; font-size: 14px; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.meta { margin: 10px 0 0; font-size: 12px; color: var(--ink-dim); }

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

.map-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1c1611;
}
.map-row.active { border-color: var(--accent); background: var(--panel-2); }

.map-row .pick {
  flex: 1;
  min-width: 0;
  display: block;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0;
}
.map-row .pick .nm {
  display: block;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-row .pick .sub { display: block; font-size: 11px; color: var(--ink-dim); }
.map-row.active .pick .nm { font-weight: 600; color: var(--accent); }

.map-row .act {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink-dim);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.map-row .act:hover { color: var(--ink); }
.map-row .act:disabled { opacity: 0.3; cursor: default; }

/* ---- colour picker ------------------------------------------------------ */

.swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 6px 0 8px;
}

.swatch {
  appearance: none;
  aspect-ratio: 1;
  min-height: 30px;             /* stays a comfortable tap target on a phone */
  border: 2px solid transparent;
  border-radius: 7px;
  background: var(--sw, #888);
  cursor: pointer;
  padding: 0;
}
.swatch[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ink);
}

.swatch-foot { display: flex; gap: 8px; align-items: center; }
.swatch-foot input[type="text"] {
  margin-top: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: lowercase;
}
.swatch-foot .btn { margin-top: 0; width: auto; flex: 0 0 auto; white-space: nowrap; }

/* One type's row in the settings colour list. */
.type-row { margin: 0 0 14px; }
.type-row > .name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--ink);
  margin-bottom: 2px;
}
.type-row .dot {
  width: 12px; height: 12px;
  border-radius: 3px;
  background: var(--sw, #888);
  flex: 0 0 auto;
}
.type-row .tiles { color: var(--ink-dim); font-size: 11px; margin-left: auto; }

/* Calibration state line. The colour is the message: amber while the grid is
   still being guessed at, green once it is solved. */
.calib {
  margin: 8px 0 0;
  padding: 7px 9px;
  border-radius: 7px;
  border-left: 3px solid var(--ink-dim);
  background: #1c1611;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-dim);
}
.calib.provisional { border-left-color: #d9a02b; color: #e8c98a; }
.calib.exact { border-left-color: var(--ok); color: #9fe0b4; }
.hint { margin: 4px 0 8px; font-size: 12px; color: var(--ink-dim); }
.hint b { color: var(--ink); font-weight: 600; }

/* ---- toast ------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--pal) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 8px);
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(20,15,12,0.94);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 30;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* On a phone the wordmark is the first thing to go — the three tools and the
   four icon buttons all have to fit on one row. */
@media (max-width: 560px) {
  .brand { display: none; }
  .seg-btn { padding: 7px 9px; font-size: 12px; }
  .icon-btn { width: 34px; height: 34px; flex-basis: 34px; font-size: 16px; }
  .topbar { gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .panel.open, .toast { transition: none; }
  .welcome-wrap { animation: none; }
}

@media (min-width: 720px) {
  .brand { font-size: 13px; padding-right: 6px; }
  /* Centring an overflowing flex row would clip the first chip out of scroll
     range, so pad the track instead and let it stay left-aligned. */
  .palette::before,
  .palette::after { content: ""; flex: 1 0 0; min-width: 0; }
}
