/* =====================================================================
   SEISMOGRAPH — design tokens
   Palette is an aged recording-station instrument, not a flat dark UI:
   warm bistre black, brass for the calm baseline, ember for energy.
   ===================================================================== */

:root{
  --ink:        #0b0a08;
  --ink-2:      #14110c;
  --ink-3:      #1c1812;
  --paper-line: rgba(201,151,74,0.09);
  --paper-line-strong: rgba(201,151,74,0.16);

  --brass:        #c9974a;
  --brass-bright: #e3b568;
  --brass-dim:    #8a6a3a;

  --ember:        #e8602f;
  --ember-bright: #ff7a45;
  --ember-hot:    #ff4d2e;

  --bone:       #ece4d3;
  --bone-dim:   #c9bea7;
  --smoke:      #948a78;
  --smoke-dim:  #5c5546;

  --mag-micro:    #6f6858;
  --mag-minor:    #c9974a;
  --mag-moderate: #e0913f;
  --mag-strong:   #e8602f;
  --mag-major:    #ff4d2e;

  --font-display: 'Fraunces', Georgia, serif;
  --font-ui:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:    'JetBrains Mono', 'SF Mono', Consolas, monospace;

  --radius: 10px;
  --bezel-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 0 0 1px rgba(201,151,74,0.14), 0 18px 40px -20px rgba(0,0,0,0.8);
}

*{ box-sizing: border-box; }
html, body{ margin:0; padding:0; }

body{
  background: var(--ink);
  background-image:
    radial-gradient(ellipse 1200px 700px at 18% -10%, rgba(201,151,74,0.07), transparent 60%),
    radial-gradient(ellipse 900px 600px at 100% 0%, rgba(232,96,47,0.05), transparent 60%);
  color: var(--bone);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a{ color: var(--brass-bright); text-decoration: none; border-bottom: 1px solid rgba(201,151,74,0.35); }
a:hover{ color: var(--ember-bright); border-color: rgba(232,96,47,0.5); }

:focus-visible{
  outline: 2px solid var(--brass-bright);
  outline-offset: 2px;
}

h1, h2{ font-family: var(--font-display); margin: 0; color: var(--bone); }

main{
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px 60px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* =====================================================================
   MASTHEAD
   ===================================================================== */

.masthead{
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px 28px 18px;
}

.masthead-row{
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 14px;
  border-bottom: 1px solid var(--paper-line-strong);
  padding-bottom: 18px;
}

.eyebrow{
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass-dim);
  margin-bottom: 8px;
}

.masthead-mark h1{
  font-size: clamp(34px, 6vw, 54px);
  font-weight: 900;
  letter-spacing: -0.01em;
  line-height: 1;
}

.masthead-readout{
  display: flex;
  align-items: center;
  gap: 18px;
}

.clock{
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--bone);
  letter-spacing: 0.02em;
}
.clock-zone{
  font-size: 11px;
  color: var(--smoke);
  margin-left: 6px;
  letter-spacing: 0.08em;
}

.status{
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--smoke);
  padding: 6px 12px;
  border: 1px solid var(--paper-line-strong);
  border-radius: 999px;
}
.status-dot{
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--smoke-dim);
  box-shadow: none;
}
.status-dot.live{
  background: var(--ember);
  box-shadow: 0 0 0 0 rgba(232,96,47,0.6);
  animation: statusPulse 2s infinite;
}
.status-dot.warn{ background: var(--brass); }
@keyframes statusPulse{
  0%   { box-shadow: 0 0 0 0 rgba(232,96,47,0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(232,96,47,0); }
  100% { box-shadow: 0 0 0 0 rgba(232,96,47,0); }
}

/* =====================================================================
   PANELS — shared shell
   ===================================================================== */

.panel{
  background: linear-gradient(180deg, var(--ink-2), var(--ink-3));
  border-radius: var(--radius);
  box-shadow: var(--bezel-shadow);
  padding: 22px 24px 26px;
}

.panel-head{ margin-bottom: 16px; }
.panel-head-row{
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 14px;
}
.panel-head h2{
  font-size: 22px;
  font-weight: 600;
  font-style: italic;
}
.panel-sub{
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--smoke);
  max-width: 56ch;
}

/* =====================================================================
   LIVE RECORDER
   ===================================================================== */

.recorder-frame{
  position: relative;
  border-radius: 8px;
  padding: 14px;
  background: linear-gradient(180deg, #232019, #161310);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset, 0 0 0 1px rgba(201,151,74,0.18);
}

.rivet{
  position: absolute;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--brass-bright), var(--brass-dim) 70%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.rivet-tl{ top: 9px; left: 9px; }
.rivet-tr{ top: 9px; right: 9px; }
.rivet-bl{ bottom: 9px; left: 9px; }
.rivet-br{ bottom: 9px; right: 9px; }

.recorder-paper{
  position: relative;
  height: 240px;
  border-radius: 4px;
  overflow: hidden;
  background-color: #100d09;
  background-image:
    repeating-linear-gradient(to right, var(--paper-line) 0, var(--paper-line) 1px, transparent 1px, transparent 60px),
    repeating-linear-gradient(to bottom, var(--paper-line) 0, var(--paper-line) 1px, transparent 1px, transparent 30px);
}

#liveCanvas{
  display: block;
  width: 100%;
  height: 100%;
}

.recorder-flash{
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 92% 50%, rgba(255,122,69,0.35), transparent 55%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.recorder-flash.show{ opacity: 1; }

.recorder-axis{
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--smoke-dim);
  padding: 8px 4px 0;
  letter-spacing: 0.04em;
}

/* =====================================================================
   DIAL STRIP
   ===================================================================== */

.dial-strip{
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: linear-gradient(180deg, var(--ink-2), var(--ink-3));
  border-radius: var(--radius);
  box-shadow: var(--bezel-shadow);
}

.dial{
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 22px;
  border-right: 1px solid var(--paper-line-strong);
}
.dial:last-child{ border-right: none; }

.dial-label{
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brass-dim);
}
.dial-value{
  font-family: var(--font-mono);
  font-size: clamp(18px, 2.4vw, 24px);
  font-weight: 700;
  color: var(--bone);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =====================================================================
   FILTER ROW
   ===================================================================== */

.filter-row{
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-btn{
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--smoke);
  background: transparent;
  border: 1px solid var(--paper-line-strong);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.filter-btn:hover{ color: var(--bone); border-color: var(--brass-dim); }
.filter-btn.is-active{
  color: var(--ink);
  background: var(--brass);
  border-color: var(--brass);
  font-weight: 600;
}

/* =====================================================================
   TIMELINE (72h record)
   ===================================================================== */

.timeline-wrap{
  position: relative;
}
#timelineSvgHost svg{
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.tl-grid{ stroke: var(--paper-line); stroke-width: 1; }
.tl-axis-text{ font-family: var(--font-mono); font-size: 10px; fill: var(--smoke-dim); }
.tl-day-rule{ stroke: var(--paper-line-strong); stroke-width: 1; stroke-dasharray: 2 3; }
.tl-day-label{ font-family: var(--font-mono); font-size: 10.5px; fill: var(--brass-dim); letter-spacing: 0.06em; }
.tl-stem{ stroke-width: 1.4; }
.tl-dot{ cursor: pointer; transition: r 0.12s ease; }
.tl-dot:hover, .tl-dot:focus{ filter: drop-shadow(0 0 4px currentColor); }

.timeline-tooltip{
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  border: 1px solid var(--brass-dim);
  border-radius: 6px;
  padding: 8px 11px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  color: var(--bone);
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.7);
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.1s ease;
  white-space: nowrap;
  z-index: 5;
}
.timeline-tooltip.show{ opacity: 1; }
.timeline-tooltip b{ color: var(--brass-bright); }

/* =====================================================================
   SPLIT: FEED + MAP
   ===================================================================== */

.split{
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) 1.15fr;
  gap: 22px;
  align-items: stretch;
}

.feed-panel{ display: flex; flex-direction: column; }

.feed-list{
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  max-height: 420px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.feed-list::-webkit-scrollbar{ width: 8px; }
.feed-list::-webkit-scrollbar-track{ background: transparent; }
.feed-list::-webkit-scrollbar-thumb{ background: var(--smoke-dim); border-radius: 4px; }

.feed-item{
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 11px 6px;
  border-bottom: 1px solid var(--paper-line);
  animation: feedIn 0.4s ease;
}
@keyframes feedIn{
  from{ opacity: 0; transform: translateY(-4px); background: rgba(232,96,47,0.12); }
  to{ opacity: 1; transform: translateY(0); }
}

.feed-mag{
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  padding: 5px 0;
  border-radius: 6px;
  color: var(--ink);
}

.feed-info{ min-width: 0; }
.feed-place{
  font-size: 13.5px;
  color: var(--bone-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.feed-meta{
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--smoke);
  margin-top: 2px;
}

.feed-time{
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--smoke);
  text-align: right;
  white-space: nowrap;
}

.feed-empty, .feed-loading{
  padding: 24px 6px;
  color: var(--smoke);
  font-size: 13px;
  text-align: center;
}

/* =====================================================================
   MAP
   ===================================================================== */

.map-panel{ display: flex; flex-direction: column; }
#map{
  flex: 1;
  min-height: 420px;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(201,151,74,0.14);
  background: #100d09;
}
.leaflet-popup-content-wrapper{
  background: var(--ink-2);
  color: var(--bone);
  border-radius: 6px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.7);
}
.leaflet-popup-tip{ background: var(--ink-2); }
.leaflet-popup-content{ font-family: var(--font-ui); font-size: 12.5px; margin: 10px 12px; }
.leaflet-popup-content b{ font-family: var(--font-mono); color: var(--brass-bright); }
.leaflet-container a.leaflet-popup-close-button{ color: var(--smoke); }
.leaflet-control-attribution{
  background: rgba(11,10,8,0.7) !important;
  color: var(--smoke-dim) !important;
}
.leaflet-control-attribution a{ color: var(--smoke) !important; }

/* =====================================================================
   FOOTER
   ===================================================================== */

.site-footer{
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 28px 50px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  border-top: 1px solid var(--paper-line-strong);
}
.site-footer p{
  margin: 0;
  font-size: 12px;
  color: var(--smoke-dim);
  max-width: 70ch;
}

.sound-toggle{
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--smoke);
  background: transparent;
  border: 1px solid var(--paper-line-strong);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.sound-toggle[aria-pressed="true"]{ color: var(--brass-bright); border-color: var(--brass-dim); }
.sound-icon{ margin-right: 4px; }

/* =====================================================================
   STATION PICKER + RAW WAVEFORM
   ===================================================================== */

.station-panel{ display: flex; flex-direction: column; gap: 14px; }

.station-controls{
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.station-select{
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--bone);
  background: var(--ink-2);
  border: 1px solid rgba(201,151,74,0.22);
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
  min-width: 240px;
  max-width: 340px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a6a3a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.station-select:focus{ outline: 2px solid var(--brass-bright); outline-offset: 2px; }
.station-select option, .station-select optgroup{
  background: #1c1812;
  color: var(--bone);
}

.station-refresh-btn{
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--smoke);
  background: transparent;
  border: 1px solid var(--paper-line-strong);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.station-refresh-btn:hover{ color: var(--brass-bright); border-color: var(--brass-dim); }

.station-canvas-wrap{
  position: relative;
  width: 100%;
  height: 240px;
  background: var(--ink-2);
  border: 1px solid rgba(201,151,74,0.12);
  border-radius: 6px;
  overflow: hidden;
}
.station-canvas-wrap canvas{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.station-info{
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--smoke);
  padding: 2px 0;
}

/* =====================================================================
   RESPONSIVE — mobile-first overhaul
   Breakpoints: 880px (tablet), 560px (phone), 380px (small phone)
   ===================================================================== */

/* --- Tablet (≤880px) --- */
@media (max-width: 880px){
  main{ gap: 20px; padding: 0 20px 50px; }

  .masthead{ padding: 22px 20px 16px; }

  /* Stack feed + map vertically */
  .split{ grid-template-columns: 1fr; gap: 20px; }

  /* Stats: 2×2 grid */
  .dial-strip{ grid-template-columns: repeat(2, 1fr); }
  .dial:nth-child(2){ border-right: none; }
  .dial:nth-child(1),
  .dial:nth-child(2){ border-bottom: 1px solid var(--paper-line-strong); }

  #map{ min-height: 320px; }
  .feed-list{ max-height: 320px; }

  /* Station select full width */
  .station-select{ min-width: 0; flex: 1; max-width: 100%; }
  .station-controls{ width: 100%; }

  /* Panel header: stack on small tablet */
  .panel-head-row{ flex-direction: column; align-items: flex-start; gap: 12px; }
  .filter-row{ width: 100%; }
}

/* --- Phone (≤560px) --- */
@media (max-width: 560px){
  /* Layout */
  main{ padding: 0 12px 40px; gap: 16px; }
  .masthead{ padding: 16px 12px 14px; }

  /* Masthead: clock + status stack below title */
  .masthead-row{ flex-direction: column; align-items: flex-start; gap: 10px; }
  .masthead-readout{ width: 100%; justify-content: space-between; }
  .clock{ font-size: 16px; }
  .masthead-mark h1{ font-size: clamp(28px, 8vw, 40px); }
  .eyebrow{ font-size: 10px; }

  /* Panels */
  .panel{ padding: 16px 14px 18px; border-radius: 8px; }
  .panel-head h2{ font-size: 18px; }
  .panel-sub{ font-size: 12px; }

  /* Recorder */
  .recorder-paper{ height: 160px; }
  .recorder-frame{ padding: 10px; }
  .rivet{ width: 5px; height: 5px; }
  .rivet-tl{ top: 6px; left: 6px; }
  .rivet-tr{ top: 6px; right: 6px; }
  .rivet-bl{ bottom: 6px; left: 6px; }
  .rivet-br{ bottom: 6px; right: 6px; }
  .recorder-axis{ font-size: 10px; }

  /* Station canvas shorter on phone */
  .station-canvas-wrap{ height: 160px; }
  .station-info{ font-size: 10px; }

  /* Station controls: select full width, refresh below */
  .station-controls{ flex-direction: column; align-items: stretch; gap: 8px; }
  .station-select{
    min-width: 0; width: 100%; max-width: 100%;
    font-size: 13px; padding: 10px 32px 10px 10px;
  }
  .station-refresh-btn{
    width: 100%; text-align: center;
    padding: 10px 14px; font-size: 12px;
    border-radius: 8px;
  }

  /* Dials: 2×2, larger tap targets */
  .dial{ padding: 14px 14px; }
  .dial-label{ font-size: 10px; }
  .dial-value{ font-size: clamp(16px, 5vw, 22px); }

  /* Filter buttons: scroll horizontally so they stay on one line */
  .filter-row{
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .filter-row::-webkit-scrollbar{ display: none; }
  .filter-btn{
    flex-shrink: 0;
    padding: 8px 13px;
    font-size: 11px;
    /* Bigger tap target */
    min-height: 36px;
  }

  /* Feed items: tighter, time wraps below */
  .feed-item{
    grid-template-columns: 46px 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
    padding: 10px 4px;
  }
  .feed-mag{ font-size: 13px; }
  .feed-place{ font-size: 13px; }
  .feed-time{
    grid-column: 2;
    text-align: left;
    font-size: 11px;
    color: var(--smoke-dim);
  }

  /* Map: shorter on phone */
  #map{ min-height: 260px; }

  /* Footer: stack everything */
  .site-footer{
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    padding: 18px 12px 36px;
  }
  .footer-right{
    width: 100%;
    justify-content: space-between;
  }
  .site-footer p{ font-size: 11px; }
  .footer-credit{ font-size: 11px; }

  /* Sound toggle: larger tap target */
  .sound-toggle{ padding: 9px 16px; font-size: 12px; min-height: 38px; }

  /* Tooltip: prevent overflow on narrow screens */
  .timeline-tooltip{
    font-size: 11px;
    max-width: calc(100vw - 32px);
    white-space: normal;
    line-height: 1.4;
  }
}

/* --- Small phone (≤380px) --- */
@media (max-width: 380px){
  main{ padding: 0 10px 36px; gap: 14px; }
  .masthead{ padding: 14px 10px 12px; }
  .panel{ padding: 14px 12px 16px; }
  .recorder-paper{ height: 140px; }
  .station-canvas-wrap{ height: 140px; }
  .dial-strip{ grid-template-columns: repeat(2, 1fr); }
  .dial{ padding: 12px 10px; }
  #map{ min-height: 220px; }
}

/* --- Touch: bigger tap targets on coarse pointers --- */
@media (pointer: coarse){
  .filter-btn{ min-height: 40px; padding: 9px 14px; }
  .sound-toggle{ min-height: 40px; }
  .station-refresh-btn{ min-height: 40px; }
  .feed-item{ padding: 13px 4px; }
  .tl-dot{ r: 6; }  /* timeline dots easier to tap */
}

@media (prefers-reduced-motion: reduce){
  .status-dot.live{ animation: none; }
  .feed-item{ animation: none; }
}

/* Footer layout */
.footer-data{ flex: 1; min-width: 0; }
.footer-right{
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.footer-credit{
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--smoke-dim);
  white-space: nowrap;
}
.footer-credit a{
  color: var(--brass-bright);
  border-bottom-color: rgba(201,151,74,0.25);
  transition: color 0.15s;
}
.footer-credit a:hover{ color: var(--ember-bright); }

/* Safe-area insets for notched/dynamic-island phones */
@supports (padding: env(safe-area-inset-left)){
  .masthead{ padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
  main{ padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .site-footer{ padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); padding-bottom: max(36px, env(safe-area-inset-bottom)); }
}
