:root {
  color-scheme: dark;
  --bg: #121214;
  --surface: #1c1c20;
  --surface-elevated: #232328;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f5f5f7;
  --secondary: #a1a1aa;
  --muted: #6e6e77;
  --accent: #fa243c;
  --accent-hover: #ff3b52;
  --accent-soft: rgba(250, 36, 60, 0.14);
  --on-accent: #ffffff;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-press: rgba(255, 255, 255, 0.1);
  --success: #34c759;
  --warning: #f5b942;
  --danger: #ff5b52;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

/* Author display rules (.page, .tabs, .ghost, .panel--center, ...) would
   otherwise override the browser's [hidden] rule and leave hidden panels
   visible. */
[hidden] {
  display: none !important;
}

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

body {
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(250, 36, 60, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-elevated);
  color: var(--secondary);
  font-size: 0.9em;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.02em;
}

h1 {
  font-size: 28px;
}

h2 {
  margin-bottom: 10px;
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

p {
  margin: 0;
}

.muted {
  color: var(--secondary);
}

.optional {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.eyebrow {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Top bar */

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 56px;
  padding: 0 clamp(18px, 3.6vw, 32px);
  border-bottom: 1px solid var(--line);
  background: var(--bar, rgba(24, 24, 28, 0.82));
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: none;
  place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand-mark--logo {
  background: transparent;
}

.brand-mark--logo img {
  display: block;
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.brand strong {
  display: block;
  font-size: 14px;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--secondary);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.tab:hover {
  background: var(--surface);
  color: var(--text);
}

.tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* Layout */

main {
  width: min(1080px, 100% - 40px);
  margin: 0 auto;
  padding: 24px 0 56px;
}

.page {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}

.panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel h2 {
  margin-bottom: 6px;
}

.panel > .muted {
  margin-bottom: 16px;
}

.panel--center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 64px 24px;
  text-align: center;
}

.panel--auth {
  max-width: 420px;
  margin: 40px auto;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

/* Forms */

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

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--secondary);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input:not([type]),
select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 400;
  outline: none;
  transition: border-color 140ms ease, background-color 140ms ease;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder {
  color: var(--muted);
}

.row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 12px;
}

.row--even {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

button {
  font: inherit;
}

.primary,
.ghost,
.danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 17px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

.primary {
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
}

.primary:hover {
  background: var(--accent-hover);
}

.ghost {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

.ghost:hover {
  background: var(--surface-elevated);
  border-color: var(--muted);
}

.danger {
  border: 1px solid rgba(250, 36, 60, 0.4);
  background: rgba(250, 36, 60, 0.12);
  color: #ff8a97;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

/* Pills and status */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pill--muted {
  background: var(--surface-elevated);
  color: var(--secondary);
}

.pill--ok {
  background: rgba(52, 199, 89, 0.14);
  color: var(--success);
}

.pill--warn {
  background: rgba(245, 185, 66, 0.14);
  color: var(--warning);
}

.pill--error {
  background: var(--accent-soft);
  color: var(--accent);
}

.error {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: #ff8a97;
  font-size: 12.5px;
  line-height: 1.45;
}

.notice {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(52, 199, 89, 0.1);
  color: var(--success);
  font-size: 12.5px;
  line-height: 1.45;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--surface-elevated);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Overview cards */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.card-label {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.card strong {
  font-size: 22px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.card small {
  color: var(--secondary);
  font-size: 12px;
}

/* Charts */

.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chart-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.chart-card--wide {
  grid-column: 1 / -1;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.chart-head h3 {
  font-size: 13px;
  color: var(--secondary);
  font-weight: 600;
}

.chart-head span {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

canvas {
  display: block;
  width: 100%;
  height: 120px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.details {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 12px 0 0;
}

.details div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.details div:first-child {
  border-top: 0;
}

.details dt {
  color: var(--secondary);
  font-size: 12.5px;
}

.details dd {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Network setup */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  color: var(--secondary);
  font-weight: 400;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.mode-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.mode-card strong {
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
}

.mode-card span {
  font-size: 12px;
  line-height: 1.4;
}

.mode-card:hover {
  border-color: var(--line-strong);
  background: var(--surface-elevated);
}

.mode-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tunnel-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--bg);
}

.provider-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tunnel-status {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.tunnel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.current-setup {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.address-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.address-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.address-list .tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-elevated);
  color: var(--muted);
  font-family: inherit;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Console */

.console-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 12px;
}

.terminal {
  min-height: 360px;
  max-height: 56vh;
  margin: 10px 0 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0c0c0e;
  color: #c9c9d1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.terminal--short {
  min-height: 160px;
  max-height: 30vh;
}

.terminal .error {
  color: #ff8a97;
}

.command-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.command-form .prompt {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
}

.command-form input {
  flex: 1;
  height: 40px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

/* Responsive */

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 18px;
    gap: 12px;
  }

  .brand {
    min-width: 0;
  }

  .topbar-actions {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }

  .tabs {
    order: 2;
  }

  .charts,
  .console-grid,
  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .mode-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 560px) {
  main {
    width: min(100%, 100% - 24px);
    padding-top: 18px;
  }

  .row {
    grid-template-columns: minmax(0, 1fr);
  }
}
