@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; }
}
