/* The Listening Field — field-notebook aesthetic: paper, ink, specimen map. */

:root {
  --paper: #f2ecdb;
  --paper2: #ece4cd;
  --ink: #2b3324;
  --ink-soft: #5a614b;
  --moss: #4a6741;      /* flows / keynote */
  --clay: #b05c38;      /* recurs / signal */
  --night: #35506e;     /* on call / soundmark */
  --line: #c9bfa4;
  --accent: #8a3324;
}

* { box-sizing: border-box; }

/* iOS: a slider drag must not become a sheet/page scroll */
input[type="range"] { touch-action: none; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Spectral", Georgia, serif;
  font-size: 15px;
  color: var(--ink);
  background:
    url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="180" height="180"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2"/><feColorMatrix values="0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.045 0"/></filter><rect width="180" height="180" filter="url(%23n)"/></svg>'),
    radial-gradient(ellipse at 30% 10%, #f7f2e4 0%, var(--paper) 55%, var(--paper2) 100%);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;   /* iOS: don't hide the shelf behind the URL bar */
  overflow: hidden;
}

h2, h3, .wordmark { font-family: "Fraunces", Georgia, serif; }

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 22px 8px;
  border-bottom: 1px solid var(--line);
}
.wordmark {
  font-weight: 900;
  font-size: 15px;
  line-height: 0.95;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-right: 3px double var(--line);
  padding-right: 18px;
}
#title {
  flex: 1;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-size: 24px;
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--line);
  color: var(--ink);
  padding: 2px 6px;
  min-width: 120px;
}
#title:focus { outline: none; border-bottom-color: var(--accent); }
.transport { display: flex; gap: 8px; align-items: center; }
#status {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 13px;
  max-width: 210px;
  text-align: right;
}
#status.err { color: var(--accent); }

button, select, input[type="file"]::file-selector-button {
  font-family: "Spectral", Georgia, serif;
  font-size: 14px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink-soft);
  border-radius: 2px;
  padding: 5px 12px;
  cursor: pointer;
}
button:hover { background: var(--ink); color: var(--paper); }
button:disabled { opacity: 0.4; cursor: default; }
button:disabled:hover { background: transparent; color: var(--ink); }
button.big { padding: 9px 16px; font-size: 15px; }
button.live { background: var(--accent); border-color: var(--accent); color: var(--paper); }
button.live:hover { background: var(--accent); color: var(--paper); }
select { background: var(--paper); }

/* ---------- main grid ---------- */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 52px 300px 1fr auto;
  min-height: 0;
}

/* stations rail */
#stations {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}
#stations button {
  flex: 1;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.18em;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 0;
  color: var(--ink-soft);
}
#stations button b { font-family: "Fraunces", serif; font-style: italic; font-size: 15px; }
#stations button.on { background: var(--ink); color: var(--paper); }
#stations button:hover { background: var(--ink); color: var(--paper); }

/* station panel */
#panel {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 20px 22px 40px;
}
#panel section { display: none; }
#panel section.on { display: block; animation: rise 0.35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
#panel h2 {
  font-size: 30px;
  font-weight: 600;
  font-style: italic;
  margin: 0 0 10px;
}
.lede { font-size: 16.5px; font-style: italic; color: var(--ink-soft); }
#panel p, #panel li { line-height: 1.5; }
#panel ul { padding-left: 18px; }
#panel li { margin-bottom: 7px; }
#panel a { color: var(--accent); }
.hint { font-size: 13px; color: var(--ink-soft); font-style: italic; }
#panel label {
  display: block;
  font-size: 13px;
  font-style: italic;
  color: var(--ink-soft);
  margin: 14px 0;
}
#panel textarea, #panel input[type="range"] { width: 100%; margin-top: 4px; }
#panel textarea {
  font-family: "Spectral", Georgia, serif;
  font-size: 14px;
  background: rgba(255,255,255,0.35);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 7px;
  resize: vertical;
}
#meter { display: block; margin: 12px 0 4px; border: 1px solid var(--line); background: rgba(255,255,255,0.3); }

/* ---------- the field ---------- */
#fieldwrap { position: relative; min-width: 0; }
#field { width: 100%; height: 100%; display: block; touch-action: none; }
.ring { fill: none; stroke: var(--line); stroke-dasharray: 3 7; stroke-width: 1.5; }
.ringlabel {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-size: 20px;
  fill: var(--ink-soft);
  opacity: 0.75;
}
.listener { fill: var(--ink); }
.listener-halo { fill: none; stroke: var(--ink); stroke-width: 1; opacity: 0.35; }

.blot { cursor: grab; }
.blot circle.body { stroke: var(--ink); stroke-width: 1; opacity: 0.85; }
.blot.flow  circle.body { fill: var(--moss); }
.blot.recur circle.body { fill: var(--clay); }
.blot.call  circle.body { fill: var(--night); }
.blot text {
  font-family: "Spectral", serif;
  font-size: 19px;
  fill: var(--ink);
  text-anchor: middle;
  pointer-events: none;
}
.blot.sel circle.body { stroke-width: 3.5; opacity: 1; }
.blot circle.pulse { fill: none; stroke: var(--ink); opacity: 0; pointer-events: none; }
.blot.sounding circle.pulse { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse {
  from { opacity: 0.5; r: 26; }
  to   { opacity: 0;   r: 90; }
}

/* ---------- the score ---------- */
#score {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
#ruler {
  position: absolute;
  left: 0; top: 0;
  width: 44px;
}
.tick {
  position: absolute;
  left: 0; right: 0;
  border-top: 1px dashed var(--line);
  font-family: "Fraunces", serif;
  font-style: italic;
  font-size: 11px;
  color: var(--ink-soft);
  padding: 1px 0 0 6px;
  pointer-events: none;
}
#clips {
  position: absolute;
  left: 48px; right: 14px; top: 0;
}
.clip {
  position: absolute;
  border: 1px solid var(--ink-soft);
  border-radius: 2px;
  background: rgba(255,255,255,0.42);
  box-shadow: 2px 2px 0 rgba(43,51,36,0.12);
  cursor: grab;
  overflow: hidden;
  transition: left 0.25s ease, width 0.25s ease;
  touch-action: none;
}
.clip canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.clip .cnm {
  position: absolute;
  top: 3px; left: 6px; right: 4px;
  font-size: 11.5px;
  font-style: italic;
  color: var(--ink);
  pointer-events: none;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.clip.sel { border-color: var(--accent); border-width: 2px; }
.clip.gran { border-style: dotted; }
#playhead {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 2px solid var(--accent);
  pointer-events: none;
}
#playhead::before {
  content: "▸";
  position: absolute;
  left: 2px; top: -11px;
  color: var(--accent);
  font-size: 13px;
}
.scorehint {
  position: absolute;
  left: 0; right: 0; top: 40%;
  text-align: center;
  font-style: italic;
  color: var(--ink-soft);
  pointer-events: none;
}

/* ---------- the walk ---------- */
#walk {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
#walk[hidden] { display: none; }
#map { flex: 1; min-height: 0; background: var(--paper2); }
#map .leaflet-tile { filter: sepia(0.35) saturate(0.55) brightness(1.04); }
.pin {
  width: 26px; height: 26px;
  border-radius: 50% 46% 52% 48%;
  border: 1.5px solid var(--ink);
  background: var(--moss);
  opacity: 0.9;
  box-shadow: 2px 2px 0 rgba(43,51,36,0.2);
}
.pin.sel { border-width: 3px; opacity: 1; }
.pinlabel {
  font-family: "Spectral", serif;
  font-size: 12px;
  font-style: italic;
  color: var(--ink);
  text-shadow: 0 0 3px var(--paper), 0 0 3px var(--paper);
  white-space: nowrap;
  transform: translate(-50%, 15px);
  display: inline-block;
}
.walkerdot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1.5px var(--accent);
}
#walkline {
  height: 170px;
  border-top: 3px double var(--line);
  background:
    url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="180" height="180"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2"/><feColorMatrix values="0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.04 0"/></filter><rect width="180" height="180" filter="url(%23n)"/></filter></svg>'),
    linear-gradient(#f5efdf, #ece4cd);
  cursor: ew-resize;
  touch-action: none;
}
.row.wide { display: flex; gap: 8px; align-items: end; margin: 10px 0; }
.row.wide .sel { flex: 1; }
.row.wide select { width: 100%; }
#drawPath.live { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.leaflet-container { font-family: "Spectral", Georgia, serif; }

/* ---------- inspector ---------- */
#inspector {
  width: 250px;
  border-left: 1px solid var(--line);
  padding: 18px 16px 30px;
  overflow-y: auto;
  background: rgba(255,255,255,0.25);
}
#inspector h3 { margin: 0 0 12px; font-size: 21px; font-style: italic; font-weight: 600; overflow-wrap: anywhere; padding-right: 28px; }
#iClose {
  position: absolute;
  top: 10px; right: 10px;
  border: none;
  font-size: 15px;
  padding: 4px 8px;
}
#inspector { position: relative; }
#inspector label { display: block; font-size: 12.5px; font-style: italic; color: var(--ink-soft); margin: 12px 0; }
#inspector input[type="range"], #inspector input[type="text"], #inspector #iAttr { width: 100%; margin-top: 3px; }
#iAttr {
  font-family: "Spectral", serif; font-size: 13px;
  background: rgba(255,255,255,0.4); border: 1px solid var(--line); padding: 5px; color: var(--ink);
}
#inspector .row { display: flex; gap: 8px; align-items: end; }
#inspector .row .sel { flex: 1; }
#inspector select { width: 100%; }
#inspector .chk { display: flex; align-items: center; gap: 7px; font-style: normal; }
#wave { width: 100%; height: 64px; border: 1px solid var(--line); background: rgba(255,255,255,0.35); margin-top: 10px; }
.trim label { flex: 1; }

/* ---------- shelf ---------- */
footer {
  border-top: 1px solid var(--line);
  padding: 8px 22px 12px;
}
.shelfhead { display: flex; gap: 10px; align-items: baseline; margin-bottom: 8px; }
.shelfhead b { font-family: "Fraunces", serif; font-style: italic; font-size: 17px; margin-right: 8px; }
.shelfhead button { font-size: 12.5px; padding: 3px 10px; }
#shelf {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  min-height: 62px;
  align-items: stretch;
}
.card {
  border: 1px solid var(--ink-soft);
  border-radius: 2px;
  padding: 7px 10px;
  min-width: 150px;
  background: rgba(255,255,255,0.35);
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 2px 2px 0 rgba(43,51,36,0.12);
}
.card .nm { font-weight: 600; font-size: 13.5px; overflow-wrap: anywhere; }
.card .meta {
  font-size: 11.5px; color: var(--ink-soft); font-style: italic;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .ops { display: flex; gap: 6px; margin-top: auto; }
.card .ops button { font-size: 12px; padding: 2px 8px; }

@media (max-width: 900px) {
  /* one column: header / stations / panel / view / shelf — nothing overlaps */
  main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;   /* children shrink; the shelf never gets pushed off */
  }

  header {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px 12px 6px;
  }
  .wordmark { font-size: 11px; padding-right: 10px; }
  #title { font-size: 18px; min-width: 100px; order: 1; flex: 1 1 100%; }
  .transport { order: 0; margin-left: auto; }
  #status { order: 2; flex: 1 1 100%; text-align: left; max-width: none; font-size: 12px; }
  button.big { padding: 7px 12px; font-size: 14px; }

  /* stations become a horizontal rail */
  #stations {
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--line);
    flex: none;
  }
  #stations button {
    writing-mode: horizontal-tb;
    flex-direction: column;
    gap: 1px;
    padding: 6px 0 5px;
    font-size: 11px;
    letter-spacing: 0.08em;
    border-bottom: none;
    border-right: 1px solid var(--line);
    justify-content: center;
  }
  #stations button:last-child { border-right: none; }
  #stations button b { font-size: 12px; }

  /* the guide panel scrolls on its own; tap the active station to hide it */
  #panel {
    border-right: none;
    border-bottom: 1px solid var(--line);
    flex: 0 1 auto;
    min-height: 0;
    max-height: 30dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 16px 20px;
  }
  #panel.closed { display: none; }
  #panel h2 { font-size: 22px; }
  .lede { font-size: 14.5px; }

  #fieldwrap { flex: 1 1 0; min-height: 150px; }
  #walkline { height: 96px; flex: none; }
  #map { min-height: 50px; }

  /* inspector = bottom sheet above the shelf, dismissible */
  #inspector {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 45dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 30;
    background: var(--paper);
    border-left: none;
    border-top: 2px solid var(--ink-soft);
    box-shadow: 0 -6px 18px rgba(43,51,36,0.25);
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  /* the shelf stays reachable above the iOS URL bar */
  footer {
    padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
  }
  .shelfhead { flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
  .shelfhead b { font-size: 15px; }
  #shelf { min-height: 56px; }
  .card { min-width: 128px; padding: 5px 8px; }
}
