/* ==========================================================================
   Land Pooling 3D - interface styling
   --------------------------------------------------------------------------
   Written entirely against the main project's --pc-* design tokens
   (see css/tokens.css). No colour, size, spacing or timing literal appears
   below except where a token deliberately does not exist for it, and those
   cases are commented.

   Class names are widget-scoped (.app, .tool, .info, .help) so the stylesheet
   can be dropped into the site without colliding with the theme.
   ========================================================================== */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  background: var(--pc-n-50);
  color: var(--pc-body);
  font-family: var(--pc-font-sans);
  font-size: var(--pc-text-base);
  font-weight: var(--pc-weight-regular);
  line-height: var(--pc-leading-body);
  -webkit-text-size-adjust: 100%;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
}

/* ------------------------------- header -------------------------------- */

.app__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--pc-space-1) var(--pc-space-3);
  padding: var(--pc-space-2) var(--pc-gutter) 14px;
  background: var(--pc-on-ink);
  border-bottom: var(--pc-border-hair) solid var(--pc-line);
  /* The discipline rule: this is the planning tool. */
  border-top: 3px solid var(--pc-d-planning);
}

.app__title {
  margin: 0;
  color: var(--pc-ink);
  font-size: var(--pc-h3);
  font-weight: var(--pc-weight-semibold);
  letter-spacing: var(--pc-tracking-tight);
  line-height: var(--pc-leading-tight);
}

.app__subtitle {
  margin: 4px 0 0;
  color: var(--pc-muted);
  font-size: var(--pc-text-sm);
  line-height: var(--pc-leading-snug);
}

.app__status {
  margin: 0;
  color: var(--pc-muted);
  font-family: var(--pc-font-mono);
  font-size: var(--pc-text-xs);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------- toolbar ------------------------------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pc-space-1);
  padding: 12px var(--pc-gutter);
  background: var(--pc-on-ink);
  border-bottom: var(--pc-border-hair) solid var(--pc-line);
}

.tool {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;              /* compact; 24px is the WCAG 2.5.8 AA floor */
  padding: 5px 10px;
  font-family: inherit;
  font-size: var(--pc-text-xs);
  font-weight: var(--pc-weight-medium);
  line-height: 1;
  white-space: nowrap;
  color: var(--pc-n-800);
  background: var(--pc-on-ink);
  border: var(--pc-border-hair) solid var(--pc-n-300);
  border-radius: var(--pc-radius);
  cursor: pointer;
  transition:
    background var(--pc-duration-fast) var(--pc-ease),
    border-color var(--pc-duration-fast) var(--pc-ease),
    color var(--pc-duration-fast) var(--pc-ease);
}

/* Inline SVG, coloured by the button through currentColor. */
.tool__icon {
  flex: none;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Touch input needs a comfortable target even though the buttons are small. */
@media (pointer: coarse) {
  .tool {
    min-height: var(--pc-tap-min);
    padding: var(--pc-space-1) 12px;
  }
}

.tool:hover {
  background: var(--pc-n-100);
  border-color: var(--pc-n-500);
}

/* Amber alone is 1.77:1 on white, so the ring is doubled with an ink hairline
   to guarantee the 3:1 that WCAG 2.4.11 asks of a focus indicator. */
.tool:focus-visible,
.info__btn:focus-visible,
.viewport canvas:focus-visible {
  outline: var(--pc-focus-width) solid var(--pc-focus-color);
  outline-offset: var(--pc-focus-offset);
  box-shadow: 0 0 0 var(--pc-border-hair) var(--pc-ink);
}

.tool.is-active,
.tool[aria-pressed="true"] {
  background: var(--pc-ink);
  border-color: var(--pc-ink);
  color: var(--pc-on-ink);
}

.tool--import { margin-left: auto; }

.tool--reset { color: var(--pc-n-600); }

/* Accessible, visually hidden file input. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* -------------------------------- stage -------------------------------- */

.stage {
  position: relative;
  z-index: var(--pc-z-base);
  flex: 1 1 auto;
  min-height: 420px;
}

.viewport {
  position: absolute;
  inset: 0;
  background: var(--pc-n-100);
  touch-action: none;       /* camera + drag gestures handled in JS */
  cursor: grab;
}

.viewport.is-dragging { cursor: grabbing; }
.viewport.is-placing  { cursor: crosshair; }

/* A GeoJSON file is being dragged over the model. */
.viewport.is-dropzone {
  outline: var(--pc-border-thick) dashed var(--pc-d-planning);
  outline-offset: -6px;
}

.viewport canvas { display: block; }

.viewport canvas:focus-visible { outline-offset: calc(var(--pc-focus-offset) * -1); }

/* --------------------------- information panel ------------------------- */

.info {
  position: absolute;
  z-index: var(--pc-z-raised);
  top: var(--pc-space-2);
  left: var(--pc-space-2);
  width: 240px;
  max-width: calc(100% - var(--pc-space-4));
  padding: 14px var(--pc-space-2);
  background: rgba(255, 255, 255, 0.95);   /* translucent over the model */
  border: var(--pc-border-hair) solid var(--pc-n-200);
  border-left: 3px solid var(--pc-n-300);
  border-radius: var(--pc-radius);
  box-shadow: var(--pc-shadow-sm);
  backdrop-filter: blur(2px);
}

/* Selection is signalled three ways: this rule, the panel copy, and the
   outline drawn around the object in the 3D scene. */
.info.is-selected { border-left-color: var(--pc-d-planning); }

.info__name {
  margin: 0 0 var(--pc-space-1);
  color: var(--pc-ink);
  font-size: var(--pc-text-lg);
  font-weight: var(--pc-weight-semibold);
  letter-spacing: var(--pc-tracking-tight);
  line-height: var(--pc-leading-snug);
}

.info__rows { margin: 0; }

.info__row {
  display: flex;
  justify-content: space-between;
  gap: var(--pc-space-1);
  padding: 4px 0;
  border-top: var(--pc-border-hair) solid var(--pc-line);
  font-size: var(--pc-text-sm);
  line-height: var(--pc-leading-snug);
}

.info__row dt {
  color: var(--pc-muted);
  font-size: var(--pc-text-label);
  letter-spacing: var(--pc-tracking-label);
  text-transform: uppercase;
}

.info__row dd {
  margin: 0;
  color: var(--pc-n-800);
  font-family: var(--pc-font-mono);
  font-size: var(--pc-text-xs);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.info__controls:not(:empty) {
  margin-top: 12px;
  padding-top: 10px;
  border-top: var(--pc-border-hair) solid var(--pc-line);
}

.info__slider {
  display: flex;
  align-items: center;
  gap: var(--pc-space-1);
  padding: 2px 0;
}

.info__slider-label {
  flex: none;
  width: 44px;
  color: var(--pc-muted);
  font-size: var(--pc-text-label);
  letter-spacing: var(--pc-tracking-label);
  text-transform: uppercase;
}

.info__slider input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  height: 18px;
  accent-color: var(--pc-d-planning);
  cursor: pointer;
}

.info__slider input[type="range"]:focus-visible {
  outline: var(--pc-focus-width) solid var(--pc-focus-color);
  outline-offset: 2px;
  box-shadow: 0 0 0 var(--pc-border-hair) var(--pc-ink);
}

.info__slider-value {
  flex: none;
  width: 26px;
  color: var(--pc-n-800);
  font-family: var(--pc-font-mono);
  font-size: var(--pc-text-xs);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.info__choices {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: var(--pc-space-1);
}

.info__choice {
  flex: 1 1 auto;
  min-height: 28px;
  padding: 4px 6px;
  font-family: inherit;
  font-size: var(--pc-text-xs);
  font-weight: var(--pc-weight-medium);
  color: var(--pc-n-800);
  background: var(--pc-on-ink);
  border: var(--pc-border-hair) solid var(--pc-n-300);
  border-radius: var(--pc-radius);
  cursor: pointer;
}

.info__choice:hover { background: var(--pc-n-100); }

.info__choice[aria-pressed="true"] {
  background: var(--pc-ink);
  border-color: var(--pc-ink);
  color: var(--pc-on-ink);
}

.info__choice:focus-visible {
  outline: var(--pc-focus-width) solid var(--pc-focus-color);
  outline-offset: 2px;
  box-shadow: 0 0 0 var(--pc-border-hair) var(--pc-ink);
}

.info__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.info__actions:empty { display: none; }

.info__btn {
  flex: 1 1 0;
  min-height: 36px;              /* inside a panel; --pc-tap-min applies to
                                    the primary toolbar controls */
  padding: 6px var(--pc-space-1);
  font-family: inherit;
  font-size: var(--pc-text-xs);
  font-weight: var(--pc-weight-medium);
  color: var(--pc-n-800);
  background: var(--pc-on-ink);
  border: var(--pc-border-hair) solid var(--pc-n-300);
  border-radius: var(--pc-radius);
  cursor: pointer;
  transition: background var(--pc-duration-fast) var(--pc-ease);
}

.info__btn:hover { background: var(--pc-n-100); border-color: var(--pc-n-500); }

/* Destructive, so it is marked with the amber accent rather than a new hue. */
.info__btn--danger {
  border-left: 3px solid var(--pc-amber);
  color: var(--pc-accent-text);
}

.info__hint {
  margin: 12px 0 0;
  color: var(--pc-muted);
  font-size: var(--pc-text-xs);
  line-height: var(--pc-leading-snug);
}

/* ------------------------------- layers -------------------------------- */

.layers {
  position: absolute;
  z-index: var(--pc-z-raised);
  top: var(--pc-space-2);
  right: var(--pc-space-2);
  width: 208px;
  max-width: calc(100% - var(--pc-space-4));
  padding: 12px var(--pc-space-2) 14px;
  background: rgba(255, 255, 255, 0.95);
  border: var(--pc-border-hair) solid var(--pc-n-200);
  border-radius: var(--pc-radius);
  box-shadow: var(--pc-shadow-sm);
  backdrop-filter: blur(2px);
}

.layers__summary {
  color: var(--pc-ink);
  font-size: var(--pc-text-label);
  font-weight: var(--pc-weight-semibold);
  letter-spacing: var(--pc-tracking-label);
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
}

.layers__summary::-webkit-details-marker { display: none; }

.layers__summary::after {
  content: " ▾";           /* closed */
  color: var(--pc-n-500);
}

.layers[open] .layers__summary::after { content: " ▴"; }

.layers__summary:focus-visible {
  outline: var(--pc-focus-width) solid var(--pc-focus-color);
  outline-offset: var(--pc-focus-offset);
  box-shadow: 0 0 0 var(--pc-border-hair) var(--pc-ink);
}

.layers__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--pc-space-1);
}

.layer {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  font-size: var(--pc-text-sm);
  line-height: var(--pc-leading-snug);
}

.layer__toggle {
  display: flex;
  align-items: center;
  gap: var(--pc-space-1);
  cursor: pointer;
}

/* Lock: the layer stays visible but its objects cannot be selected. */
.layer__lock {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-left: auto;
  padding: 0;
  color: var(--pc-n-300);
  background: none;
  border: 0;
  border-radius: var(--pc-radius);
  cursor: pointer;
}

.layer__lock:hover { color: var(--pc-n-500); background: var(--pc-n-100); }

.layer__lock.is-locked,
.layer__lock[aria-pressed="true"] { color: var(--pc-accent-text); }

.layer__lock:focus-visible {
  outline: var(--pc-focus-width) solid var(--pc-focus-color);
  outline-offset: 1px;
  box-shadow: 0 0 0 var(--pc-border-hair) var(--pc-ink);
}

.layer__lock-icon {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.layer input[type="checkbox"] {
  flex: none;
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--pc-d-planning);
  cursor: pointer;
}

.layer input[type="checkbox"]:focus-visible {
  outline: var(--pc-focus-width) solid var(--pc-focus-color);
  outline-offset: 2px;
  box-shadow: 0 0 0 var(--pc-border-hair) var(--pc-ink);
}

.layer input:disabled { cursor: not-allowed; }
.layer input:disabled ~ .layer__name { color: var(--pc-n-300); }

/* Imported layers show the colour they are drawn in. */
.layer__swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.layer__name { color: var(--pc-n-800); }

.layer__note {
  margin-left: auto;
  color: var(--pc-muted);
  font-size: var(--pc-text-xs);
  font-style: italic;
}

.layer__note:not(:empty) + .layer__lock { margin-left: 4px; }

.layers__source,
.layers__attribution {
  margin: 12px 0 0;
  padding-top: var(--pc-space-1);
  border-top: var(--pc-border-hair) solid var(--pc-line);
  color: var(--pc-muted);
  font-size: var(--pc-text-xs);
  line-height: var(--pc-leading-snug);
  overflow-wrap: anywhere;
}

.layers__attribution { border-top: 0; padding-top: 4px; margin-top: 6px; }

/* Settings live at the foot of the layer panel: measurement units. */
.layers__settings {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--pc-n-100);
  font-size: var(--pc-text-sm);
}

.layers__settings-label {
  margin-right: auto;
  color: var(--pc-muted);
}

.layers .info__btn { width: 100%; margin-top: var(--pc-space-1); }

/* ------------------------------- notice -------------------------------- */

.notice {
  position: absolute;
  z-index: var(--pc-z-raised);
  right: var(--pc-space-2);
  bottom: var(--pc-space-2);
  left: var(--pc-space-2);
  max-width: 560px;
  margin: 0 auto;
  padding: var(--pc-space-1) 12px;
  background: var(--pc-ink);
  color: var(--pc-on-ink);
  border-radius: var(--pc-radius);
  box-shadow: var(--pc-shadow-sm);
  font-size: var(--pc-text-xs);
  line-height: var(--pc-leading-snug);
  text-align: center;
}

/* No "error" colour exists in the system - red is the engineering discipline,
   not a status - so a problem is marked with the amber accent bar instead. */
.notice[data-tone="error"] {
  border-left: 3px solid var(--pc-amber);
  text-align: left;
}

.notice[hidden] { display: none; }

/* ------------------------------ error state ---------------------------- */

.error {
  position: absolute;
  z-index: calc(var(--pc-z-raised) + 1);
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--pc-space-1);
  padding: var(--pc-space-3);
  background: var(--pc-n-50);
  color: var(--pc-n-800);
  text-align: center;
}

.error p { margin: 0; max-width: 34ch; }   /* short notice, not body prose */
.error strong { color: var(--pc-ink); font-weight: var(--pc-weight-semibold); }
.error[hidden] { display: none; }

/* -------------------------------- help --------------------------------- */

.help {
  display: flex;
  flex-wrap: wrap;
  gap: 6px var(--pc-space-3);
  padding: 10px var(--pc-gutter);
  background: var(--pc-on-ink);
  border-top: var(--pc-border-hair) solid var(--pc-line);
  color: var(--pc-muted);
  font-size: var(--pc-text-xs);
  line-height: var(--pc-leading-snug);
}

.help b {
  color: var(--pc-n-800);
  font-weight: var(--pc-weight-medium);
}

.help__copyright {
  margin: 0 0 0 auto;
  color: var(--pc-muted);
  font-size: var(--pc-text-xs);
  white-space: nowrap;
}

/* ------------------------------ responsive -----------------------------
   Values mirror --pc-bp-lg / -md / -sm; see the note in tokens.css. */

@media (max-width: 1024px) {
  .info { width: 216px; }
  .layers { width: 190px; }
}

@media (max-width: 768px) {
  .stage { min-height: 360px; }
  .info {
    width: 196px;
    top: var(--pc-space-1);
    left: var(--pc-space-1);
    padding: 12px;
  }
  .info__name { font-size: var(--pc-text-sm); }
  .tool--import { margin-left: 0; }
  .layers {
    top: var(--pc-space-1);
    right: var(--pc-space-1);
    width: 172px;
    padding: 10px 12px 12px;
  }
  .notice { bottom: var(--pc-space-1); font-size: var(--pc-text-xs); }
}

@media (max-width: 480px) {
  .app__subtitle { display: none; }
  .toolbar { gap: 6px; }
  .tool {
    flex: 1 1 auto;
    min-width: 0;
    padding: var(--pc-space-1) 10px;
    text-align: center;
  }
  .stage { min-height: 300px; }
  .info {
    width: auto;
    right: var(--pc-space-1);
    left: var(--pc-space-1);
    padding: 10px;
  }
  .info__rows { display: flex; flex-wrap: wrap; gap: 0 var(--pc-space-2); }
  .info__row { border-top: 0; padding: 2px 0; }
  .info__actions { margin-top: var(--pc-space-1); }
  .info__hint { margin-top: 6px; }
  .help__item:nth-child(n + 4) { display: none; }
  .help__copyright {
    margin-left: 0;
    white-space: normal;
  }
  /* Below the information panel, which is full width here. */
  .layers {
    top: auto;
    right: var(--pc-space-1);
    bottom: 44px;
    width: 164px;
    max-height: 52%;
    overflow-y: auto;
  }
  .layers:not([open]) { padding-bottom: 10px; }
  .notice { bottom: 6px; }
}

/* Landscape phones: protect the model area. */
@media (max-height: 520px) and (orientation: landscape) {
  .app__subtitle, .help { display: none; }
  .stage { min-height: 240px; }
}

@media (prefers-reduced-motion: reduce) {
  .tool, .info__btn { transition: none; }
}
