:root {
  color-scheme: light dark;
  --bg: #fcfcff;
  --text: #262c39;
  --muted: #717a90;
  --surface: #ffffff;
  --surface-muted: #f6f7fb;
  --surface-strong: #eef1f7;
  --line: #e8ebf3;
  --line-strong: #d7dce8;
  --accent: #8b5cf6;
  --accent-hover: #7a4ee4;
  --accent-soft: #ece8f8;
  --accent-focus: #8b5cf6;
  --accent-text: #ffffff;
  --danger: #a54064;
  --shadow: 0 18px 44px rgba(91, 57, 178, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f1a;
    --text: #f5f6ff;
    --muted: #919ab8;
    --surface: #131a30;
    --surface-muted: #0d1220;
    --surface-strong: #11172b;
    --line: #202944;
    --line-strong: #2a3450;
    --accent: #b78cf8;
    --accent-hover: #c8a8ff;
    --accent-soft: #161d35;
    --accent-focus: #c9a8ff;
    --accent-text: #140f24;
    --danger: #f59a4a;
    --shadow: 0 20px 52px rgba(0, 0, 0, 0.32);
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--surface-muted), var(--accent) 4%),
      var(--bg)
    ),
    var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 18px;
}

.url {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: min(100%, 980px);
  justify-self: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  box-shadow: var(--shadow);
}

.url-label {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.url-input {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.url-input::placeholder {
  color: color-mix(in srgb, var(--muted), transparent 24%);
}

.url-input:focus-visible {
  border-color: var(--accent-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 74%);
}

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn-primary {
  min-width: 82px;
  height: 42px;
  padding: 0 18px;
  background: var(--accent);
  color: var(--accent-text);
  border-color: color-mix(in srgb, var(--accent), black 10%);
}

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

.btn-secondary {
  min-width: 68px;
  padding: 0 10px;
  background: transparent;
  color: inherit;
  border-color: var(--line-strong);
}

.btn-secondary:hover {
  background: var(--accent-soft);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-focus);
  outline-offset: 2px;
}

.btn.is-disabled {
  color: var(--muted);
  pointer-events: none;
}

.previews {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.preview {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--text);
  box-shadow: var(--shadow);
}

.preview-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
}

.preview-header > div:first-child {
  min-width: 0;
}

.preview-label,
.preview-title {
  margin: 0;
}

.preview-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.preview-label::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
}

.preview-title {
  max-width: min(46vw, 560px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(1rem, 1rem + 0.2rem, 1.2rem);
  font-weight: 800;
  letter-spacing: 0;
}

.preview-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.frame {
  min-height: 0;
  background: var(--surface);
}

iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  background: canvas;
}

.preview-light iframe {
  color-scheme: light;
}

.preview-dark iframe {
  color-scheme: dark;
}

.status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.status[data-tone="error"] {
  color: var(--danger);
}

@media (max-width: 820px) {
  .app {
    padding: 12px;
  }

  .url {
    grid-template-columns: 1fr auto;
  }

  .url-label {
    grid-column: 1 / -1;
  }

  .previews {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(58vh, 1fr);
  }

  .preview-title {
    max-width: calc(100vw - 190px);
  }
}

@media (max-width: 480px) {
  .preview-header {
    align-items: stretch;
    flex-direction: column;
  }

  .preview-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .btn-secondary {
    width: 100%;
  }

  .preview-title {
    max-width: 100%;
  }
}
