:root {
  --bg: #08110e;
  --bg-soft: #0c1713;
  --panel: #0e1b16;
  --panel-deep: #081310;
  --paper: #ebe5d5;
  --paper-2: #e2dac7;
  --paper-edge: #b8ae98;
  --ink: #17211c;
  --ink-soft: #5c675f;
  --cream: #ece8da;
  --muted: #84958b;
  --line: rgba(236, 232, 218, 0.11);
  --amber: #f0b429;
  --amber-dim: #c99425;
  --amber-wash: rgba(240, 180, 41, 0.12);
  --sage: #8fb8a2;
  --red: #d4553d;
  --red-soft: #e2a08f;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Hiragino Sans GB", sans-serif;
  --serif: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  --mono: "SFMono-Regular", "Cascadia Mono", "Consolas", "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(900px 480px at 12% -8%, rgba(240, 180, 41, 0.06), transparent 65%),
    radial-gradient(800px 500px at 92% 0%, rgba(143, 184, 162, 0.05), transparent 60%),
    var(--bg);
  color: var(--cream);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(236, 232, 218, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(236, 232, 218, 0.028) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse at 50% 20%, black, transparent 78%);
}

.app {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
  padding: 34px clamp(16px, 4vw, 48px) 34px;
}

/* ------------------------------------------------------------------ header */
.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  color: var(--amber);
  flex: none;
}

.brand-copy h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.7rem, 3vw, 2.35rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.1;
}

.brand-copy p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.net-readout {
  display: flex;
  gap: clamp(16px, 3vw, 34px);
  margin: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.net-readout div { min-width: 0; }

.net-readout dt {
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  margin-bottom: 4px;
}

.net-readout dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--cream);
  white-space: nowrap;
}

.link-state { color: var(--muted); }

.link-state::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 7px;
  vertical-align: 1px;
}

.link-state.is-on { color: var(--sage); }
.link-state.is-off { color: var(--red-soft); }

/* ----------------------------------------------------------------- console */
.console {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  gap: clamp(20px, 3vw, 36px);
  align-items: start;
  margin-top: 30px;
}

/* ------------------------------------------------------------------- phone */
.phone {
  position: relative;
  background: linear-gradient(176deg, var(--paper) 0%, var(--paper-2) 100%);
  color: var(--ink);
  border-radius: 34px 34px 14px 14px;
  padding: 0 26px 22px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 2px 0 rgba(255, 255, 255, 0.2),
    0 24px 46px rgba(0, 0, 0, 0.42),
    0 5px 0 var(--paper-edge);
}

.speaker-grille {
  height: 40px;
  margin: 0 -26px 12px;
  border-radius: 34px 34px 0 0;
  background-image: radial-gradient(circle, rgba(23, 33, 28, 0.36) 1.1px, transparent 1.5px);
  background-size: 8px 8px;
  background-position: center 10px;
  background-repeat: repeat;
  opacity: 0.7;
  mask-image: linear-gradient(90deg, transparent, black 22%, black 78%, transparent);
}

.phone-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 2px 14px;
}

.line-led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #b7ae99;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.35);
  flex: none;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.line-led.is-dialing {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(240, 180, 41, 0.18), 0 0 12px rgba(240, 180, 41, 0.75);
  animation: led-pulse 1.4s ease-in-out infinite;
}

.line-led.is-live {
  background: #3e7a5d;
  box-shadow: 0 0 0 4px rgba(62, 122, 93, 0.16), 0 0 10px rgba(62, 122, 93, 0.5);
}

.line-led.is-error {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(212, 85, 61, 0.14);
}

@keyframes led-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.line-label {
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.call-timer {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 1.02rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.number-display {
  position: relative;
  display: block;
  padding: 17px 18px 15px;
  border-radius: 12px;
  background: #14201a;
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.55),
    inset 0 -1px 0 rgba(255, 255, 255, 0.06);
}

.number-display input {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: #f1c86a;
  caret-color: var(--amber);
  font-family: var(--mono);
  font-size: clamp(1.9rem, 4.6vw, 2.5rem);
  letter-spacing: 0.1em;
  text-align: right;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.display-caption {
  display: block;
  margin-top: 2px;
  text-align: right;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  color: rgba(241, 200, 106, 0.5);
}

.mic-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 11px 2px 0;
  flex-wrap: wrap;
}

.mic-label {
  flex: none;
  color: var(--ink-soft);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}

.mic-select {
  flex: 1 1 120px;
  min-width: 0;
  max-width: 215px;
  padding: 5px 6px;
  border: 1px solid rgba(23, 33, 28, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.35);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.7rem;
  outline: none;
}

.mic-select:focus-visible {
  outline: 2px solid #1f6f5c;
  outline-offset: 1px;
}

.mic-test {
  flex: none;
  border: 0;
  padding: 3px 1px;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.7rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.mic-test:hover:not(:disabled) { color: var(--ink); }
.mic-test:disabled { opacity: 0.4; cursor: not-allowed; }

.mic-meter {
  flex: none;
  display: block;
  width: 46px;
  height: 5px;
  border-radius: 3px;
  background: rgba(23, 33, 28, 0.13);
  overflow: hidden;
}

.mic-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 3px;
  background: #4a8a68;
  transition: width 80ms linear, background 160ms ease;
}

.mic-meter span.is-hot { background: var(--amber-dim); }

.mic-status {
  flex: none;
  min-width: 32px;
  text-align: right;
  color: rgba(92, 103, 95, 0.72);
  font-size: 0.64rem;
  letter-spacing: 0.02em;
}

.mic-status.is-live { color: #2f6b4f; }
.mic-status.is-warn { color: #a34a2f; }

.mic-warning {
  margin: 7px 2px 0;
  padding: 5px 8px;
  border-left: 2px solid #9c3b2a;
  border-radius: 0 4px 4px 0;
  background: rgba(156, 59, 42, 0.08);
  color: #9c3b2a;
  font-size: 0.68rem;
  line-height: 1.45;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0 14px;
}

.key {
  justify-self: center;
  width: 74px;
  height: 74px;
  max-width: 100%;
  border-radius: 50%;
  border: 1px solid rgba(23, 33, 28, 0.16);
  background: linear-gradient(180deg, #f6f1e3 0%, #e8e0ce 100%);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 1.32rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow:
    0 3px 0 var(--paper-edge),
    0 5px 8px rgba(23, 33, 28, 0.1);
  transition: transform 60ms ease, box-shadow 60ms ease, background 120ms ease;
  touch-action: manipulation;
}

.key:hover:not(:disabled) { background: #fbf7ea; }

.key:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: 0 1px 0 var(--paper-edge);
  transform: translateY(2px);
}

.key:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--paper-edge), 0 2px 4px rgba(23, 33, 28, 0.12);
}

.key-aux {
  color: var(--ink-soft);
  font-size: 1.1rem;
  background: linear-gradient(180deg, #eee8d9 0%, #ded6c2 100%);
}

.phone-actions {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.dial-btn,
.hangup-btn {
  height: 52px;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 0.98rem;
  letter-spacing: 0.14em;
  cursor: pointer;
  transition: transform 80ms ease, background 160ms ease, box-shadow 160ms ease;
}

.dial-btn {
  border: 0;
  background: var(--ink);
  color: var(--cream);
  font-weight: 600;
  box-shadow: 0 3px 0 #000;
}

.dial-btn:hover:not(:disabled) { background: #223129; }

.dial-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #000;
}

.hangup-btn {
  border: 1px solid rgba(156, 59, 42, 0.45);
  background: transparent;
  color: #9c3b2a;
  font-weight: 600;
}

.hangup-btn:hover:not(:disabled) { background: rgba(156, 59, 42, 0.09); }

.dial-btn:disabled,
.hangup-btn:disabled,
.text-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.phone-foot {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  padding: 0 4px;
}

.text-btn {
  border: 0;
  padding: 4px 0;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  border-bottom: 1px solid transparent;
}

.text-btn:hover:not(:disabled) {
  color: var(--ink);
  border-bottom-color: currentColor;
}

.phone-foot .hint {
  margin-left: auto;
  font-size: 0.7rem;
  color: rgba(92, 103, 95, 0.72);
}

/* ----------------------------------------------------------------- monitor */
.monitor {
  position: relative;
  background: linear-gradient(180deg, #0f1d18 0%, #0a1511 100%);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: clamp(18px, 2.4vw, 26px);
  min-height: 680px;
}

.monitor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.monitor-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.38rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.chip-live {
  color: var(--amber);
  border-color: rgba(240, 180, 41, 0.42);
  background: var(--amber-wash);
}

.chip-idle { color: var(--muted); }

.scope-wrap {
  position: relative;
  margin-top: 16px;
  border: 1px solid rgba(236, 232, 218, 0.09);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel-deep);
}

#scope {
  display: block;
  width: 100%;
  height: 188px;
}

.scope-legend {
  position: absolute;
  left: 13px;
  right: 13px;
  bottom: 8px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.scope-legend span::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 2px;
  margin-right: 6px;
  vertical-align: 3px;
  background: currentColor;
}

.legend-near { color: var(--sage); }
.legend-far { color: var(--amber-dim); }

.readouts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 16px 0 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.readouts div {
  padding: 12px 14px 12px 0;
  border-right: 1px solid var(--line);
  min-width: 0;
}

.readouts div:last-child { border-right: 0; }

.readouts dt {
  color: var(--muted);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
}

.readouts dd {
  margin: 5px 0 0;
  font-family: var(--mono);
  font-size: 0.86rem;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.section-head h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.16em;
}

.mono-note {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.66rem;
  color: rgba(132, 149, 139, 0.7);
  word-break: break-all;
}

.log-block { margin-top: 18px; }

.event-log {
  list-style: none;
  height: 146px;
  margin: 10px 0 0;
  padding: 10px 12px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.75;
  scrollbar-width: thin;
  scrollbar-color: rgba(132, 149, 139, 0.35) transparent;
}

.event-log li {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 10px;
  color: var(--muted);
}

.event-log time { color: rgba(132, 149, 139, 0.5); }

.event-log li.is-live { color: var(--amber); }
.event-log li.is-ok { color: var(--sage); }
.event-log li.is-error { color: var(--red-soft); }

.recording-box {
  margin-top: 18px;
  padding: 15px 16px 13px;
  border: 1px solid rgba(240, 180, 41, 0.26);
  border-radius: 12px;
  background: rgba(240, 180, 41, 0.045);
}

.recording-box audio {
  width: 100%;
  height: 36px;
  margin-top: 10px;
  color-scheme: dark;
}

.download-link {
  color: var(--amber);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-decoration: none;
  border-bottom: 1px solid rgba(240, 180, 41, 0.4);
}

.download-link:hover { border-bottom-color: var(--amber); }

.history-block { margin-top: 20px; }

.history-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  border-top: 1px solid var(--line);
  max-height: 196px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(132, 149, 139, 0.35) transparent;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
}

.history-main {
  min-width: 0;
  font-size: 0.78rem;
}

.history-main strong {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--cream);
  letter-spacing: 0.04em;
}

.history-main span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-btn {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.68rem;
  padding: 4px 8px;
  cursor: pointer;
}

.mini-btn:hover {
  color: var(--amber);
  border-color: rgba(240, 180, 41, 0.4);
}

.history-empty {
  padding: 16px 2px;
  color: var(--muted);
  font-size: 0.74rem;
}

.error-bar {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--red);
  border-radius: 0 8px 8px 0;
  background: rgba(212, 85, 61, 0.1);
  color: var(--red-soft);
  font-size: 0.78rem;
}

/* ------------------------------------------------------------------ footer */
.footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 30px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  color: rgba(236, 232, 218, 0.32);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}

/* ------------------------------------------------------------------- focus */
:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.phone :focus-visible {
  outline: 2px solid #1f6f5c;
  outline-offset: 2px;
}

[hidden] { display: none !important; }

/* --------------------------------------------------------------- responsive */
@media (max-width: 940px) {
  .console { grid-template-columns: minmax(0, 460px); justify-content: center; }
  .monitor { min-height: 0; }
  .masthead { align-items: flex-start; }
}

@media (max-width: 620px) {
  .app { padding-top: 22px; }
  .masthead { flex-direction: column; align-items: stretch; gap: 18px; }
  .net-readout { justify-content: flex-start; gap: 18px; }
  .phone { padding: 0 18px 18px; border-radius: 28px 28px 12px 12px; }
  .speaker-grille { margin: 0 -18px 10px; }
  .key { width: 62px; height: 62px; font-size: 1.15rem; }
  .readouts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .readouts div:nth-child(2) { border-right: 0; }
  .readouts div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  #scope { height: 152px; }
  .footer { flex-direction: column; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .line-led.is-dialing { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
