:root {
  --bg: #0c0f0d;
  --bg-2: #131815;
  --panel: rgba(19, 24, 21, 0.92);
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #e9efe9;
  --muted: #8d9a91;
  --green: #2fdc6e;
  --green-ink: #062611;
  --amber: #ffb224;
  --red: #ff6b6b;
  --radius: 18px;
  --vvh: 100dvh;
  --kb: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---- stage: the rendered page fills the screen on phones ---- */
.stage { position: fixed; inset: 0; display: grid; place-items: center; }
.device { position: absolute; inset: 0; background: #fff; }
.frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }

/* ---- welcome ---- */
.welcome {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + var(--safe-b));
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(47, 220, 110, 0.16), transparent 60%),
    radial-gradient(80% 50% at 100% 110%, rgba(255, 178, 36, 0.08), transparent 60%),
    var(--bg);
  overflow-y: auto;
}
.welcome-card { width: min(100%, 560px); flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.welcome-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.home-link { color: var(--muted); font: 500 13px/1 var(--mono); text-decoration: none; padding: 10px 4px; }
.home-link:hover { color: var(--text); }
.brand { margin: 0; display: flex; align-items: center; gap: 10px; font: 700 30px/1 var(--mono); letter-spacing: -0.03em; }
.brand-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px rgba(47, 220, 110, 0.18); }
.lede { margin: 0 0 4px; font-size: 16px; color: var(--muted); text-wrap: pretty; }
.hint { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }
kbd { font: 600 11px/1 var(--mono); padding: 2px 5px; border: 1px solid var(--line-2); border-radius: 5px; color: var(--text); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; border: 1px solid var(--line-2); border-radius: 14px; background: var(--bg-2); padding: 12px 16px; font-weight: 600; transition: transform 0.15s var(--ease), background 0.15s; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--green); color: var(--green-ink); border-color: transparent; }
.btn-primary:hover { background: #4be585; }
.btn-lg { min-height: 56px; font-size: 17px; flex: none; }
.btn > span { display: inline-flex; align-items: center; gap: 10px; }
#paste-btn[data-mode="paste"] .when-render, #paste-btn[data-mode="render"] .when-paste { display: none; }

.drop { flex: 1; min-height: 0; display: flex; }
.code {
  width: 100%; resize: none; border: 1px solid var(--line-2); border-radius: 14px;
  background: rgba(0, 0, 0, 0.35); color: var(--text); padding: 12px 14px;
  font: 14px/1.5 var(--mono); tab-size: 2; caret-color: var(--green);
}
.code::placeholder { color: #56625a; }
.code:focus { outline: none; border-color: rgba(47, 220, 110, 0.6); }
/* 16px stops iOS zooming into the field on focus. */
@media (hover: none) { .code { font-size: 16px; } }
.drop-input { flex: 1; min-height: 160px; }

/* ---- dock ---- */
.dock {
  position: fixed; z-index: 5; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%);
  display: flex; gap: 4px; padding: 5px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line-2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: opacity 0.2s, transform 0.25s var(--ease);
  touch-action: none; /* swipe up opens the editor */
}
.dock-btn { position: relative; display: inline-flex; align-items: center; gap: 8px; min-width: 44px; height: 44px; padding: 0 12px; border: 0; border-radius: 999px; background: transparent; justify-content: center; }
.dock-btn:hover { background: rgba(255, 255, 255, 0.07); }
.dock-main { background: var(--green); color: var(--green-ink); font-weight: 650; padding: 0 16px; }
.dock-main:hover { background: #4be585; }
.dock-btn .badge { position: absolute; top: 4px; right: 2px; }
body.sheet-open .dock { opacity: 0; pointer-events: none; transform: translate(-50%, 12px); }

.badge { display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 5px; border-radius: 999px; background: var(--line-2); color: var(--text); font: 600 10px/1 var(--font); }
.badge-error { background: var(--red); color: #2a0606; }

/* ---- sheet (editor) ---- */
.sheet {
  position: fixed; z-index: 6; left: 0; right: 0; top: auto;
  /* --kb is the part of the layout viewport hidden by the keyboard (incl. iOS panning). */
  bottom: var(--kb);
  height: min(44vh, calc(var(--vvh) - 56px));
  display: flex; flex-direction: column;
  background: var(--panel); border-top: 1px solid var(--line-2);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  animation: sheet-in 0.3s var(--ease);
  overscroll-behavior: contain;
}
/* Only animate on purpose (open, drag release, grip); never while the keyboard moves. */
.sheet-dragging iframe { pointer-events: none; }
.sheet.settling { transition: transform 0.26s var(--ease), height 0.26s var(--ease); }
@keyframes sheet-in { from { transform: translateY(100%); } }
body.sheet-tall .sheet { height: calc(var(--vvh) - 72px); }
.sheet-grip { display: grid; place-items: center; height: 24px; margin-bottom: -10px; width: 100%; border: 0; background: transparent; flex: none; touch-action: none; }
.sheet-grip span { width: 40px; height: 5px; border-radius: 999px; background: var(--line-2); }
.sheet-grip:hover span { background: var(--muted); }

.sheet-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 6px 10px; border-bottom: 1px solid var(--line); touch-action: pan-x; user-select: none; -webkit-user-select: none; }
.tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted); font: 600 13px/1 var(--mono); white-space: nowrap;
}
.tab.has-code::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }
.tab[aria-selected="true"] { background: rgba(47, 220, 110, 0.14); color: var(--green); }
.sheet-actions { display: flex; gap: 2px; padding-left: 6px; border-left: 1px solid var(--line); }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); }
.icon-btn:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); }
/* Phones: keep all four tabs and three actions on one row. */
@media (max-width: 430px) {
  .sheet-head { gap: 4px; padding-left: 6px; padding-right: 4px; }
  .tab { padding: 0 9px; }
  .icon-btn { width: 38px; }
}

.panes { flex: 1; min-height: 0; display: flex; padding: 8px 10px calc(10px + var(--safe-b)); }
.pane { flex: 1; min-height: 0; height: 100%; overscroll-behavior: contain; }
textarea.pane { border-radius: 12px; background: rgba(0, 0, 0, 0.4); white-space: pre; overflow: auto; }

/* ---- code editor: coloured layer + line numbers under a see-through textarea ---- */
.editor {
  --fs: 14px; --lh: calc(var(--fs) * 1.5); --gw: 2ch;
  flex: 1; min-height: 0; min-width: 0; position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr);
  border: 1px solid var(--line-2); border-radius: 12px; background: rgba(0, 0, 0, 0.4); overflow: hidden;
}
.editor:focus-within { border-color: rgba(47, 220, 110, 0.6); }
.gutter {
  overflow: hidden; border-right: 1px solid var(--line); background: rgba(255, 255, 255, 0.02);
  user-select: none; -webkit-user-select: none; pointer-events: none;
}
.gutter-in {
  padding: 12px 8px 12px 10px; min-width: calc(var(--gw) + 18px); text-align: right; white-space: pre;
  font: calc(var(--fs) * 0.82) / var(--lh) var(--mono); color: #4d5a52; font-variant-numeric: tabular-nums; will-change: transform;
}
.editor .hl, .editor textarea { grid-column: 2; grid-row: 1; margin: 0; }
.editor .hl { overflow: hidden; pointer-events: none; }
.hl-in, .editor textarea {
  font: var(--fs) / var(--lh) var(--mono); tab-size: 2; letter-spacing: 0; padding: 12px 14px;
  white-space: pre; word-wrap: normal; overflow-wrap: normal;
}
.hl-in { display: block; width: max-content; min-width: 100%; color: var(--text); will-change: transform; }
.editor textarea {
  width: 100%; height: 100%; border: 0; border-radius: 0; background: transparent; resize: none;
  color: transparent; -webkit-text-fill-color: transparent; caret-color: var(--green);
}
.editor textarea::placeholder { color: #56625a; -webkit-text-fill-color: #56625a; }
.editor textarea::selection { background: rgba(47, 220, 110, 0.28); }
.editor textarea:focus { outline: none; }
/* Huge pastes skip colouring so typing stays fast. */
.editor.plain textarea { color: var(--text); -webkit-text-fill-color: var(--text); }
.t-com { color: #5f6e65; font-style: italic; }
.t-str { color: #a6e3a1; }
.t-kw { color: #ff7ab6; }
.t-num { color: #f9a66c; }
.t-fn { color: #82aaff; }
.t-type { color: #ffd479; }
.t-tag { color: #5fd4ff; }
.t-attr { color: #ffb224; }
.t-punct, .t-meta { color: #7d8a81; }
.t-prop { color: #5fd4ff; }
.t-val { color: #e9efe9; }
.t-sel { color: #ffb224; }
.t-el { color: #ffd479; }
@media (hover: none) { .editor { --fs: 16px; } }

.log { margin: 0; padding: 4px 0; list-style: none; overflow: auto; font: 12.5px/1.5 var(--mono); }
.log:empty::before { content: "Console output from your code shows up here."; display: block; padding: 12px; color: var(--muted); font-family: var(--font); }
.log li { padding: 6px 12px; border-bottom: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.log .log-warn { color: var(--amber); background: rgba(255, 178, 36, 0.06); }
.log .log-error { color: var(--red); background: rgba(255, 107, 107, 0.07); }
.log .log-info { color: #9fd0ff; }
.log .log-debug { color: var(--muted); }

/* ---- toast + drop ---- */
.toast {
  position: fixed; z-index: 9; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  padding: 9px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line-2);
  font-size: 13px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); animation: toast-in 0.2s var(--ease);
  max-width: calc(100vw - 32px);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -6px); } }
.dropzone { position: fixed; inset: 12px; z-index: 10; display: grid; place-items: center; border: 2px dashed var(--green); border-radius: 22px; background: rgba(12, 15, 13, 0.85); color: var(--green); font: 600 18px/1 var(--mono); pointer-events: none; }

.desk-only { display: none; }

/* ---- desktop: phone frame + side editor ---- */
@media (min-width: 900px) and (hover: hover) {
  .desk-only { display: inline-flex; }
  .stage {
    background:
      radial-gradient(70% 60% at 50% 0%, rgba(47, 220, 110, 0.08), transparent 70%),
      var(--bg);
    padding: 24px 24px 92px; /* keeps the dock below the phone frame */
    transition: left 0.28s var(--ease);
  }
  body.sheet-open .stage { left: min(46vw, 640px); }
  .device {
    position: relative; inset: auto;
    width: 390px; height: min(844px, calc(100vh - 116px));
    border-radius: 44px; overflow: hidden;
    box-shadow: 0 0 0 10px #1c221e, 0 0 0 11px var(--line-2), 0 30px 80px rgba(0, 0, 0, 0.6);
    transition: width 0.3s var(--ease), height 0.3s var(--ease), border-radius 0.3s var(--ease);
  }
  body.full-width .device { width: 100%; height: 100%; border-radius: 14px; }
  .sheet-grip { display: none; }
  .welcome { justify-content: center; }
  .welcome-card { flex: none; }
  .drop-input { min-height: 260px; max-height: 50vh; }
  .sheet, body.sheet-tall .sheet {
    left: 0; top: 0; bottom: 0; right: auto; width: min(46vw, 640px); height: auto;
    border-radius: 0; border-top: 0; border-right: 1px solid var(--line-2);
    box-shadow: 16px 0 40px rgba(0, 0, 0, 0.35);
    animation-name: sheet-in-side;
  }
  @keyframes sheet-in-side { from { transform: translateX(-24px); opacity: 0; } }
  body.sheet-open .dock { opacity: 1; pointer-events: auto; transform: translateX(-50%); left: calc(min(46vw, 640px) + (100vw - min(46vw, 640px)) / 2); }
  /* The console tab is already on screen while the editor is open. */
  body.sheet-open .dock [data-action="console"] { display: none; }
  body.sheet-open .toast { left: calc(min(46vw, 640px) + (100vw - min(46vw, 640px)) / 2); }
  .code { font-size: 13.5px; }
  .editor { --fs: 13.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
