:root {
  color-scheme: light;
  --bg: #f3f6f6;
  --card: #e7eeee;
  --text: #122022;
  --muted: #4d6264;
  --primary: #0f6e78;
  --on-primary: #f4fffe;
  --danger: #8c2f2f;
  --danger-bg: #f8d9d4;
  --line: #c5d5d6;
  --focus: #0f6e78;
  --shadow: 0 16px 40px rgb(15 40 44 / 8%);
  font-family: "Segoe UI", "Manrope", "Noto Sans", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1516;
  --card: #243031;
  --text: #e7f1f1;
  --muted: #b7c9ca;
  --primary: #8ed4d8;
  --on-primary: #042326;
  --danger: #ffb4ab;
  --danger-bg: #5c221d;
  --line: #355053;
  --focus: #b7ebf0;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    color-scheme: dark;
    --bg: #0e1516;
    --card: #243031;
    --text: #e7f1f1;
    --muted: #b7c9ca;
    --primary: #8ed4d8;
    --on-primary: #042326;
    --danger: #ffb4ab;
    --danger-bg: #5c221d;
    --line: #355053;
    --focus: #b7ebf0;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 320px at 10% -10%, color-mix(in srgb, var(--primary) 28%, transparent), transparent 70%),
    var(--bg);
  color: var(--text);
}
button, input, textarea, a { font: inherit; color: inherit; }
button, a.button, .segment {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid transparent;
  cursor: pointer;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
.top, .install, .layout, .settings-wrap { width: min(1120px, calc(100% - 32px)); margin-inline: auto; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: end;
  padding: 28px 0 8px;
}
h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.2rem); letter-spacing: -0.04em; }
h2 { margin: 0 0 6px; font-size: 1.3rem; }
.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.icon-button, .text-button {
  background: transparent;
  min-width: 48px;
}
.icon-button { font-size: 1.4rem; }
.install, .card {
  background: color-mix(in srgb, var(--card) 92%, white 0%);
  border-radius: 28px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.install {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin: 12px auto 18px;
}
.install-actions, .dialog-actions, .split { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.layout {
  display: grid;
  gap: 16px;
  padding-bottom: 40px;
  grid-template-areas: "ip" "speed" "router" "history";
}
#ip-card { grid-area: ip; }
.speed-card { grid-area: speed; }
#router-card { grid-area: router; }
#history-card { grid-area: history; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ip { font-family: ui-monospace, "Cascadia Code", monospace; font-size: clamp(1.6rem, 3vw, 2.4rem); margin: 8px 0; }
.place { font-size: 1.2rem; margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.ok { color: var(--primary); }
.mono { font-family: ui-monospace, monospace; overflow-wrap: anywhere; }
.primary, a.button {
  background: var(--primary);
  color: var(--on-primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
}
.secondary, #dialog-cancel, .segment {
  background: transparent;
  border-color: var(--line);
  padding: 0 16px;
}
.danger { background: var(--danger-bg); color: var(--danger); padding: 0 18px; }
.segmented { display: flex; gap: 8px; margin: 12px 0; }
.segment { flex: 1; }
.segment[aria-checked="true"] { background: var(--primary); color: var(--on-primary); border-color: transparent; }
label { display: grid; gap: 6px; margin: 10px 0; font-weight: 600; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 500;
}
.gauge-wrap { position: relative; height: 260px; }
canvas { width: 100%; height: 100%; }
.gauge-readout {
  position: absolute;
  inset: 18% 10% 8%;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  pointer-events: none;
}
#gauge-value { margin: 0; font-size: clamp(2.4rem, 6vw, 4rem); letter-spacing: -0.04em; }
#gauge-unit, #gauge-caption { margin: 0; color: var(--muted); }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 14px; }
.metrics div { background: color-mix(in srgb, var(--bg) 65%, transparent); border-radius: 16px; padding: 12px; }
.metrics span, .metrics small { display: block; color: var(--muted); }
.metrics strong { font-size: 1.4rem; }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 12px; }
.progress span { display: block; height: 100%; width: 20%; background: var(--primary); animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 50% { width: 85%; } }
#start-test, #reboot, #lock-submit, #ssh-form .primary { width: 100%; }
.screen {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 92%, black 8%);
  overflow: auto;
  padding: 24px 0 48px;
}
.settings-wrap { display: grid; gap: 16px; }
dialog {
  border: 0;
  border-radius: 24px;
  padding: 22px;
  background: var(--card);
  color: var(--text);
  width: min(460px, calc(100% - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.split label { flex: 1; }
#ssh-password-label, #ssh-key-label, #ssh-passphrase-label { margin-top: 0; }

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 0.9fr 1.15fr;
    grid-template-areas:
      "ip speed"
      "router speed"
      "history speed";
    align-items: start;
  }
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .gauge-wrap { height: 320px; }
}

@media (min-width: 1200px) {
  body { font-size: 1.12rem; }
  button, .segment, input, textarea { min-height: 56px; }
  .gauge-wrap { height: 360px; }
}
