/* Theme variables */
:root[data-theme="dark"] {
  --re-surface: #0b1220;
  --re-panel: #111827;
  --re-text: #f8fafc;
  --re-muted: #cbd5e1;
  --re-border: #334155;
  --re-device: #111827;
  --re-device-border: #202938;
  --re-overlay: rgba(2, 6, 23, 0.7);
  --re-spinner-base: rgba(255, 255, 255, 0.15);
  --re-spinner-top: #ffffff;
  --re-resizer: rgba(148, 163, 184, 0.7);
  --re-primary: #8e44ad;
  --re-primary-border: #7c3aa0;
  --re-badge-bg: rgba(142, 68, 173, 0.15);
  --re-badge-text: #e9d5ff;
  --re-fit-off: #475569;
  --re-fit-on: #27ae60;
  --re-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --re-surface: #ffffff;
  --re-panel: #f8fafc;
  --re-text: #0b1220;
  --re-muted: #475569;
  --re-border: #e2e8f0;
  --re-device: #ffffff;
  --re-device-border: #cbd5e1;
  --re-overlay: rgba(148, 163, 184, 0.35);
  --re-spinner-base: rgba(0, 0, 0, 0.15);
  --re-spinner-top: #334155;
  --re-resizer: rgba(100, 116, 139, 0.7);
  --re-primary: #8e44ad;
  --re-primary-border: #7c3aa0;
  --re-badge-bg: rgba(142, 68, 173, 0.12);
  --re-badge-text: #6b21a8;
  --re-fit-off: #94a3b8;
  --re-fit-on: #16a34a;
  --re-shadow: 0 10px 30px rgba(2, 6, 23, 0.12);
}

.re-page {
  max-width: 1200px;
  margin: 0 auto;
  margin-top: 100px;
  margin-bottom: 100px;
  padding: 20px;
  font-family: "Noto Sans", system-ui, -apple-system, Segoe UI, Roboto,
    Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

.re-header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 12px;
}

.re-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.re-title .re-badge {
  background: var(--re-badge-bg);
  color: var(--re-badge-text);
  border: 1px solid var(--re-primary-border);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.re-toolbar {
  background: var(--re-panel);
  border: 1px solid var(--re-border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
}

.re-url-rrrow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  align-items: center;
}

.re-url-input {
  width: 100%;
  display: flex;
  gap: 8px;
  align-items: center;
}

.re-url-input input[type="text"] {
  flex: 1;
  height: 42px;
  background: var(--re-surface);
  color: var(--re-text);
  border: 1px solid var(--re-border);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
  box-sizing: border-box;
}

.re-url-input input[type="text"]:focus {
  border-color: var(--re-fit-on);
  box-shadow: 0 0 0 3px rgba(39, 174, 96, 0.25);
}

.rebtn {
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--re-border);
  border-radius: 8px;
  background: var(--re-surface);
  color: var(--re-text);
  cursor: pointer;
  box-sizing: border-box;
}

.rebtn.reprimary {
  background: var(--re-primary);
  border-color: var(--re-primary-border);
}

.rebtn:hover {
  filter: brightness(1.08);
}

.rrrow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: 100%;
}
.rrrow > * {
  min-width: 0;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 6px;
  background: var(--re-surface);
  border: 1px solid var(--re-border);
  border-radius: 8px;
  padding: 6px;
  flex: 1 1 320px;
  min-width: 260px;
  box-sizing: border-box;
}

.segmented .seg {
  background: transparent;
  border: 0;
  color: var(--re-muted);
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  min-width: 80px;
}

.segmented .seg.reactive {
  background: var(--re-primary);
  color: #ffffff;
}

.re-select {
  height: 42px;
  background: var(--re-surface);
  border: 1px solid var(--re-border);
  color: var(--re-text);
  border-radius: 8px;
  padding: 0 12px;
  flex: 0 1 240px;
  min-width: 200px;
  box-sizing: border-box;
}

.scale {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--re-muted);
  min-width: 220px;
  flex: 1 1 280px;
}

.scale input[type="range"] {
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
}

.reactions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.rebtn {
  min-width: 44px;
}

.viewport-shell {
  margin-top: 12px;
  background: var(--re-surface);
  border: 1px solid var(--re-border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  box-sizing: border-box;
}

.device-frame {
  position: relative;
  width: 375px;
  height: 812px;
  background: var(--re-device);
  border: 1px solid var(--re-device-border);
  border-radius: 16px;
  box-shadow: var(--re-shadow);
  overflow: hidden;
  transform-origin: top center;
  margin: 0 auto;
  box-sizing: border-box;
}

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--re-muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.device-header .retag {
  padding: 6px 10px;
  border: 1px dashed var(--re-border);
  border-radius: 8px;
}

.resizer {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 16px;
  height: 16px;
  border-bottom: 3px solid var(--re-resizer);
  border-right: 3px solid var(--re-resizer);
  cursor: nwse-resize;
  z-index: 3;
}

iframe#viewport {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--re-surface);
}

.reloading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--re-overlay);
  z-index: 2;
}

.reloading.show {
  display: flex;
}

.reloading .spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--re-spinner-base);
  border-top-color: var(--re-spinner-top);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.re-hint {
  color: #cbd5e1;
  font-size: 12px;
  margin-top: 8px;
}

@media (max-width: 1180px) {
  .segmented {
    flex: 1 1 100%;
  }
  .re-select {
    flex: 1 1 260px;
  }
  .scale {
    flex: 1 1 100%;
  }
  .reactions {
    justify-content: flex-start;
  }
}

@media (max-width: 820px) {
  .rrrow {
    flex-direction: column;
  }
  .re-url-rrrow {
    flex-direction: column;
  }
  .segmented {
    width: 100%;
    grid-auto-flow: rrrow;
  }
  .scale {
    width: 100%;
  }
  .reactions {
    justify-content: flex-start;
  }
}

/* Small-phone optimizations */
@media (max-width: 420px) {
  .re-header {
    gap: 6px;
  }
  .re-title span {
    font-size: 18px !important;
  }
  .re-title .re-badge {
    display: none;
  }

  .rebtn {
    padding: 0 10px;
    height: 38px;
  }
  .re-select {
    height: 38px;
    min-width: 0;
    flex: 1 1 100%;
  }
  .re-url-input input[type="text"] {
    height: 38px;
  }

  .segmented {
    gap: 4px;
    padding: 4px;
  }
  .segmented .seg {
    padding: 6px 8px;
    min-width: 0;
  }

  .scale {
    gap: 6px;
  }
  .scale .scale-label {
    display: none;
  }
  #scaleValue {
    width: 44px;
    text-align: right;
  }

  .reactions {
    gap: 6px;
  }
}

/* Compact Auto-Fit indicator */
#fitButton {
  position: relative;
  white-space: nowrap;
}
#fitButton::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--re-fit-off);
  margin-left: 8px;
  vertical-align: middle;
}
#fitButton[aria-pressed="true"]::after {
  background: var(--re-fit-on);
}
/* Mobile width warning modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--re-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-overlay.show {
  display: flex;
}
.modal-card {
  background: var(--re-panel);
  color: var(--re-text);
  border: 1px solid var(--re-border);
  border-radius: 12px;
  max-width: 520px;
  width: 100%;
  padding: 18px;
  box-shadow: var(--re-shadow);
  position: relative;
  box-sizing: border-box;
}
.modal-card h3 {
  margin: 0 0 8px 0;
  font-size: 18px;
}
.modal-card p {
  margin: 0 0 14px 0;
  color: var(--re-muted);
  line-height: 1.5;
}
.modal-reactions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.rebtn.ghost {
  background: transparent;
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--re-border);
  background: var(--re-surface);
  color: var(--re-text);
  cursor: pointer;
  box-sizing: border-box;
}
