:root {
  /* Brand palette taken from the LinkedIn cover:
     navy headline #1A202C, gold accent #C4A052. */
  --ink: #0d1017;          /* app background, slightly deeper than the navy */
  --ink-soft: #141822;
  --panel: #1a1f2b;
  --line: #2b3140;
  --paper: #eeeae0;
  --paper-line: #ddd6c6;

  --navy: #1a202c;         /* brand navy (headline colour) */
  --navy-hi: #273143;      /* lighter navy for hovers */
  --gold: #c4a052;         /* brand gold accent */
  --gold-hi: #d4b366;      /* brighter gold for hover/highlight */

  /* accent now = brand gold, so primary actions read as "on brand" */
  --accent: #c4a052;
  --accent-dim: #b08f42;

  --text: #f1ede4;
  --text-muted: #9aa0ab;
  --text-faint: #616773;

  --font-display: "Space Grotesk", sans-serif;
  --font-ui: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  font-family: var(--font-ui);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* No fixed height / no overflow:hidden — the body grows with its content
     so the whole page scrolls normally on mobile. The stage gets its own
     touch-scrollable region via the media query below. */
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--ink-soft);
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
}
.brand span { color: var(--text); }

.url-bar { display: flex; gap: 10px; flex: 1; max-width: 720px; }
#urlInput {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13.5px;
  padding: 11px 14px;
  border-radius: 8px;
  outline: none;
  transition: border-color .15s ease;
}
#urlInput:focus { border-color: var(--accent); }
#urlInput::placeholder { color: var(--text-faint); }

#generateBtn {
  background: var(--navy);
  color: #fff;
  border: 1px solid var(--navy-hi);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13.5px;
  padding: 0 20px;
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; gap: 9px;
  transition: background .15s ease, transform .1s ease;
}
#generateBtn:hover { background: var(--navy-hi); }
#generateBtn:active { transform: scale(0.98); }
#generateBtn:disabled { opacity: .6; cursor: wait; }
.btn-spinner {
  width: 13px; height: 13px;
  border: 2px solid rgba(26,13,6,.35);
  border-top-color: #1a0d06;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Workspace layout ---------- */
.workspace { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--ink-soft);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 18px 16px 24px;
  display: flex;
  flex-direction: column;
}
.panel { margin-bottom: 26px; }
.panel h3 {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.panel-hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.panel-hint.small { font-size: 11px; margin: 10px 0 0; min-height: 14px; }

.device-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.device-toggle {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.device-toggle svg { width: 22px; height: 22px; }
.device-toggle input { display: none; }
.device-toggle:has(input:checked) {
  border-color: var(--accent);
  color: var(--text);
  background: #241a14;
}

.field-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: var(--text-muted);
}
#bgColor {
  width: 30px; height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  padding: 0;
}
#viewAngle {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 12.5px;
  padding: 7px 8px;
  border-radius: 6px;
}

.switch-row {
  display: flex; align-items: center; gap: 9px;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 8px 0;
  cursor: pointer;
}
.switch-row input {
  appearance: none; width: 32px; height: 18px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; position: relative; cursor: pointer;
  transition: background .15s ease;
  flex-shrink: 0;
}
.switch-row input::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-muted);
  transition: transform .15s ease, background .15s ease;
}
.switch-row input:checked { background: var(--accent-dim); border-color: var(--accent); }
.switch-row input:checked::after { transform: translateX(14px); background: #241c08; }

.primary-btn, .ghost-btn {
  width: 100%;
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .1px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease, opacity .15s ease;
}
/* Primary = the capture (download) actions. Gold, with a little depth so
   they read as the main call to action and stand out from the panel. */
.primary-btn {
  background: linear-gradient(180deg, var(--gold-hi), var(--gold));
  color: #241c08;
  border: none;
  box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 2px 8px rgba(196,160,82,.28);
}
.primary-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #dcbb70, var(--gold-hi));
  transform: translateY(-1px);
  box-shadow: 0 1px 0 rgba(255,255,255,.22) inset, 0 4px 14px rgba(196,160,82,.4);
}
.primary-btn:active:not(:disabled) { transform: translateY(0); box-shadow: 0 1px 4px rgba(196,160,82,.3); }
.primary-btn:disabled { opacity: .35; cursor: not-allowed; }

.ghost-btn {
  background: rgba(255,255,255,.02);
  color: var(--text-muted);
  border: 1px solid var(--line);
}
.ghost-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--gold);
  background: rgba(196,160,82,.06);
}
.ghost-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Stage ---------- */
.stage-wrap { flex: 1; padding: 20px; min-width: 0; }
.stage {
  /* Height follows the artboard; it's centered horizontally so the normal-
     mode margin sits evenly on both sides rather than as dark padding on one
     edge. overflow:hidden keeps it unscrollable. */
  height: auto;
  background: var(--ink);
  border-radius: 14px;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

/* The artboard is always 1500x880 internally. This wrapper carries the
   fit-to-stage scale so the LAYOUT footprint shrinks too — otherwise a
   scaled .preview would still occupy 1500px of layout and force scrollbars
   (that was the mobile "devices not visible" bug: the scene was laid out
   far off-screen). JS sets its width/height each time the stage resizes. */
.artboard-box { position: relative; }



.preview {
  position: absolute;
  top: 0; left: 0;
  width: 1500px;
  height: 700px;
  transform-origin: top left;   /* JS composes fit-scale + larger + angle */
  transition: transform .25s ease;
}

.device {
  position: absolute;
  top: 0; left: 0;
  cursor: grab;
  filter: drop-shadow(0 30px 26px rgba(20,22,27,.28)) drop-shadow(0 10px 10px rgba(20,22,27,.18));
  touch-action: none;
  user-select: none;
}
.device.dragging { cursor: grabbing; }
.device[hidden] { display: none; }

.frame-img { position: relative; display: block; width: 100%; height: 100%; pointer-events: none; }
.screen-slot { position: absolute; overflow: hidden; background: #fff; }
.live-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }

/*
 * Wrapper sizes, screen-slot percentages, and object-fit behavior below are
 * taken directly from the reference tool's actual CSS (desktop-wrapper,
 * mac-wrapper, ipad-wrapper, iphone-wrapper and their *-inner children),
 * not approximated from visual inspection. The four PNGs are the exact
 * same source images the reference uses, confirmed by matching filenames
 * and pixel dimensions, so these numbers map onto them precisely.
 */

/* iMac — 703x576 wrapper, image is native size (703x576), fills exactly */
.device-imac { width: 703px; aspect-ratio: 703 / 576; }
.device-imac .frame-img { object-fit: fill; }
.device-imac .screen-slot { left: 6.83%; top: 6.25%; width: 85.49%; height: 59.55%; }

/* MacBook — 650x406 wrapper; native image is 1217x706, reference uses
   background-size:contain with default (top-left) position, so the image
   renders smaller than the box and sits flush top-left, not centered. */
.device-macbook { width: 650px; aspect-ratio: 650 / 377; }
.device-macbook .frame-img { object-fit: fill; }
.device-macbook .screen-slot { left: 12.77%; top: 7.43%; width: 74.46%; height: 80.10%; }

/* iPad — 250x353 wrapper; native image 407x574, reference uses
   background-size:cover, background-position:bottom. */
.device-ipad { width: 250px; aspect-ratio: 250 / 353; }
.device-ipad .frame-img { object-fit: cover; object-position: bottom; }
.device-ipad .screen-slot { left: 6.80%; top: 9.35%; width: 86.80%; height: 82.15%; }

/* iPhone — 120x240 wrapper; native image 500x998, reference uses
   background-size:cover, background-position:bottom. */
.device-iphone { width: 120px; aspect-ratio: 120 / 240; }
.device-iphone .frame-img { object-fit: cover; object-position: bottom; }
.device-iphone .screen-slot { left: 6.67%; top: 7.50%; width: 86.67%; height: 89.17%; }

/* ---------- Ad bands ---------- */
.ad-band {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px 16px;
  background: var(--ink-soft);
  border-bottom: 1px solid var(--line);
  min-height: 0; /* collapses to nothing until an ad unit is pasted in */
}
#adBottom { border-bottom: none; border-top: 1px solid var(--line); }

/* ---------- Capture (native screen-capture) ---------- */
.panel-divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}
.capture-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(10, 12, 16, 0.94);
  display: flex;
  flex-direction: column;
}
.capture-overlay[hidden] { display: none; }
.capture-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: var(--ink-2, #12151b);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.capture-hint { color: var(--text-dim, #aeb4bf); font-size: 13px; }
.capture-actions { display: flex; gap: 8px; }
.capture-actions .ghost-btn,
.capture-actions .primary-btn { width: auto; margin: 0; padding: 8px 16px; }
.capture-stage {
  position: relative;
  flex: 1;
  overflow: hidden;          /* never scroll — scrolling broke selection offsets */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 0;
}
#captureCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;          /* fit in BOTH dimensions (portrait frames too) */
  width: auto;
  height: auto;
  object-fit: contain;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  cursor: crosshair;
  touch-action: none;
}
.capture-selection {
  position: absolute;
  border: 2px dashed var(--gold, #c4a052);
  background: rgba(196, 160, 82, 0.14);
  pointer-events: auto;
  cursor: move;
  box-sizing: border-box;
}
.capture-selection[hidden] { display: none; }

.cap-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--gold, #c4a052);
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
  box-sizing: border-box;
}
/* corners */
.cap-handle[data-h="nw"] { left: -7px;  top: -7px;    cursor: nwse-resize; }
.cap-handle[data-h="ne"] { right: -7px; top: -7px;    cursor: nesw-resize; }
.cap-handle[data-h="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.cap-handle[data-h="sw"] { left: -7px;  bottom: -7px; cursor: nesw-resize; }
/* edges */
.cap-handle[data-h="n"] { left: 50%; top: -7px;    transform: translateX(-50%); cursor: ns-resize; }
.cap-handle[data-h="s"] { left: 50%; bottom: -7px; transform: translateX(-50%); cursor: ns-resize; }
.cap-handle[data-h="w"] { top: 50%; left: -7px;    transform: translateY(-50%); cursor: ew-resize; }
.cap-handle[data-h="e"] { top: 50%; right: -7px;   transform: translateY(-50%); cursor: ew-resize; }


.credit-link { color: var(--gold); text-decoration: none; font-weight: 600; }
.credit-link:hover { color: var(--gold-hi); text-decoration: underline; }

/* Developer credit pinned to the bottom of the sidebar */
.sidebar-credit {
  margin-top: auto;
  padding: 14px 4px 4px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--text-muted);
}

@media (max-width: 860px) {
  .workspace { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
    order: 2;               /* controls come AFTER the canvas on mobile */
    display: block;         /* cancel the flex-column so credit isn't pushed by margin-top:auto */
  }
  .stage-wrap {
    order: 1;               /* canvas first — the mockup is the point */
    padding: 10px;
  }
  .topbar { flex-wrap: wrap; }
  /* Credit sits naturally at the end of the sidebar (which is last) instead
     of being pinned mid-panel by margin-top:auto. */
  .sidebar-credit { margin-top: 20px; }
  /* Screen capture isn't supported on mobile browsers, so tell the user
     rather than showing dead buttons. */
  .mobile-capture-note { display: block; }
  .capture-controls { display: none; }
}
@media (min-width: 861px) {
  .mobile-capture-note { display: none; }
}
