:root {
  --bg: #0c0c0e;
  --panel: #141417;
  --panel-2: #1b1b1f;
  --line: #2a2a30;
  --line-strong: #3a3a42;
  --text: #ececf0;
  --muted: #8d8d98;
  --accent: #ff7a2f;
  --accent-strong: #ff9150;
  --accent-ink: #1a0b03;
  --danger: #ff5f56;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }

/* --- Buttons & controls ---------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel-2); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #24242a; border-color: #4a4a54; }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }

.segmented {
  display: flex; padding: 3px; gap: 3px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
}
.segmented button {
  flex: 1; height: 30px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 13px;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }

/* --- Brand ------------------------------------------------------------------ */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: radial-gradient(circle at 35% 30%, #ffc28a, var(--accent) 45%, #8a2a00);
  box-shadow: 0 0 18px rgba(255, 122, 47, .45);
}

/* --- Login -------------------------------------------------------------------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 14px;
  padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input {
  height: 40px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--bg);
}
.login-card .btn { height: 40px; margin-top: 4px; }
.muted { color: var(--muted); margin: 0; }
.form-error { color: var(--danger); margin: 0; }

/* --- Editor layout ------------------------------------------------------------ */
.page-editor { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 16px; flex: none;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.urlbar { flex: 1; display: flex; gap: 8px; max-width: 760px; margin: 0 auto; }
.urlbar input {
  flex: 1; min-width: 0; height: 36px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg);
}
.topbar-end { display: flex; align-items: center; gap: 8px; }
.logout { margin: 0; }

.workspace { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 248px; flex: none; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 20px;
  background: var(--panel); border-right: 1px solid var(--line);
}
.panel section { display: grid; gap: 10px; }
.panel h2 { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 600; }
.btn-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.btn-row .btn { height: auto; padding: 8px 4px; flex-direction: column; gap: 4px; font-size: 12px; }
.btn-row .btn svg { width: 22px; height: 22px; }
.panel-foot { margin-top: auto; }
.hint { margin: 0; color: var(--muted); font-size: 12px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; padding: 0;
  border: 1px solid var(--line-strong); position: relative;
}
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-custom { overflow: hidden; }
.swatch-custom input { position: absolute; inset: -8px; width: 48px; height: 48px; border: 0; padding: 0; cursor: pointer; opacity: 0; }
.swatch-custom::after { content: "+"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; mix-blend-mode: difference; pointer-events: none; }

.checker, .canvas.is-transparent {
  background-color: #2a2a2e;
  background-image:
    linear-gradient(45deg, #3a3a40 25%, transparent 25%), linear-gradient(-45deg, #3a3a40 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #3a3a40 75%), linear-gradient(-45deg, transparent 75%, #3a3a40 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

/* --- Stage & devices ------------------------------------------------------------ */
.stage {
  flex: 1; min-width: 0; position: relative; overflow: hidden;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, #17171b, #0a0a0c 70%);
}
.canvas {
  position: relative; overflow: hidden; flex: none;
  border-radius: 4px; box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(0, 0, 0, .5);
}
.device { position: absolute; transform-origin: 0 0; }
.device svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.device .frame-under { cursor: grab; }
.device .frame-over { pointer-events: none; }
.device .screen { position: absolute; overflow: hidden; background: #000; }
.device iframe { display: block; border: 0; width: 100%; height: 100%; background: #fff; }
.device.loading .screen::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(110deg, #101013 30%, #1d1d22 50%, #101013 70%) 0 0 / 300% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -150% 0; } }

.stage.interacting iframe { pointer-events: none; }
.stage.interacting .device .frame-under { cursor: grabbing; }

.chrome { position: absolute; pointer-events: none; }
.chrome .outline {
  position: absolute; inset: -4px; border-radius: 8px;
  border: 1.5px dashed transparent;
}
.chrome.selected .outline { border-color: rgba(255, 122, 47, .7); }
.chrome .bar {
  position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%);
  display: none; align-items: center; gap: 2px; padding: 4px;
  background: rgba(20, 20, 23, .96); border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); pointer-events: auto;
}
.chrome.selected .bar { display: flex; }
.chrome.bar-below .bar { bottom: auto; top: calc(100% + 10px); }
.bar .grip { cursor: grab; padding: 0 6px; color: var(--muted); font-size: 12px; user-select: none; white-space: nowrap; }
.bar input {
  width: 260px; height: 28px; padding: 0 8px; font-size: 12px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}
.bar button {
  width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; cursor: pointer;
  display: grid; place-items: center; color: var(--muted);
}
.bar button:hover { background: var(--panel-2); color: var(--text); }
.bar button.danger:hover { color: var(--danger); }
.bar svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chrome .handle {
  position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--accent); border: 3px solid #0c0c0e;
  cursor: nwse-resize; pointer-events: auto; display: none;
}
.chrome.selected .handle { display: block; }

.guide { position: absolute; top: 0; bottom: 0; width: 1px; left: 50%; background: var(--accent); opacity: 0; pointer-events: none; z-index: 5000; }
.guide-h { top: 50%; bottom: auto; left: 0; right: 0; width: auto; height: 1px; }
.guide.on { opacity: .8; }

/* --- Overlays ----------------------------------------------------------------- */
.busy { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(5, 5, 7, .6); z-index: 9000; backdrop-filter: blur(2px); }
.busy[hidden] { display: none; }
.busy-card { display: flex; align-items: center; gap: 12px; padding: 16px 20px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 12px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line-strong);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 9500;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); }

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .urlbar { order: 3; flex-basis: 100%; }
  .workspace { flex-direction: column; }
  .panel { width: auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); gap: 16px; }
  .panel section { min-width: 200px; }
  .panel-foot { display: none; }
  .bar input { width: 140px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
