/* =========================================================
   WebPreview Pro — style.css  (v4 redesign)
   Mobile-first. Laptop layout kicks in at 1024px.
   ========================================================= */

/* ---------- Tokens ---------- */
:root {
  --bg: #060912;
  --panel: rgba(15, 21, 38, 0.72);
  --panel-solid: #0e1424;
  --field: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);

  --text: #e8ecf8;
  --muted: #8c97b0;
  --dim: #5d6882;

  --primary: #7c8cff;
  --primary-2: #5563f0;
  --cyan: #22d3ee;
  --amber: #f59e0b;
  --success: #34d399;

  --grad: linear-gradient(135deg, #7c8cff 0%, #22d3ee 100%);
  --grad-btn: linear-gradient(135deg, #6f7fff 0%, #4f5df0 100%);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 10px 30px -8px rgba(99, 112, 255, 0.55);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --page-pad: 14px;
  --sidebar-w: clamp(320px, 26vw, 420px);
  --bezel: 10px;
}

/* ---------- Base ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  /* 16px on phones → ~18px on 1080p → 20px on 2K+ */
  font-size: clamp(16px, 0.45vw + 10px, 20px);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(var(--page-pad), env(safe-area-inset-top))
    max(var(--page-pad), env(safe-area-inset-right))
    max(var(--page-pad), env(safe-area-inset-bottom))
    max(var(--page-pad), env(safe-area-inset-left));
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Aurora glow */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(600px 400px at 12% -5%, rgba(99, 112, 255, 0.28), transparent 70%),
    radial-gradient(540px 380px at 92% 8%, rgba(34, 211, 238, 0.16), transparent 70%),
    radial-gradient(700px 420px at 50% 115%, rgba(168, 85, 247, 0.14), transparent 70%);
  animation: glow 10s ease-in-out infinite alternate;
}

/* Faint blueprint grid */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 20%, transparent 75%);
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 20%, transparent 75%);
}

@keyframes glow {
  from { opacity: 0.65; }
  to { opacity: 1; }
}

button { font-family: inherit; color: inherit; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

kbd {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  padding: 1px 6px;
  border-radius: 6px;
}

.container { max-width: 1720px; margin: 0 auto; }

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--grad);
  display: grid;
  place-items: center;
  color: #0a0f1e;
  font-size: 1.15rem;
  box-shadow: 0 8px 24px -6px rgba(99, 112, 255, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  flex-shrink: 0;
}

.brand-text { min-width: 0; }

.brand-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.brand h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.brand h1 span {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.version-chip {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cyan);
  background: rgba(34, 211, 238, 0.1);
  border: 1px solid rgba(34, 211, 238, 0.3);
  padding: 2px 8px;
  border-radius: 999px;
}

.tagline {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tagline i { color: var(--primary); }

.owner-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 14px 5px 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.owner-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: #1a1203;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  flex-shrink: 0;
}

.owner-info .name {
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.verified-badge { color: var(--primary); font-size: 0.75rem; }
.owner-info .title { font-size: 0.68rem; color: var(--muted); }

/* ---------- Layout ---------- */
.preview-card { margin-bottom: 18px; }
.sidebar, .stage { min-width: 0; }

.sidebar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

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

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-title i {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  color: var(--primary);
  background: rgba(124, 140, 255, 0.14);
  border-radius: 8px;
}

.kbd-hints {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  color: var(--dim);
}

/* ---------- Address card ---------- */
.omnibar {
  position: relative;
  display: flex;
  align-items: center;
}

.omni-icon {
  position: absolute;
  left: 14px;
  color: var(--dim);
  font-size: 0.9rem;
  pointer-events: none;
}

.omnibar input {
  width: 100%;
  padding: 13px 14px 13px 40px;
  font-family: var(--mono);
  font-size: 16px; /* stops iOS zoom-on-focus */
  font-weight: 500;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

.omnibar input::placeholder { color: var(--dim); font-size: 0.85rem; }

.omnibar input:focus {
  border-color: var(--primary);
  background: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 0 4px rgba(124, 140, 255, 0.18);
}

.btn-row { display: flex; gap: 8px; margin-top: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  font-size: 0.88rem;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  flex: 2;
  color: #fff;
  background: var(--grad-btn);
  box-shadow: var(--shadow-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn-secondary {
  flex: 1;
  color: var(--text);
  background: var(--field);
  border-color: var(--line-strong);
}

.btn.btn-sm { padding: 8px 12px; font-size: 0.78rem; border-radius: var(--r-sm); flex: 0 0 auto; }

.quick-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.quick-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.quick-link i { color: var(--primary); font-size: 0.85rem; }
.quick-link:active { transform: scale(0.97); }

.quick-link.special { border-color: rgba(24, 119, 242, 0.55); background: rgba(24, 119, 242, 0.1); }
.quick-link.special i { color: #4c9bff; }

.quick-link.is-on {
  color: var(--text);
  border-color: var(--primary);
  background: rgba(124, 140, 255, 0.16);
}

/* ---------- Device card ---------- */
.device-buttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.device-btn {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "ico name" "ico size";
  align-items: center;
  column-gap: 10px;
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.device-btn i {
  grid-area: ico;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  transition: all 0.2s var(--ease);
}

.device-btn span { grid-area: name; font-size: 0.85rem; font-weight: 700; color: var(--text); line-height: 1.2; }

.device-btn .dev-size {
  grid-area: size;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--dim);
  line-height: 1.2;
}

.device-btn:active { transform: scale(0.98); }

.device-btn.active {
  border-color: rgba(124, 140, 255, 0.75);
  background: rgba(124, 140, 255, 0.13);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.14);
}

.device-btn.active i { background: var(--grad); color: #0a0f1e; }
.device-btn.active .dev-size { color: var(--cyan); }

/* ---------- Code editor card ---------- */
.code-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.code-editor-actions { display: flex; gap: 6px; flex-wrap: wrap; }

#htmlCodeTextarea {
  display: block;
  width: 100%;
  min-height: 200px;
  max-height: 420px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.65;
  tab-size: 2;
  color: #cfd8ee;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  resize: vertical;
  outline: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

#htmlCodeTextarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(124, 140, 255, 0.18); }
#htmlCodeTextarea::placeholder { color: var(--dim); }

.code-editor-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--dim);
}

.code-editor-hint i { color: var(--primary); margin-top: 2px; }

/* ---------- Stage (browser window) ---------- */
.stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.browser-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
}

.traffic { display: none; gap: 7px; flex-shrink: 0; }
.traffic span { width: 11px; height: 11px; border-radius: 50%; }
.traffic span:nth-child(1) { background: #ff5f57; }
.traffic span:nth-child(2) { background: #febc2e; }
.traffic span:nth-child(3) { background: #28c840; }

.preview-badge {
  flex: 1 1 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px;
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.preview-badge span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.dim-badge {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--cyan);
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.25);
  padding: 6px 10px;
  border-radius: 999px;
}

.preview-controls { display: flex; gap: 6px; margin-left: auto; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 38px;
  height: 38px;
  padding: 0 11px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.icon-btn i { font-size: 0.9rem; }
.icon-btn:active { transform: scale(0.96); }
.icon-btn .lbl { display: none; }

.icon-btn.fullscreen-active {
  color: #fff;
  background: var(--grad-btn);
  border-color: transparent;
}

/* Viewport area. Edge-to-edge inside the card on phones. */
.iframe-wrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: #04060c;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.iframe-container {
  position: relative;
  width: 100%;
  height: 420px;
  margin: 0 auto;
  background: #fff;
  overflow: hidden;
  transition: border-radius 0.3s var(--ease), box-shadow 0.3s var(--ease);
}

.iframe-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #fff;
  transform-origin: 0 0;
}

/* Device bezels (drawn only when JS marks the device as framed) */
.iframe-container[data-device="mobile"]  { --bezel: 10px; }
.iframe-container[data-device="tablet"]  { --bezel: 10px; }
.iframe-container[data-device="desktop"] { --bezel: 6px; }

.iframe-container[data-framed="true"] {
  margin: var(--bezel) auto;
  box-shadow:
    0 0 0 var(--bezel) #10162a,
    0 0 0 calc(var(--bezel) + 1px) rgba(255, 255, 255, 0.2),
    0 30px 60px -10px rgba(0, 0, 0, 0.7);
}

.iframe-container[data-framed="true"][data-device="mobile"]  { border-radius: 30px; }
.iframe-container[data-framed="true"][data-device="tablet"]  { border-radius: 20px; }
.iframe-container[data-framed="true"][data-device="desktop"] { border-radius: 8px; }

.iframe-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  overflow: auto;
  background:
    radial-gradient(circle at 50% 35%, rgba(124, 140, 255, 0.16), transparent 60%),
    linear-gradient(180deg, #0b1122, #070b16);
}

.placeholder-icon {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  font-size: 1.7rem;
  color: var(--primary);
  background: rgba(124, 140, 255, 0.1);
  border: 1px solid rgba(124, 140, 255, 0.3);
  border-radius: 22px;
  box-shadow: 0 0 40px -6px rgba(124, 140, 255, 0.5);
  animation: float 3.5s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.iframe-placeholder h4 { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 6px; }
.iframe-placeholder p { font-size: 0.85rem; color: var(--muted); max-width: 360px; }

.loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 18, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.loading-spinner { text-align: center; }

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 14px;
  border: 3px solid rgba(124, 140, 255, 0.2);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.loading-spinner p { font-size: 0.85rem; font-weight: 600; color: var(--text); }

/* Info footer */
.info-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 14px;
}

.stats { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; min-width: 0; }

.stat-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.76rem;
  color: var(--muted);
  min-width: 0;
}

.stat-item i { color: var(--primary); font-size: 0.8rem; }

.stat-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#currentUrlDisplay { font-family: var(--mono); font-size: 0.72rem; max-width: 36ch; }

.owner-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.owner-footer .by { font-size: 0.78rem; color: var(--muted); }
.owner-footer .by strong { color: var(--text); }

.social-links { display: flex; gap: 6px; }

.social-link {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--muted);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 50%;
  transition: all 0.2s var(--ease);
}

.social-link:active { transform: scale(0.94); }

/* Credit + footer note */
.credit-section { margin-top: 16px; }

.credit-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-size: 0.72rem;
  color: var(--dim);
}

.credit-content a { display: inline-flex; align-items: center; gap: 6px; color: var(--primary); text-decoration: none; }

.footer-note { max-width: 1720px; margin: 12px auto 0; }

.note-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  font-size: 0.74rem;
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: var(--r-md);
}

.note-content i { margin-top: 2px; }

/* ---------- Fullscreen mode ---------- */
.fullscreen-container {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 9999;
  background: #000;
}

body.fullscreen-mode { padding: 0; background: #000; overflow: hidden; }
body.fullscreen-mode::before,
body.fullscreen-mode::after { display: none; }
body.fullscreen-mode .container,
body.fullscreen-mode .footer-note { display: none; }
body.fullscreen-mode .fullscreen-container { display: block; }

.fullscreen-iframe-wrapper { position: relative; width: 100%; height: 100%; background: #000; }

.fullscreen-iframe-container { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: #000; }

#fullscreenFrame { width: 100%; height: 100%; border: none; display: block; background: #fff; }

.fullscreen-controls,
.exit-hint,
.fullscreen-url-bar {
  position: fixed;
  z-index: 10000;
  display: flex;
  align-items: center;
  background: rgba(10, 15, 30, 0.78);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  color: var(--text);
}

.fullscreen-controls {
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  gap: 6px;
  padding: 6px;
}

.fullscreen-controls .icon-btn { border-radius: 999px; background: rgba(255, 255, 255, 0.08); }

.exit-hint {
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.75rem;
  color: var(--muted);
}

.fullscreen-url-bar {
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  gap: 8px;
  max-width: 90%;
  padding: 8px 16px;
  font-family: var(--mono);
  font-size: 0.74rem;
}

.fullscreen-url-bar i { color: var(--primary); }
.fullscreen-url-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Utilities ---------- */
@media (max-width: 640px) {
  .hide-mobile { display: none !important; }
}

@media (hover: none) and (pointer: coarse) {
  .hide-touch { display: none !important; }
}

@media (pointer: coarse) {
  .btn, .icon-btn, .device-btn, .quick-link { min-height: 44px; }
  .social-link { width: 44px; height: 44px; }
}

@media (hover: hover) {
  .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 34px -8px rgba(99, 112, 255, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.25); }
  .btn-secondary:hover { background: rgba(255, 255, 255, 0.09); border-color: rgba(255, 255, 255, 0.28); }
  .quick-link:hover { color: var(--text); border-color: var(--primary); background: rgba(124, 140, 255, 0.12); transform: translateY(-1px); }
  .device-btn:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.07); }
  .device-btn.active:hover { border-color: rgba(124, 140, 255, 0.75); background: rgba(124, 140, 255, 0.16); }
  .icon-btn:hover { color: var(--text); border-color: var(--primary); background: rgba(124, 140, 255, 0.14); }
  .icon-btn.fullscreen-active:hover { background: var(--grad-btn); }
  .social-link:hover { color: #fff; background: var(--primary-2); border-color: transparent; transform: translateY(-2px); }
  .social-link.facebook:hover { background: #1877f2; }
  .social-link.github:hover { background: #333a47; }
  .credit-content a:hover { color: var(--text); }
}

/* ---------- Small phones ---------- */
@media (max-width: 360px) {
  :root { --page-pad: 8px; }
  .brand h1 { font-size: 1.15rem; }
  .device-btn { padding: 8px; column-gap: 8px; }
  .device-btn i { width: 30px; height: 30px; }
}

/* =========================================================
   ≥ 640px — tablets
   ========================================================= */
@media (min-width: 640px) {
  :root { --page-pad: 20px; }

  .brand-mark { width: 50px; height: 50px; font-size: 1.3rem; }
  .brand h1 { font-size: 1.6rem; }
  .tagline { font-size: 0.82rem; }
  .owner-avatar { width: 38px; height: 38px; }
  .owner-info .name { font-size: 0.92rem; }

  .card { padding: 18px; }
  .kbd-hints { display: flex; }

  .btn { padding: 13px 22px; font-size: 0.92rem; }
  .btn.btn-sm { padding: 9px 14px; font-size: 0.8rem; }
  .quick-link { padding: 8px 14px; font-size: 0.8rem; }

  .device-buttons { grid-template-columns: repeat(4, 1fr); }

  .traffic { display: flex; }
  .browser-bar { flex-wrap: nowrap; padding: 12px 16px; gap: 12px; }
  .preview-badge { flex: 1 1 auto; }
  .preview-controls { margin-left: 0; }

  .iframe-wrapper { padding: 14px; }
  .iframe-container { border-radius: var(--r-sm); }

  .info-footer { flex-direction: row; align-items: center; justify-content: space-between; padding: 14px 18px; }
  .owner-footer { gap: 16px; }

  .iframe-placeholder h4 { font-size: 1.4rem; }
  .iframe-placeholder p { font-size: 0.95rem; }
  .placeholder-icon { width: 88px; height: 88px; font-size: 2rem; border-radius: 26px; }

  .credit-content { font-size: 0.8rem; gap: 8px 24px; }
  .note-content { padding: 12px 18px; font-size: 0.82rem; }

  .exit-hint { top: 24px; left: 24px; font-size: 0.85rem; padding: 12px 18px; }
  .fullscreen-controls { top: 24px; right: 24px; }
  .fullscreen-url-bar { bottom: 24px; padding: 10px 20px; font-size: 0.82rem; }
}

/* =========================================================
   ≥ 1024px — laptops & desktops
   Sidebar of controls on the left, big live stage on the right
   ========================================================= */
@media (min-width: 1024px) {
  :root { --page-pad: 22px; }

  .header { margin-bottom: 14px; }

  .preview-card {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    margin-bottom: 14px;
  }

  .sidebar {
    position: sticky;
    top: 14px;
    max-height: calc(100vh - 28px);
    max-height: calc(100dvh - 28px);
    margin-bottom: 0;
    overflow-y: auto;
    padding: 0 2px 2px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  }

  .device-buttons { grid-template-columns: repeat(2, 1fr); }

  .iframe-wrapper {
    padding: 20px;
    background:
      radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.075) 1px, transparent 0) 0 0 / 22px 22px,
      #04060c;
  }

  .info-footer { padding: 12px 18px; }
  .credit-section { margin-top: 6px; }
}

/* ≥ 1280px — show labels on the toolbar buttons */
@media (min-width: 1280px) {
  .stage .icon-btn { padding: 0 14px; }
  .stage .icon-btn .lbl { display: inline; }
}

/* ≥ 1440px — large laptops */
@media (min-width: 1440px) {
  :root { --page-pad: 28px; }
  .preview-card { gap: 24px; }
  .card { padding: 20px; }
}

/* ≥ 1920px — Full HD+ */
@media (min-width: 1920px) {
  .container { max-width: 1860px; }
  .iframe-wrapper { padding: 26px; }
}

/* Short laptop screens (e.g. 1366×768 minus browser chrome) */
@media (min-width: 1024px) and (max-height: 800px) {
  body { --page-pad: 12px; }
  .header { margin-bottom: 10px; }
  .brand-mark { width: 42px; height: 42px; font-size: 1.05rem; }
  .brand h1 { font-size: 1.35rem; }
  .tagline { display: none; }
  .owner-profile { padding: 4px 12px 4px 4px; }
  .owner-avatar { width: 32px; height: 32px; }
  .preview-card { margin-bottom: 6px; }
  .sidebar { top: 10px; max-height: calc(100dvh - 20px); gap: 10px; }
  .card { padding: 14px; }
  .browser-bar { padding: 9px 14px; }
  .iframe-wrapper { padding: 12px; }
  .info-footer { padding: 9px 16px; }
  .credit-section, .footer-note { display: none; }
}

/* Phones in landscape */
@media (max-width: 1023px) and (orientation: landscape) and (max-height: 600px) {
  .tagline { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* ---------- v4.1 additions ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  max-width: min(92vw, 460px);
  padding: 10px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  z-index: 10000;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.icon-btn:disabled { opacity: 0.35; pointer-events: none; }
.icon-btn.is-on { color: var(--primary); border-color: var(--primary); }

#htmlCodeTextarea { tab-size: 2; }


/* ---------- v4.2: touch-friendly fullscreen ---------- */
.fs-grip { display: none; }
.fullscreen-container, .fullscreen-iframe-wrapper { height: 100vh; height: 100dvh; }

@media (pointer: coarse), (max-width: 640px) {
  /* Don't cover the previewed site's header / bottom nav */
  .exit-hint, .fullscreen-url-bar { display: none !important; }

  .fullscreen-controls {
    top: 42%;
    right: max(0px, env(safe-area-inset-right));
    bottom: auto;
    left: auto;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border-radius: 999px;
    transform: translate(38%, -50%);
    opacity: 0.55;
    transition: transform 0.25s var(--ease), opacity 0.25s var(--ease);
  }
  .fullscreen-controls .fs-grip { display: inline-flex; }
  .fullscreen-controls .icon-btn:not(.fs-grip) { display: none; }
  .fullscreen-controls.open { transform: translate(-6px, -50%); opacity: 1; }
  .fullscreen-controls.open .icon-btn:not(.fs-grip) { display: inline-flex; }
  .fullscreen-controls .icon-btn .hide-mobile { display: none; }
}


/* ---------- v4.3 additions ---------- */
.device-btn[data-device="custom"] { grid-column: 1 / -1; }
.custom-size { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); }
.custom-size[hidden] { display: none; }
.custom-size input {
  flex: 1; min-width: 0; padding: 9px 10px; font: inherit; font-family: var(--mono); font-size: 0.85rem;
  color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.live-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; font-size: 0.78rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.live-toggle input { accent-color: var(--primary); }


/* ---------- v4.4 additions ---------- */
.btn[hidden] { display: none; }
.iframe-placeholder .btn { margin-top: 16px; }
#rotateBtn i { transition: transform 0.25s var(--ease); }
#rotateBtn.is-on i { transform: rotate(90deg); }

@media (max-width: 639px) {
  /* Spread the toolbar evenly instead of a right-aligned strip */
  .preview-controls { width: 100%; margin-left: 0; }
  .preview-controls .icon-btn { flex: 1; justify-content: center; }
}


/* ---------- v4.5: MPA upload ---------- */
.mpa-select {
  width: 100%; margin-top: 10px; padding: 10px 12px; font: inherit; font-family: var(--mono); font-size: 0.82rem;
  color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.mpa-select option { background: var(--panel-solid); color: var(--text); }
