:root {
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
  --stage: #101013;
  --chrome: #f8f8fa;
  --sheet: #fcfcfe;
  --well: #eeeef3;
  --text: #1c1c22;
  --secondary: #575761;
  --separator: #dddde4;
  --accent: #005fc7;
  --accent-fill: #0064d5;
  --accent-tint: #e8f1ff;
  --accent-pressed: #d7e7ff;
  --live: #1a7950;
  color: var(--text);
  background: var(--stage);
}

@media (prefers-color-scheme: dark) {
  :root {
    --chrome: #1c1c20;
    --sheet: #242428;
    --well: #333338;
    --text: #f4f4f6;
    --secondary: #b1b1bb;
    --separator: #3c3c43;
    --accent: #86bdff;
    --accent-tint: #20334c;
    --accent-pressed: #2b4565;
    --live: #6bce9a;
  }
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
.symbols, [hidden] { display: none !important; }

svg {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.play { fill: currentColor; stroke: none; }

button {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { cursor: default; }
button:focus-visible, #full-address:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.layout {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.toolbar {
  flex: none;
  padding: calc(2px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 2px max(10px, env(safe-area-inset-left));
  background: var(--chrome);
  border-bottom: 1px solid var(--separator);
}

.toolbar-inner {
  width: min(100%, 960px);
  min-height: 44px;
  margin-inline: auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

#refresh {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  place-items: center;
  justify-self: start;
  min-height: 44px;
  border-radius: 10px;
  color: var(--accent);
  font-size: .8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.refresh-content {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding-inline: 8px;
  border-radius: 8px;
  background: var(--accent-tint);
}

.refresh-content svg { font-size: 15px; }
.refresh-label { display: none; }
#refresh:disabled { opacity: .5; }
#refresh:active:not(:disabled) .refresh-content { background: var(--accent-pressed); }

#quality {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

.quality-icon {
  display: none;
  flex: none;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-tint);
  color: var(--accent);
}

.quality-copy { min-width: 0; }
.quality-label {
  display: block;
  color: var(--secondary);
  font-size: .75rem;
  font-weight: 500;
  line-height: 1.3;
}

.source {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  max-width: 100%;
  text-align: start;
  color: var(--accent);
  font-size: .75rem;
  line-height: 1.25;
}

.source span { flex: none; }
.source b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  font-weight: 500;
}

.source svg { font-size: 11px; }
.source:disabled { color: var(--secondary); }
.source:disabled svg { visibility: hidden; }
.source:active:not(:disabled) { text-decoration: underline; }

.icon-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  min-height: 44px;
  border-radius: 10px;
  color: var(--secondary);
}

#hide-quality { width: 32px; }
.icon-button svg {
  width: 19px;
  height: 19px;
  padding: 2px;
  border-radius: 50%;
  background: var(--well);
}
.icon-button:active svg { background: var(--separator); }

.network {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-inline: 8px 2px;
  border-inline-start: 1px solid var(--separator);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#quality[hidden] ~ .network { border-inline-start: 0; }
.network svg { color: var(--secondary); font-size: 15px; }
.network[data-live="true"] svg { color: var(--live); }
.network-copy { display: grid; line-height: 1.2; }
#node {
  max-width: 8ch;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .75rem;
  font-weight: 650;
}
#latency { color: var(--secondary); font-size: .6875rem; }

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#screen {
  position: absolute;
  inset: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  --frame-w: 9;
  --frame-h: 16;
}

#screen.wide { --frame-w: 16; --frame-h: 9; }
#screen iframe {
  display: block;
  width: min(100%, calc(100cqh * var(--frame-w) / var(--frame-h)));
  max-height: 100%;
  aspect-ratio: var(--frame-w) / var(--frame-h);
  border: 0;
  background: #000;
}

.status {
  position: relative;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  width: min(320px, calc(100% - 24px));
  max-height: 100%;
  overflow: auto;
  padding: 14px;
  border: 1px solid #ffffff19;
  border-radius: 16px;
  background: #242428;
  box-shadow: 0 6px 22px #0004;
  color: #f4f4f6;
}

.status[data-loading="true"] { pointer-events: none; }
.status-icon {
  position: relative;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #253955;
  color: #95c6ff;
  font-size: 22px;
}

.status[data-loading="true"] .status-icon::after {
  content: "";
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 10px;
  height: 10px;
  border: 2px solid #526783;
  border-top-color: #b9d8ff;
  border-radius: 50%;
  background: #242428;
  animation: spin .9s linear infinite;
}

h1, h2 { margin: 0; font-weight: 650; line-height: 1.3; }
h1 { font-size: 1rem; }
h2 { font-size: 1.0625rem; }
.status p { margin: 4px 0 0; color: #c2c2cb; font-size: .8125rem; line-height: 1.45; }

.primary {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  background: var(--accent-fill);
  color: #fff;
  font-size: .875rem;
  font-weight: 650;
}

.primary:active { background: #0051ad; }
#action { grid-column: 2; justify-self: start; }

dialog {
  width: min(440px, calc(100% - 24px));
  max-height: 85vh;
  max-height: 85dvh;
  padding: 12px 16px 16px;
  overflow: auto;
  border: 1px solid var(--separator);
  border-radius: 22px;
  background: var(--sheet);
  box-shadow: 0 12px 40px #0004;
  color: var(--text);
}

dialog::backdrop { background: #0008; }
.sheet-heading { display: flex; align-items: center; justify-content: space-between; }
#full-address {
  max-height: 36vh;
  padding: 12px;
  overflow: auto;
  overflow-wrap: anywhere;
  user-select: all;
  border-radius: 10px;
  background: var(--well);
  font-size: .875rem;
  line-height: 1.5;
}

dialog .primary { width: 100%; margin-top: 12px; }
#copy-result { margin: 8px 0 0; color: var(--secondary); font-size: .8125rem; }

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

@media (min-width: 375px) {
  .refresh-label { display: inline; }
}

@media (min-width: 640px) {
  .toolbar-inner { grid-template-columns: 1fr minmax(0, 360px) 1fr; }
  #quality { justify-self: center; gap: 8px; max-width: 100%; }
  .quality-icon { display: grid; }
  .source b { max-width: 22ch; }
  .network { border-inline-start: 0; }
  .network-copy { display: flex; align-items: baseline; gap: 8px; }
}

@media (max-width: 539px) {
  dialog {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    padding: 12px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    border-radius: 22px 22px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status[data-loading="true"] .status-icon::after { animation: none; }
}
