/*
 * The stop editor.
 *
 * Designed against one sentence: "done when a stop can be created standing in a park with one hand."
 * Everything here follows from that and from the sunlight/touch requirements:
 *
 *   - Primary actions sit at the BOTTOM, inside the thumb's arc. A save button at the top of a phone
 *     screen requires a second hand or a grip change, and the organizer has a child in the other one.
 *   - 48px minimum on anything tappable, above the stated 44px floor, because the target user is
 *     walking.
 *   - Ink on paper contrast, no thin grey type. Read in direct sun.
 *   - The two secret fields are marked in the layout itself, not only in words. Publishing a hiding
 *     note to families is the failure that ends the hunt.
 */

/*
 * `[hidden]` must actually hide.
 *
 * The attribute is honoured by a user-agent rule of the very lowest specificity, so ANY class rule
 * that sets `display` beats it. Three things here are laid out with flex and start hidden — the
 * sheet, the passcode strip and the map-style chips — and without this the "hidden" sheet sat over
 * the whole screen at full size, invisible to a reader of the markup and fatal in practice: every
 * tap on the page beneath it was swallowed, so the editor could not be used at all.
 *
 * Found by driving the real page in a real browser. No unit test and no amount of reading the HTML
 * would have caught it, because in both of those the attribute is simply "set".
 */
[hidden] { display: none !important; }

.editor {
  padding-bottom: calc(5.5rem + env(safe-area-inset-bottom));
}

/* The terrain backdrop from the landing page would fight with a map. */
.editor .terrain { display: none; }

/* ─────────────────────────── Header ─────────────────────────── */

.ed-head {
  padding: 1rem var(--gutter) 0.75rem;
  border-bottom: 1px solid var(--rule);
}

.ed-back {
  display: inline-block;
  font: 500 0.85rem/1 var(--body);
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 0.7rem 0.4rem 0.7rem 0;
  min-height: 44px;
}
.ed-back:hover { color: var(--trail-deep); }

.ed-head h1 {
  font: 400 clamp(1.5rem, 6vw, 2rem)/1.1 var(--display);
  margin: 0.1rem 0 0.15rem;
  color: var(--ink);
}

.ed-sub {
  margin: 0;
  font: 400 0.85rem/1.4 var(--body);
  color: var(--ink-soft);
}

/* ──────────────────── The passcode strip ────────────────────
 *
 * Sticky under the header on purpose. The link between a medallion code and the passcode families
 * type is invisible — you change a code in one place and a number changes somewhere the organizer
 * is not looking. Keeping it on screen is the cheapest possible guard against that.
 */

.passcode-strip {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  gap: 1.5rem;
  align-items: baseline;
  padding: 0.6rem var(--gutter);
  background: var(--paper-warm);
  border-bottom: 1px solid var(--rule);
}

.passcode-strip .label {
  display: block;
  font: 500 0.62rem/1 var(--body);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.22rem;
}

.passcode {
  font: 600 1.15rem/1 var(--mono);
  letter-spacing: 0.08em;
  color: var(--trail-deep);
}
.passcode.small { font-size: 1rem; }
.passcode.unset { color: var(--ink-faint); letter-spacing: 0; font-weight: 400; }

/* ─────────────────────────── Problems ─────────────────────────── */

.problems {
  list-style: none;
  margin: 0;
  padding: 0.75rem var(--gutter);
  background: color-mix(in srgb, var(--trail) 12%, var(--paper));
  border-bottom: 1px solid var(--rule);
}
.problems li {
  font: 400 0.88rem/1.45 var(--body);
  color: var(--ink);
  padding-left: 1.4rem;
  position: relative;
}
.problems li + li { margin-top: 0.4rem; }
.problems li::before {
  content: '!';
  position: absolute;
  left: 0;
  top: 0.05rem;
  width: 1rem; height: 1rem;
  border-radius: 50%;
  background: var(--trail);
  color: #fff;
  font: 600 0.7rem/1rem var(--body);
  text-align: center;
}

/* ──────────────────────── The stop list ────────────────────────
 *
 * The dashed spine from the landing page, reused: the list IS the trail, in order, and a gap in the
 * numbering is visible as a gap rather than hidden by renumbering.
 */

main { padding: 0 var(--gutter); }

.stops {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0 0 0 var(--spine);
  position: relative;
}

.stops::before {
  content: '';
  position: absolute;
  left: calc(var(--spine) / 2 - 1px);
  top: 0.75rem;
  bottom: 0.75rem;
  border-left: 2px dashed var(--contour);
}

.stop-card {
  position: relative;
  background: var(--paper-warm);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.85rem 0.9rem;
  margin-bottom: 0.85rem;
  cursor: pointer;
  min-height: 48px;
}
.stop-card:hover { border-color: var(--trail); }

.stop-card.placeholder,
.stop-card.placeholder:hover {
  cursor: default;
  border-style: dashed;
  border-color: var(--rule);
  color: var(--ink-faint);
  font: 400 0.9rem/1.4 var(--body);
}

/* The numbered pin, sitting on the spine. */
.stop-n {
  position: absolute;
  left: calc(-1 * var(--spine) + 0.1rem);
  top: 0.8rem;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  background: var(--trail);
  color: #fff;
  font: 600 0.9rem/2rem var(--mono);
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.stop-card.unpinned .stop-n { background: var(--ink-faint); }

.stop-title {
  font: 500 1rem/1.3 var(--body);
  color: var(--ink);
  margin: 0 0 0.2rem;
}
.stop-title .untitled { color: var(--ink-faint); font-style: italic; }

.stop-riddle {
  font: 400 0.87rem/1.45 var(--body);
  color: var(--ink-soft);
  margin: 0 0 0.45rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.stop-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  font: 400 0.75rem/1.3 var(--body);
  color: var(--ink-faint);
}
.stop-meta .code {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--trail-deep);
  letter-spacing: 0.06em;
}
.stop-meta .warn { color: var(--trail-deep); font-weight: 500; }

.empty {
  font: 400 0.95rem/1.5 var(--body);
  color: var(--ink-soft);
  padding: 1.5rem 0;
  max-width: var(--measure);
}

.notice {
  font: 400 0.9rem/1.5 var(--body);
  color: var(--ink);
  background: var(--paper-warm);
  border: 1px solid var(--rule);
  padding: 0.9rem;
  border-radius: 3px;
}

/* ──────────────────── Bottom action bar ────────────────────
 * Fixed in the thumb zone. This is the one-handed requirement made literal.
 */

.action-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  padding: 0.7rem var(--gutter) calc(0.7rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--rule);
}

.btn.big {
  display: block;
  width: 100%;
  min-height: 52px;
  font-size: 1rem;
}

.btn.primary {
  background: var(--trail);
  border-color: var(--trail-deep);
  color: #fff;
}
.btn.primary:hover { background: var(--trail-deep); }
.btn.danger { color: var(--trail-deep); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ─────────────────────────── The sheet ─────────────────────────── */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(10, 18, 28, 0.45);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

@media (min-width: 720px) {
  .sheet {
    inset: 3vh 50% auto auto;
    right: auto; left: 50%;
    transform: translateX(-50%);
    width: min(38rem, 94vw);
    max-height: 94vh;
    border: 1px solid var(--rule);
    border-radius: 4px;
    box-shadow: 0 18px 60px rgba(0,0,0,0.3);
  }
}

.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-warm);
}
.sheet-head h2 {
  margin: 0;
  text-align: center;
  font: 400 1.15rem/1 var(--display);
  color: var(--ink);
}
.sheet-head .btn { min-height: 48px; border: none; background: none; }
.sheet-head .btn:last-child { justify-self: end; }
.sheet-head .btn:first-child { justify-self: start; }

.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem var(--gutter) 1.5rem;
}

.sheet-foot {
  padding: 0.7rem var(--gutter) calc(0.7rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
  background: var(--paper-warm);
}

.save-state {
  margin: 0 0 0.5rem;
  min-height: 1.1rem;
  font: 400 0.8rem/1.1 var(--body);
  color: var(--ink-soft);
}
.save-state.bad { color: var(--trail-deep); font-weight: 500; }

/* ─────────────────────────── Fields ─────────────────────────── */

.field {
  display: block;
  margin-bottom: 1.4rem;
  border: 0;
  padding: 0;
}

.field-label {
  display: block;
  font: 500 0.8rem/1.2 var(--body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 0.4rem;
}
.field-label em { font-style: italic; text-transform: none; letter-spacing: 0; color: var(--ink-soft); }

.field input[type=text],
.field textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 48px;
  padding: 0.7rem 0.75rem;
  font: 400 1rem/1.4 var(--body);
  color: var(--ink);
  background: var(--paper-warm);
  border: 1px solid var(--rule);
  border-radius: 3px;
  /* 1rem, never smaller: iOS Safari zooms the whole page on focus below 16px, which on a phone in a
     park throws away the layout mid-edit. */
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus {
  outline: 2px solid var(--trail);
  outline-offset: 1px;
  border-color: var(--trail);
}

.code-input { text-transform: uppercase; letter-spacing: 0.14em; font-weight: 600; }

.hint {
  display: block;
  margin-top: 0.35rem;
  font: 400 0.78rem/1.4 var(--body);
  color: var(--ink-soft);
}
.hint.warn { color: var(--trail-deep); font-weight: 500; }

/* The two fields that must never reach a family, marked in the layout and not only in words. */
.field.secret {
  border-left: 3px solid var(--water);
  padding-left: 0.75rem;
  background: color-mix(in srgb, var(--water) 6%, transparent);
  padding-top: 0.75rem;
  padding-bottom: 0.1rem;
  border-radius: 0 3px 3px 0;
}
.who {
  font: 600 0.62rem/1 var(--body);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fff;
  background: var(--water);
  padding: 0.22rem 0.4rem;
  border-radius: 2px;
  margin-left: 0.4rem;
  vertical-align: 0.05rem;
}

/* ─────────────────────────── The pin ─────────────────────────── */

.field.pin { margin-bottom: 1.6rem; }

.pin-status {
  font: 400 0.85rem/1.4 var(--body);
  color: var(--ink-soft);
  background: var(--paper-warm);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.7rem;
}
.pin-status.set { color: var(--ink); }
.pin-status .coords { font-family: var(--mono); font-size: 0.85em; letter-spacing: 0.02em; }
.pin-status .accuracy { color: var(--ink-soft); }
.pin-status .warn { display: block; margin-top: 0.3rem; color: var(--trail-deep); font-weight: 500; }

.btn.locate { position: relative; padding-top: 0.6rem; padding-bottom: 0.6rem; }
.btn.locate small {
  display: block;
  font: 400 0.72rem/1.2 var(--body);
  opacity: 0.85;
  margin-top: 0.15rem;
  text-transform: none;
  letter-spacing: 0;
}

.map-wrap { position: relative; margin-top: 0.8rem; }

.map {
  height: 260px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--paper-deep);
}

.map-fallback {
  padding: 1rem;
  border: 1px dashed var(--rule);
  border-radius: 3px;
  background: var(--paper-warm);
}
.map-fallback p {
  margin: 0 0 0.4rem;
  font: 400 0.85rem/1.45 var(--body);
  color: var(--ink-soft);
}
.map-fallback p:last-child { margin-bottom: 0; color: var(--ink); }

.map-styles { display: flex; gap: 0.4rem; margin-top: 0.5rem; flex-wrap: wrap; }

.chip {
  min-height: 44px;
  padding: 0.4rem 0.8rem;
  font: 500 0.8rem/1 var(--body);
  color: var(--ink-soft);
  background: var(--paper-warm);
  border: 1px solid var(--rule);
  border-radius: 999px;
  cursor: pointer;
}
.chip.is-on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.paste { margin-top: 1rem; }
.paste-row { display: flex; gap: 0.5rem; }
.paste-row input { flex: 1; }
.paste-row .btn { min-height: 48px; padding-inline: 1.1rem; }

/* Leaflet's own attribution, folded into the page's type rather than left as browser default. */
.leaflet-container { font-family: var(--body); }
.leaflet-control-attribution {
  font-size: 0.65rem;
  background: color-mix(in srgb, var(--paper) 88%, transparent) !important;
  color: var(--ink-soft);
}
.leaflet-control-attribution a { color: var(--ink-soft); }

/* The draggable marker, in the trail colour rather than Leaflet's blue. */
.pin-marker {
  width: 26px; height: 26px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--trail);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ─────────────────────── Bringing a hunt aboard ─────────────────────── */

.import {
  margin: 1.5rem 0 3rem;
  padding: 1.1rem;
  border: 1px dashed var(--rule);
  border-radius: 3px;
  background: var(--paper-warm);
}
.import h2 {
  margin: 0 0 0.3rem;
  font: 400 1.15rem/1.2 var(--display);
  color: var(--ink);
}
.import .hint { margin-bottom: 0.9rem; }
.import code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--paper-deep);
  padding: 0.1rem 0.3rem;
  border-radius: 2px;
}
.import .problems { margin-top: 0.8rem; border: 0; background: none; padding: 0; }

/* The sign-in form, which is one field and one button and should look like it. */
.signin { max-width: 26rem; margin: 1.5rem 0 3rem; }
