/* WhatTheRx: hand-held instrument. Positive (reflective) LCD for sunlight,
   safety-yellow housing, hard keys. One bold element: the margin readout. */
:root {
  color-scheme: light;
  --housing: #F2C200;
  --glass: #CFD8C2;
  --ink: #14201A;
  --ink-dim: #4E5B51;
  --casing: #E8EAE3;
  --key: #3A3F3C;
  --alarm: #B3261E;
  --rule: #B9C2AE;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* components set display, which would beat the attribute */
html { background: var(--casing); }
body {
  margin: 0;
  color: var(--ink);
  font: 16px/1.4 system-ui, Roboto, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* Housing: the yellow top of the instrument. */
.housing {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--housing); border-bottom: 4px solid var(--ink);
}
h1 { margin: 0; font-size: 22px; font-weight: 900; letter-spacing: -0.02em; }
.link { font-size: 14px; font-weight: 700; padding-left: 18px; position: relative; }
.link::before {
  content: ""; position: absolute; left: 0; top: 50%; width: 11px; height: 11px; margin-top: -6px;
  border-radius: 50%; border: 2px solid var(--ink); background: transparent;
}
.link.on::before { background: var(--ink); }

main { padding: 12px 14px 40px; max-width: 560px; margin: 0 auto; }
h2 { margin: 22px 0 6px; font-size: 15px; font-weight: 800; }

/* LCD window: inset glass with a dark bezel. */
.lcd {
  position: relative; display: grid; grid-template-columns: 1fr auto; column-gap: 12px;
  padding: 12px 14px 10px; background: var(--glass); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 6px;
  box-shadow: inset 0 3px 0 rgba(20, 32, 26, .14);
}
.lcd.idle { display: block; }
.lcd p { margin: 0; }
.reading { display: flex; align-items: baseline; gap: 4px; line-height: .9; }
.reading .value { font-size: 84px; font-weight: 900; letter-spacing: -0.04em; }
.reading .unit { font-size: 26px; font-weight: 800; }
.value.low, .value.none { color: var(--alarm); }
.reading .value.none { font-size: 52px; letter-spacing: -0.03em; }
.legend { grid-column: 1; font-size: 14px; color: var(--ink-dim); }
.lcd .side { grid-column: 2; grid-row: 1 / span 2; align-self: center; text-align: right; font-size: 13px; color: var(--ink-dim); }
.lcd .side p + p { margin-top: 6px; }
.lcd .side b { display: block; font-size: 26px; font-weight: 900; color: var(--ink); line-height: 1; }
.meter { grid-column: 1 / -1; margin-top: 10px; height: 14px; }
.scale { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-dim); }
.where { grid-column: 1 / -1; margin-top: 6px !important; padding-top: 6px; border-top: 1px solid var(--rule); font-size: 14px; font-weight: 700; }

/* Bars: margin above the demodulation floor, 0..30 dB (inline SVG). */
.bar, .meter { display: block; width: 100%; background: rgba(20, 32, 26, .12); outline: 1.5px solid var(--ink); outline-offset: -1.5px; }
.bar { height: 10px; }
.bar rect, .meter rect { fill: var(--ink); }
.bar.low rect, .meter.low rect { fill: var(--alarm); }

/* Status: labelled cells, warnings inverted. */
.cells { display: grid; gap: 0; margin: 0; }
.cells div { padding: 6px 8px; }
.cells dt { font-size: 12px; color: var(--ink-dim); }
.cells dd { margin: 0; font-size: 17px; font-weight: 800; }
.strip {
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); margin-top: 10px;
  border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; background: #F4F5F0;
}
.strip div + div { border-left: 1px solid var(--rule); }
.cells .warn { background: var(--ink); }
.cells .warn dt { color: var(--casing); }
.cells .warn dd { color: var(--housing); }

/* Keys: raised, big, thumb reach. */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.keypad #burst { grid-column: 3; }  /* row 1: SF, attenuation, Burst; row 2: Sweep, Stop, Sleep */
.key {
  font: inherit; font-weight: 800; color: #fff; background: var(--key); border: 0; border-radius: 10px;
  min-height: 56px; padding: 10px 14px; box-shadow: 0 4px 0 #1E2220; cursor: pointer;
}
.key:active { transform: translateY(3px); box-shadow: 0 1px 0 #1E2220; }
.key.primary { background: var(--housing); color: var(--ink); box-shadow: 0 4px 0 #8C7000; font-size: 20px; }
.key:disabled { background: #C7CBC3; color: #6B716C; box-shadow: none; transform: none; cursor: default; }
.key.select { display: flex; align-items: center; gap: 8px; }
.key select {
  flex: 1; min-width: 0; font: inherit; font-size: 20px; font-weight: 900; color: #fff;
  background: transparent; border: 0; padding: 0;
}
.key select option { color: var(--ink); }
.key select:disabled { color: #6B716C; }
#connect { width: 100%; margin-top: 16px; }
.note { color: var(--alarm); font-weight: 700; margin: 10px 0 0; }

.ack { min-height: 1.4em; margin: 10px 0 0; font-weight: 700; }
.ack.ok { color: var(--ink); } .ack.ok::before { content: "✓ "; }
.ack.err { color: var(--alarm); } .ack.err::before { content: "✕ "; }

.banner {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px;
  padding: 8px 8px 8px 12px; background: var(--alarm); color: #fff; font-weight: 800; border-radius: 6px;
}
.banner .key { min-height: 44px; background: #fff; color: var(--alarm); box-shadow: none; }
.banner p { margin: 0; }
.banner small { display: block; font-weight: 600; font-size: 12px; opacity: .85; }
.banner small:empty { display: none; }

/* Frames: one row per test frame, tap for the gateway list. */
.frame { border-bottom: 1px solid var(--rule); }
.frame summary {
  display: grid; grid-template-columns: 2em minmax(32px, 1fr) 4.2em 3.3em 7.6em; white-space: nowrap;  /* fixed: bars share one scale */ align-items: center; gap: 8px;
  min-height: 44px; cursor: pointer; list-style: none; font-size: 15px;
}
.frame summary::-webkit-details-marker { display: none; }
.frame .n { font-weight: 800; }
.frame .m { font-weight: 800; text-align: right; }
.frame .g, .frame .d { text-align: right; color: var(--ink-dim); }
.frame.miss .d { color: var(--alarm); font-weight: 700; }
.frame[open] summary { border-bottom: 1px dashed var(--rule); }
.muted { color: var(--ink-dim); }

.panel { background: #F4F5F0; border: 2px solid var(--ink); border-radius: 6px; padding: 4px; }
.live { margin: 4px 8px 0; font-size: 13px; font-weight: 800; color: var(--ink); }
.live::before { content: "\25CF  "; color: var(--alarm); }
.panel .cells { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { font-size: 12px; font-weight: 600; color: var(--ink-dim); text-align: right; padding: 6px 8px 2px; }
td { padding: 6px 8px; text-align: right; border-top: 1px solid var(--rule); }
th:first-child, td:first-child { text-align: left; font-weight: 700; }
.barcell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.barcell .bar { flex: 1; max-width: 120px; }

dialog { border: 3px solid var(--ink); border-radius: 8px; background: var(--casing); color: var(--ink); padding: 20px; max-width: 340px; }
dialog::backdrop { background: rgba(20, 32, 26, .55); }
dialog p { margin: 0; font-size: 18px; font-weight: 700; }
dialog form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }

@media (max-width: 380px) {
  .reading .value { font-size: 72px; }
  .frame summary { grid-template-columns: 2em 1fr 4.4em 3.2em; }
  .frame .d { grid-column: 2 / -1; text-align: left; margin-top: -8px; padding-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) { .key:active { transform: none; } }
.diag-log { white-space: pre-wrap; word-break: break-word; font-size: 13px; background: var(--glass); border: 2px solid var(--ink); border-radius: 6px; padding: 8px; }
#diag .key { width: 100%; margin: 12px 0; }
