@font-face {
  font-family: "Stencil";
  src: url("/fonts/big-shoulders-stencil-display-latin-800-normal.woff2") format("woff2");
  font-weight: 800;
  font-display: swap;
}
@font-face {
  font-family: "Instrument";
  src: url("/fonts/instrument-sans-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Instrument";
  src: url("/fonts/instrument-sans-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

:root {
  --ink: #0b2530;
  --ink-2: #123946;
  --line: #2c4b55;
  --salt: #e8efee;
  --salt-2: #d3dfdd;
  --salt-text: #eaf1f0;
  --dim: #9dbbbe;
  --page-dim: #3a5660;
  --tape: #f0b323;
  --tape-edge: #c98f0c;
  --err: #7a1010;
  --radius: 6px;
  --stencil: "Stencil", "Arial Narrow", Impact, sans-serif;
  --sans: "Instrument", system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", "Geeza Pro", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--salt);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.55;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.box :focus-visible { outline-color: var(--tape); }
.tape :focus-visible { outline-color: var(--ink); }

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 clamp(1.25rem, 4vw, 3.5rem) clamp(1.5rem, 4vw, 3rem);
  overflow-x: clip;
}

.brand { padding: clamp(1.25rem, 3vw, 2.25rem) 0; }
.wordmark {
  font-family: var(--stencil);
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
}

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: clamp(2rem, 6vw, 6rem);
  align-items: center;
  max-width: 82rem;
  width: 100%;
  margin: 0 auto;
}

.intro h1 {
  font-family: var(--stencil);
  font-weight: 800;
  font-size: clamp(2.9rem, 2rem + 4.4vw, 5.6rem);
  line-height: 0.96;
  letter-spacing: 0.01em;
  margin: 0 0 1.5rem;
  text-wrap: balance;
}
.lede { margin: 0 0 1rem; max-width: 34rem; font-size: 1.1875rem; }
.note { margin: 0; max-width: 34rem; color: var(--page-dim); font-size: 0.9375rem; }

/* The box */
.box {
  position: relative;
  background: var(--ink);
  color: var(--salt-text);
  border-radius: 8px;
  box-shadow: 12px 12px 0 var(--salt-2);
  height: min(42rem, calc(100dvh - 9rem));
  min-height: 30rem;
}
.box-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: inherit;
  overflow: hidden;
  transition: filter 0.4s ease, opacity 0.4s ease;
}
.box.is-locked .box-inner { filter: blur(3px); opacity: 0.45; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
}
.status { margin: 0; font-size: 0.9375rem; color: var(--dim); }
.actions { display: flex; gap: 0.5rem; }
.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 0.875rem;
  min-height: 2.5rem;
  color: var(--salt-text);
}
.ghost:hover { border-color: var(--dim); }

.log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overscroll-behavior: contain;
}
.starters { display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-start; }
.starters p { margin: 0 0 0.25rem; color: var(--dim); }
.starters .greeting { color: var(--salt-text); font-size: 1.1875rem; line-height: 1.4; overflow-wrap: anywhere; }
.starter {
  text-align: left;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 0.875rem;
  min-height: 2.75rem;
  color: var(--salt-text);
}
.starter:hover { border-color: var(--tape); }

.msg {
  max-width: 88%;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user { align-self: flex-end; background: var(--tape); color: var(--ink); }
.msg.bot { align-self: flex-start; background: var(--ink-2); }
.msg.error { align-self: flex-start; background: transparent; border: 1px solid var(--tape); color: var(--salt-text); }
.msg.pending { color: var(--dim); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

.composer {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding: 0.75rem;
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 9rem;
  min-height: 2.75rem;
  background: #0f313d;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.625rem 0.75rem;
  font-size: 1rem; /* 16px stops iOS zooming in on focus */
  line-height: 1.4;
}
.composer textarea::placeholder { color: var(--dim); }
.send {
  background: var(--tape);
  color: var(--ink);
  border: 0;
  border-radius: var(--radius);
  font-weight: 600;
  min-height: 2.75rem;
  padding: 0 1.25rem;
}
.send:hover { background: #ffc845; }
.send:disabled { opacity: 0.5; cursor: default; }

/* Packing tape across the box */
.tape {
  position: absolute;
  left: -14px;
  right: -14px;
  top: 50%;
  transform: translateY(-50%) rotate(-1.5deg);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(0, 0, 0, 0.05)),
    var(--tape);
  color: var(--ink);
  padding: 1.25rem clamp(1rem, 3vw, 1.75rem) 1rem;
  border-top: 2px solid var(--tape-edge);
  border-bottom: 2px solid var(--tape-edge);
  transition: transform 0.6s cubic-bezier(0.65, 0.05, 0.25, 1), opacity 0.35s ease 0.2s, visibility 0s linear 0.6s;
}
.tape label { display: block; font-weight: 600; margin-bottom: 0.375rem; }
.tape .field { margin-bottom: 0.75rem; }
.tape .field input { width: 100%; }
.tape-row { display: flex; gap: 0.5rem; }
.tape input {
  flex: 1;
  min-width: 0;
  min-height: 2.75rem;
  background: var(--ink);
  color: var(--salt-text);
  border: 0;
  border-radius: var(--radius);
  padding: 0 0.875rem;
  font-size: 1rem;
}
.tape button {
  background: var(--ink);
  color: var(--salt-text);
  border: 0;
  border-radius: var(--radius);
  min-height: 2.75rem;
  padding: 0 1.125rem;
  font-weight: 600;
  white-space: nowrap;
}
.tape button:hover { background: var(--ink-2); }
.code-error { margin: 0.5rem 0 0; min-height: 1.5rem; color: var(--err); font-weight: 600; }

.box.is-open .tape {
  transform: translateY(-50%) translateY(-160%) rotate(-7deg);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 56rem) {
  .stage { grid-template-columns: minmax(0, 1fr); align-items: start; gap: 2rem; }
  .box { height: min(40rem, 78dvh); min-height: 28rem; box-shadow: 6px 6px 0 var(--salt-2); margin-bottom: 0.5rem; }
  .tape { left: -8px; right: -8px; }
}
@media (max-width: 26rem) {
  .tape-row { flex-direction: column; }
  .msg { max-width: 94%; }
}
.box.instant .tape, .box.instant .box-inner { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .tape, .box-inner { transition: none; }
  .msg.pending { animation: none; }
}


/* ---- Developer workspace ---- */
.run {
  background: var(--tape);
  color: var(--ink);
  border: 0;
  border-radius: var(--radius);
  font-weight: 600;
  min-height: 2.5rem;
  padding: 0 1.25rem;
}
.run:hover { background: #ffc845; }
.ghost.small { min-height: 2rem; padding: 0.25rem 0.625rem; font-size: 0.875rem; }
.bar { flex-wrap: wrap; }
.actions { flex-wrap: wrap; }

.pane-tabs { display: none; border-bottom: 1px solid var(--line); }
.pane-tabs button {
  flex: 1; background: transparent; border: 0; border-bottom: 3px solid transparent;
  min-height: 2.75rem; color: var(--dim); font-weight: 600;
}
.pane-tabs button[aria-pressed="true"] { color: var(--salt-text); border-bottom-color: var(--tape); }

.ws {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(16rem, 3fr) minmax(0, 4fr) minmax(0, 4fr);
}
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.pane:first-child { border-left: 0; }

.filetabs {
  display: flex; align-items: center; gap: 0.25rem; padding: 0.375rem 0.5rem;
  border-bottom: 1px solid var(--line); overflow-x: auto; flex: none;
}
.ftab { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); white-space: nowrap; }
.ftab.is-active { border-color: var(--tape); }
.ftab button, .fadd {
  background: transparent; border: 0; color: var(--salt-text);
  min-height: 2.25rem; padding: 0 0.625rem; font-size: 0.9375rem;
}
.ftab .fdel { color: var(--dim); padding: 0 0.5rem 0 0; }
.ftab .fdel:hover { color: var(--tape); }
.fadd { color: var(--dim); white-space: nowrap; }
.fadd:hover { color: var(--tape); }
.fnew {
  width: 9rem; min-height: 2.25rem; background: #0f313d; color: var(--salt-text);
  border: 1px solid var(--tape); border-radius: var(--radius); padding: 0 0.5rem; font-size: 1rem;
}

.editor { flex: 1; min-height: 0; overflow: hidden; }
.editor .cm-editor { height: 100%; }

.outbar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.375rem 0.5rem; border-bottom: 1px solid var(--line); flex: none;
}
.out-tabs { display: flex; gap: 0.25rem; }
.out-tabs button {
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  min-height: 2.25rem; padding: 0 0.75rem; color: var(--dim);
}
.out-tabs button[aria-pressed="true"] { color: var(--salt-text); border-color: var(--line); }
.badge {
  display: inline-block; min-width: 1.25rem; padding: 0 0.3rem; margin-left: 0.25rem;
  background: var(--tape); color: var(--ink); border-radius: 999px; font-size: 0.8125rem; text-align: center;
}
.preview { flex: 1; min-height: 0; position: relative; background: #fff; }
.preview[hidden], .console[hidden] { display: none; }
.preview iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.preview .empty { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; padding: 1rem; text-align: center; color: #3a5660; }
.preview .empty[hidden] { display: none; }
.console {
  flex: 1; min-height: 0; overflow: auto; padding: 0.5rem 0.75rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.8125rem; line-height: 1.5;
}
.console .line { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0.125rem 0; border-bottom: 1px solid var(--ink-2); }
.console .warn { color: var(--tape); }
.console .error { color: #ff9d7e; }
.console:empty::before { content: "Nothing logged yet. console.log() output and errors appear here."; color: var(--dim); }

/* Composer inside a narrow chat pane */
.pane-chat .composer { flex: none; }
.pane-chat .msg { max-width: 94%; }

/* Once unlocked, the box grows into a full-width workspace */
.page.is-workspace .intro { display: none; }
.page.is-workspace .stage { grid-template-columns: minmax(0, 1fr); align-items: stretch; max-width: none; }
.page.is-workspace .box { height: calc(100dvh - 6.5rem); min-height: 32rem; box-shadow: 8px 8px 0 var(--salt-2); }
.page.is-workspace .brand { padding: 1rem 0; }

@media (max-width: 56rem) {
  .pane-tabs { display: flex; }
  .ws { grid-template-columns: minmax(0, 1fr); }
  .ws .pane { display: none; border-left: 0; }
  .ws[data-pane="chat"] .pane-chat, .ws[data-pane="code"] .pane-code, .ws[data-pane="out"] .pane-out { display: flex; }
  .page.is-workspace .box { height: calc(100dvh - 5rem); min-height: 26rem; box-shadow: 4px 4px 0 var(--salt-2); }
}
@media (max-width: 40rem) {
  .actions .ghost, .run { min-height: 2.25rem; padding: 0 0.625rem; font-size: 0.9375rem; }
}
