/* ===========================================================
   HamChat — Retro radio-shack terminal aesthetic.
   Phosphor green on graphite, panel-mounted controls,
   subtle scanlines, glowing LEDs.
   =========================================================== */

:root {
  --bg-deep:        #0a0d0c;
  --bg-panel:       #14191a;
  --bg-panel-2:     #1a2122;
  --bg-recess:      #060807;
  --edge:           #2a3433;
  --edge-hi:        #3a4a48;

  --phosphor:       #6dff8a;
  --phosphor-dim:   #2a8a3e;
  --phosphor-glow:  #6dff8a55;
  --amber:          #ffb347;
  --amber-glow:     #ffb34755;
  --red:            #ff5252;
  --red-glow:       #ff525255;

  --ink:            #c8d6d2;
  --ink-dim:        #6e7b78;

  --font-display:   'VT323', 'Courier New', monospace;
  --font-mono:      'JetBrains Mono', 'Menlo', 'Consolas', monospace;

  --rad-sm: 3px;
  --rad-md: 6px;
  --rad-lg: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
  overflow: hidden;
}

body {
  /* subtle radial vignette + faint scanlines for CRT feel */
  background:
    radial-gradient(ellipse at center, #0e1413 0%, #050706 100%),
    repeating-linear-gradient(
      0deg,
      rgba(0,0,0,0) 0,
      rgba(0,0,0,0) 2px,
      rgba(255,255,255,0.012) 3px,
      rgba(0,0,0,0) 4px
    );
  background-blend-mode: normal, overlay;
}

.chassis {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px;
  gap: 12px;
}

/* ---------- TOP PANEL / BRAND ---------- */
.panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(180deg, var(--bg-panel) 0%, var(--bg-panel-2) 100%);
  border: 1px solid var(--edge);
  border-radius: var(--rad-md);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.04),
    0 4px 20px rgba(0,0,0,0.6);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  font-size: 38px;
  color: var(--phosphor);
  text-shadow: 0 0 12px var(--phosphor-glow), 0 0 4px var(--phosphor-glow);
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.85; }
  50%      { opacity: 1; }
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 34px;
  letter-spacing: 6px;
  color: var(--phosphor);
  text-shadow: 0 0 8px var(--phosphor-glow);
}
.brand-text p {
  margin: -2px 0 0 0;
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--ink-dim);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 18px;
}

.status-led {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--ink-dim);
}

.status-led .dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #1a1a1a;
  border: 1px solid #000;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.8);
  transition: all 0.15s ease;
}
.status-led[data-state="on"] .dot {
  background: var(--phosphor);
  box-shadow: 0 0 8px var(--phosphor-glow), inset 0 0 2px #fff;
}
.status-led[data-state="rx"] .dot {
  background: var(--phosphor);
  box-shadow: 0 0 10px var(--phosphor-glow);
  animation: blink-rx 0.7s ease-in-out infinite;
}
.status-led[data-state="tx"] .dot {
  background: var(--red);
  box-shadow: 0 0 12px var(--red-glow);
  animation: blink-tx 0.4s ease-in-out infinite;
}
@keyframes blink-rx { 0%,100%{opacity:1} 50%{opacity:0.45} }
@keyframes blink-tx { 0%,100%{opacity:1} 50%{opacity:0.55} }

.clock {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--amber);
  text-shadow: 0 0 6px var(--amber-glow);
  letter-spacing: 2px;
  padding: 4px 10px;
  background: var(--bg-recess);
  border: 1px solid var(--edge);
  border-radius: var(--rad-sm);
  min-width: 145px;
  text-align: center;
}

/* ---------- CONTROLS PANEL ---------- */
.panel-controls {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1.4fr 1.6fr;
  gap: 14px;
  padding: 14px 22px;
  background: var(--bg-panel);
  border: 1px solid var(--edge);
  border-radius: var(--rad-md);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}

.ctrl {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ctrl label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--ink-dim);
  font-weight: 500;
}

.ctrl input[type="text"],
.ctrl select {
  background: var(--bg-recess);
  border: 1px solid var(--edge-hi);
  color: var(--phosphor);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  border-radius: var(--rad-sm);
  outline: none;
  text-shadow: 0 0 3px var(--phosphor-glow);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ctrl input[type="text"]:focus,
.ctrl select:focus {
  border-color: var(--phosphor);
  box-shadow: 0 0 0 1px var(--phosphor), inset 0 0 6px var(--phosphor-glow);
}

.ctrl input[type="text"] {
  text-transform: uppercase;
  letter-spacing: 2px;
}

.ctrl-buttons {
  flex-direction: row;
  align-items: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.ctrl-buttons .btn {
  flex: 1 1 0;           /* equal share of available width */
  min-width: 0;
  padding: 9px 8px;       /* slightly tighter to fit three buttons */
  white-space: nowrap;
  text-align: center;
  letter-spacing: 1px;    /* tighter so "WATERFALL: OFF" fits */
}

.btn {
  background: linear-gradient(180deg, #2a3434 0%, #1a2222 100%);
  color: var(--ink);
  border: 1px solid var(--edge-hi);
  padding: 9px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 2px;
  border-radius: var(--rad-sm);
  cursor: pointer;
  transition: all 0.12s ease;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 1px 2px rgba(0,0,0,0.4);
}
.btn:hover:not(:disabled) {
  border-color: var(--phosphor);
  color: var(--phosphor);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 0 8px var(--phosphor-glow);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #1c4225 0%, #0e2a14 100%);
  border-color: var(--phosphor-dim);
  color: var(--phosphor);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #235029 0%, #163a1c 100%);
}

.btn-tx {
  background: linear-gradient(180deg, #4a1c1c 0%, #2a0e0e 100%);
  border-color: #8a3030;
  color: #ff8a8a;
  font-weight: 700;
  padding: 0 22px;
}
.btn-tx:hover:not(:disabled) {
  border-color: var(--red);
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 0 12px var(--red-glow);
}

.btn-tiny {
  padding: 4px 10px;
  font-size: 9px;
}

/* ---------- MAIN PANEL ---------- */
.panel-main {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 12px;
  min-height: 0;
}

/* When the waterfall is OFF, the chat pane takes the full width. */
.panel-main.single {
  grid-template-columns: 1fr;
}

.chat-pane, .scope-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--edge);
  border-radius: var(--rad-md);
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(180deg, #1e2627 0%, #161c1d 100%);
  border-bottom: 1px solid var(--edge);
}

.pane-title {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 4px;
  color: var(--phosphor);
  text-shadow: 0 0 4px var(--phosphor-glow);
}

.freq-readout {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--amber);
  text-shadow: 0 0 4px var(--amber-glow);
}

/* Chat log */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
  background: var(--bg-recess);
  margin: 10px;
  border-radius: var(--rad-sm);
  border: 1px inset var(--edge);
  font-size: 14px;
  line-height: 1.55;
  scrollbar-width: thin;
  scrollbar-color: var(--edge-hi) var(--bg-recess);
}
.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-track { background: var(--bg-recess); }
.chat-log::-webkit-scrollbar-thumb { background: var(--edge-hi); border-radius: 4px; }

.msg {
  margin-bottom: 6px;
  word-wrap: break-word;
}
.msg .ts {
  color: var(--ink-dim);
  margin-right: 8px;
  font-size: 11px;
}
.msg .call {
  color: var(--amber);
  text-shadow: 0 0 3px var(--amber-glow);
  margin-right: 6px;
  font-weight: 700;
}
.msg .body {
  color: var(--phosphor);
  text-shadow: 0 0 2px var(--phosphor-glow);
}
.msg.tx .call { color: #ff8a8a; text-shadow: 0 0 3px var(--red-glow); }
.msg.tx .body { color: #ffb8b8; text-shadow: 0 0 2px var(--red-glow); }
.msg.sys {
  color: var(--ink-dim);
  font-style: italic;
  font-size: 12px;
}
.msg.sys::before { content: '※ '; color: var(--ink-dim); }

/* Compose row */
.compose {
  display: flex;
  align-items: stretch;
  margin: 0 10px 10px 10px;
  background: var(--bg-recess);
  border: 1px solid var(--edge-hi);
  border-radius: var(--rad-sm);
  overflow: hidden;
}
.compose-prefix {
  padding: 10px 12px;
  background: #0e1212;
  color: var(--amber);
  text-shadow: 0 0 3px var(--amber-glow);
  font-size: 13px;
  border-right: 1px solid var(--edge);
  white-space: nowrap;
  display: flex;
  align-items: center;
  letter-spacing: 1px;
}
#compose-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 10px 12px;
  color: var(--phosphor);
  text-shadow: 0 0 2px var(--phosphor-glow);
  font-family: var(--font-mono);
  font-size: 14px;
}
#compose-input::placeholder { color: var(--ink-dim); }
.btn-tx { border-radius: 0; border: none; border-left: 1px solid var(--edge-hi); }

.ptt-instruction {
  margin: 0 10px 12px 10px;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--ink-dim);
  background: rgba(255,179,71,0.04);
  border-left: 2px solid var(--amber);
  border-radius: var(--rad-sm);
  line-height: 1.5;
}

/* Scope pane / waterfall */
.scope-pane { padding: 0; }
#waterfall {
  width: calc(100% - 20px);
  height: auto;
  flex: 1;
  margin: 10px;
  background: #000;
  border: 1px inset var(--edge);
  border-radius: var(--rad-sm);
  image-rendering: pixelated;
  display: block;
  min-height: 0;
}
.scope-legend {
  display: flex;
  justify-content: space-between;
  padding: 0 14px 6px 14px;
  font-size: 10px;
  color: var(--ink-dim);
  letter-spacing: 1px;
}

.scope-meta {
  padding: 8px 14px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.scope-meta > div {
  display: grid;
  grid-template-columns: 70px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--ink-dim);
  letter-spacing: 2px;
}
.scope-meta input[type="range"] {
  -webkit-appearance: none; appearance: none;
  background: var(--bg-recess);
  height: 4px;
  border-radius: 2px;
  outline: none;
}
.scope-meta input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px;
  background: var(--phosphor);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 6px var(--phosphor-glow);
}
.scope-meta input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--phosphor);
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 0 6px var(--phosphor-glow);
}

/* ---------- BOTTOM PANEL ---------- */
.panel-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--bg-panel);
  border: 1px solid var(--edge);
  border-radius: var(--rad-md);
  font-size: 11px;
  color: var(--ink-dim);
  gap: 16px;
}
.reg-note { line-height: 1.5; }
.reg-note strong { color: var(--amber); }
.version {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--phosphor-dim);
  white-space: nowrap;
}

/* ---------- RESPONSIVE ---------- */

/* Tablet / small laptop */
@media (max-width: 1100px) {
  .panel-controls {
    grid-template-columns: repeat(2, 1fr);
  }
  .panel-main {
    grid-template-columns: 1fr;
  }
  .scope-pane {
    max-height: 240px;
  }
}

/* Mobile landscape / small tablet */
@media (max-width: 700px) {
  .panel-top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  .status-row { justify-content: space-between; }
  .panel-controls {
    grid-template-columns: 1fr;
    padding: 12px 14px;
  }
  .panel-bottom {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  body { font-size: 13px; }
}

/* Phone portrait (iPhone, Android) */
@media (max-width: 480px) {
  html, body {
    /* The virtual keyboard + toolbars eat screen real estate. Let the
       page scroll rather than try to fit everything in 100vh. */
    overflow: auto;
    height: auto;
    min-height: 100%;
  }
  body {
    /* Respect iOS safe areas (notch, home indicator) */
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
    font-size: 14px;
  }
  .chassis {
    display: block;        /* stop being a 100vh grid */
    height: auto;
    padding: 8px;
    gap: 8px;
    max-width: 100%;
  }
  .chassis > * { margin-bottom: 8px; }

  /* Header */
  .panel-top { padding: 10px 12px; }
  .brand { gap: 10px; }
  .brand-mark { font-size: 28px; }
  .brand-text h1 { font-size: 24px; letter-spacing: 3px; }
  .brand-text p { font-size: 9px; letter-spacing: 2px; }
  .clock {
    font-size: 16px;
    min-width: 110px;
    padding: 3px 8px;
  }
  .status-row { gap: 10px; }
  .status-led .lbl { display: none; }  /* LEDs without labels saves space */
  .status-led { gap: 0; }

  /* Controls */
  .panel-controls { gap: 10px; padding: 10px 12px; }
  .ctrl input[type="text"],
  .ctrl select {
    padding: 12px 10px;       /* bigger touch targets */
    font-size: 16px;          /* 16px prevents iOS zoom-on-focus */
  }
  .btn {
    padding: 14px 16px;
    font-size: 12px;
    min-height: 44px;         /* Apple HIG minimum touch size */
  }
  .ctrl-buttons { flex-wrap: wrap; }
  .ctrl-buttons .btn { flex: 1 1 auto; min-width: 120px; }

  /* Main panels - stack vertically, reasonable heights */
  .panel-main { gap: 8px; }
  .chat-pane  { min-height: 280px; }
  .scope-pane { max-height: 180px; }
  .pane-header { padding: 8px 12px; }
  .pane-title { font-size: 13px; letter-spacing: 2px; }
  .freq-readout { font-size: 14px; }

  /* Chat log */
  .chat-log {
    margin: 8px;
    padding: 10px 12px;
    font-size: 14px;
  }
  .msg .ts { font-size: 10px; margin-right: 6px; }

  /* Compose row - stack vertically so TX button is full-width */
  .compose {
    flex-direction: column;
    margin: 0 8px 8px 8px;
  }
  .compose-prefix {
    border-right: none;
    border-bottom: 1px solid var(--edge);
    padding: 8px 12px;
    font-size: 12px;
  }
  #compose-input {
    padding: 12px;
    font-size: 16px;          /* no iOS zoom */
  }
  .btn-tx {
    border-left: none;
    border-top: 1px solid var(--edge-hi);
    padding: 14px;
    font-size: 14px;
    min-height: 48px;
  }
  .ptt-instruction {
    margin: 0 8px 8px 8px;
    font-size: 12px;
  }

  /* Waterfall */
  #waterfall { margin: 8px; min-height: 140px; }
  .scope-legend { padding: 0 10px 4px 10px; font-size: 9px; }
  .scope-meta { padding: 6px 10px 10px 10px; }

  /* Footer */
  .panel-bottom {
    padding: 10px 12px;
    font-size: 11px;
    gap: 6px;
  }
  .version { font-size: 11px; letter-spacing: 1px; }
}

/* Very narrow screens (older/small iPhones) */
@media (max-width: 360px) {
  .brand-text h1 { font-size: 20px; letter-spacing: 2px; }
  .brand-text p { display: none; }
  .clock { font-size: 14px; min-width: 95px; }
}
