/* Lispeln · style.css */
:root {
  --bg: #070a16; --ui-text: #e8e3d6; --muted: #8d97ab; --amber: #e8a84a; --violet: #a98bff; --err: #ff8f6b;
  --panel-bg: rgba(8, 12, 22, 0.74); --panel-border: rgba(255, 255, 255, 0.1); --field: rgba(10, 14, 27, 0.92);
  --mono: ui-monospace, Menlo, "SF Mono", Consolas, "Liberation Mono", monospace;
  --code-size: 13px; --code-lh: 20px;
  --ov-top: 120px; --ov-band: 48px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); overscroll-behavior: none; }
body {
  height: 100vh; height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ui-text); -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(62px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
}
button, select, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

a.home { position: fixed; top: calc(14px + env(safe-area-inset-top, 0px)); left: calc(14px + env(safe-area-inset-left, 0px)); z-index: 8;
  font-size: 12px; color: #6d7a90; text-decoration: none; padding: 4px 7px; border-radius: 5px;
  background: rgba(6, 10, 22, 0.6); border: 1px solid var(--panel-border); }
a.home:hover, a.home:focus-visible { color: var(--amber); }
.hud { position: fixed; top: calc(14px + env(safe-area-inset-top, 0px)); right: calc(14px + env(safe-area-inset-right, 0px)); z-index: 8;
  font-family: var(--mono); font-size: 11px; color: var(--muted); padding: 4px 8px; border-radius: 5px; white-space: nowrap;
  background: rgba(6, 10, 22, 0.6); border: 1px solid var(--panel-border); font-variant-numeric: tabular-nums; pointer-events: none; }

.title-overlay { position: fixed; top: calc(8px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 9; text-align: center; pointer-events: none;
  opacity: 1; transition: opacity 1s ease; width: max-content; max-width: min(560px, calc(100vw - 32px)); padding: 6px 18px; border-radius: 12px;
  background: rgba(8, 10, 18, 0.82); border: 1px solid var(--panel-border); }
.title-overlay.faded { opacity: 0; }
.title-overlay h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: 0.06em; color: #f0e2c4; text-shadow: 0 1px 12px rgba(0,0,0,0.95); }
.title-overlay p { margin: 1px 0 0; font-size: 11.5px; color: #b3bccb; text-shadow: 0 1px 10px rgba(0,0,0,0.95); }

/* ---------- toolbar ---------- */
.bar { flex: 0 0 auto; width: 100%; max-width: 1400px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 12px;
  padding: 6px; border-radius: 11px; background: var(--panel-bg); border: 1px solid var(--panel-border); }
.grp { display: flex; flex-wrap: nowrap; align-items: center; gap: 5px; min-width: 0; }
.btn { flex: 0 0 auto; min-height: 36px; min-width: 36px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--panel-border); background: rgba(18, 24, 38, 0.7); border-radius: 8px; font-size: 13px; color: var(--ui-text); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: rgba(255,255,255,0.24); }
.btn kbd { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.btn.go { color: #10131c; background: var(--amber); border-color: var(--amber); font-weight: 600; min-width: 84px; }
.btn.go kbd { color: #4a3612; }
.btn.go:hover { background: #f0b862; }
.btn.tog[aria-pressed="true"] { color: var(--violet); border-color: rgba(169,139,255,0.6); background: rgba(30,24,48,0.75); }
.btn.flash { color: var(--amber); border-color: rgba(232,168,74,0.7); }
.tabs { display: none; gap: 3px; }
.tab[aria-selected="true"] { border-color: rgba(232,168,74,0.8); background: rgba(40,32,20,0.75); color: var(--amber); }
select { min-height: 36px; border-radius: 8px; border: 1px solid var(--panel-border); background: rgba(18, 24, 38, 0.95); padding: 0 6px; font-size: 13px; max-width: 13em; }
#urlBox { width: 100%; font-family: var(--mono); font-size: 11px; padding: 6px; border-radius: 6px; border: 1px solid var(--panel-border); background: var(--field); }

/* ---------- main ---------- */
main { flex: 1 1 auto; min-height: 0; width: 100%; max-width: 1400px; margin-top: 10px;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.col { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 8px; }

.editor { flex: 3 1 0; min-height: 0; display: flex; border: 1px solid var(--panel-border); border-radius: 10px; background: var(--field); overflow: hidden; }
.editor:focus-within { border-color: rgba(232,168,74,0.55); box-shadow: 0 0 0 1px rgba(232,168,74,0.35); }
.gutter { flex: 0 0 auto; min-width: 3.1em; overflow: hidden; padding: 8px 8px 8px 4px; text-align: right; background: rgba(255,255,255,0.025);
  border-right: 1px solid rgba(255,255,255,0.05); font-family: var(--mono); font-size: var(--code-size); line-height: var(--code-lh); color: #4d586d;
  -webkit-user-select: none; user-select: none; }
.gutter-inner { white-space: pre; will-change: transform; }
textarea#code { flex: 1 1 auto; min-width: 0; margin: 0; padding: 8px 10px; border: 0; outline: none; resize: none; background: transparent;
  font-family: var(--mono); font-size: var(--code-size); line-height: var(--code-lh); white-space: pre; overflow: auto; tab-size: 2; -moz-tab-size: 2;
  caret-color: var(--amber); color: var(--ui-text); }
textarea#code::selection { background: rgba(169,139,255,0.35); }

.outwrap { flex: 2 1 0; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--panel-border); border-radius: 10px; background: var(--field); overflow: hidden; }
.out { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 8px 10px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ui-text); }
.out:focus-visible { outline-offset: -2px; }
.out .r { color: var(--muted); }
.out .e { color: var(--err); }
.out .q { color: #b9a6ff; }
.out .m { color: #5d6880; font-style: italic; }
.repl { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-top: 1px solid rgba(255,255,255,0.07); background: rgba(255,255,255,0.02); }
.repl .prompt { color: var(--amber); font-family: var(--mono); font-size: 15px; line-height: 1; }
#repl { flex: 1 1 auto; min-width: 0; height: 30px; border: 0; outline: none; background: transparent; font-family: var(--mono); font-size: 12.5px; caret-color: var(--amber); }
#repl::placeholder { color: #4d586d; }
.repl:focus-within { box-shadow: inset 0 0 0 1px rgba(232,168,74,0.45); }

.canvas-box { flex: 1 1 auto; min-height: 0; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px; }
.canvas-sq { position: relative; width: 300px; height: 300px; border-radius: 10px; overflow: hidden; border: 1px solid var(--panel-border); background: #0a0e1c; }
.canvas-sq canvas { position: absolute; left: 0; top: 0; display: block; }
#cv { cursor: pointer; touch-action: manipulation; }
#icon { pointer-events: none; }
.status { flex: 0 0 auto; width: 100%; font-family: var(--mono); font-size: 11.5px; color: var(--muted); text-align: center; min-height: 1.5em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.status.err { color: var(--err); }

/* ---------- help ---------- */
.help { position: fixed; z-index: 20; top: calc(52px + env(safe-area-inset-top, 0px)); right: calc(14px + env(safe-area-inset-right, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: min(470px, calc(100vw - 28px)); display: flex; flex-direction: column; border-radius: 12px; background: rgba(8, 12, 22, 0.97);
  border: 1px solid rgba(255,255,255,0.14); box-shadow: 0 10px 40px rgba(0,0,0,0.6); }
.help-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--panel-border); }
.help-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0.04em; color: #f0e2c4; }
.help-body { overflow: auto; padding: 6px 14px 16px; font-size: 12.5px; line-height: 1.45; }
.help-body h3 { margin: 14px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--amber); font-weight: 600; }
.help-body p { margin: 6px 0; color: #b3bccb; }
.help-body dl { margin: 0; }
.help-body dt { font-family: var(--mono); font-size: 12px; color: var(--ui-text); margin-top: 6px; overflow-wrap: anywhere; }
.help-body dd { margin: 1px 0 0 12px; color: var(--muted); }
.help-body code { font-family: var(--mono); font-size: 12px; color: var(--ui-text); }

@media (prefers-reduced-motion: reduce) { .title-overlay { transition: none; } }

/* ---------- phone ---------- */
@media (max-width: 34rem) {
  :root { --code-size: 16px; --code-lh: 22px; }
  body { padding: calc(44px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px)); }
  a.home { top: calc(10px + env(safe-area-inset-top, 0px)); left: calc(10px + env(safe-area-inset-left, 0px)); }
  .hud { top: calc(10px + env(safe-area-inset-top, 0px)); right: calc(10px + env(safe-area-inset-right, 0px)); }
  .title-overlay { top: var(--ov-top); padding: 5px 12px; border-radius: 9px; background: rgba(8,10,18,0.8); transition: opacity 0.5s ease; max-width: calc(100vw - 28px); }
  .title-overlay h1 { font-size: 15px; }
  .title-overlay p { font-size: 10.5px; margin-top: 1px; }
  .bar { gap: 5px 6px; padding: 5px; }
  .btn { min-height: 36px; padding: 0 8px; font-size: 12.5px; }
  .btn kbd { display: none; }
  .btn.go { min-width: 62px; }
  .tabs { display: flex; }
  select { min-height: 36px; font-size: 12.5px; padding: 0 3px; max-width: 11em; }
  main { grid-template-columns: minmax(0, 1fr); margin-top: 8px; }
  body.tab-code .turtle-col { display: none; }
  body.tab-turtle .code-col { display: none; }
  .editor { flex: 5 1 0; }
  .outwrap { flex: 3 1 0; }
  .gutter { min-width: 2.4em; padding-right: 6px; }
  textarea#code { padding: 8px; }
  .out { font-size: 12.5px; }
  #repl { font-size: 16px; }
  .help { top: calc(8px + env(safe-area-inset-top, 0px)); right: 8px; left: 8px; bottom: 8px; width: auto; }
  /* the title overlay sits at --ov-top, just below the toolbar: keep that band free for good,
     so the canvas never moves when the overlay fades */
  .turtle-col { padding-top: var(--ov-band); }
  .canvas-box { justify-content: flex-start; }
}
@media (max-width: 34rem) and (prefers-reduced-motion: reduce) { .title-overlay { transition: none; } }
