/* Babel: a quiet reading-room look, deliberately unlike the canvas toys. */
:root {
  --paper: #efe8d8;
  --sheet: #fbf8f0;
  --ink: #26221b;
  --muted: #6d6555;
  --line: rgba(38, 34, 27, 0.14);
  --accent: #8a3b12;
  --mark: #f6d98a;
  --raised: rgba(38, 34, 27, 0.06);
  --serif: "DM Serif Display", Georgia, serif;
  --sans: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17150f;
    --sheet: #211e16;
    --ink: #ebe4d3;
    --muted: #a39a86;
    --line: rgba(235, 228, 211, 0.14);
    --accent: #e7a366;
    --mark: #6b4d12;
    --raised: rgba(235, 228, 211, 0.07);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding: 0 max(20px, env(safe-area-inset-right)) 80px max(20px, env(safe-area-inset-left));
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.top { max-width: 720px; margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 0 0; }
.back {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px 0 10px; margin-left: -10px;
  border-radius: 999px; color: var(--muted); text-decoration: none; font-size: 14px;
}
.back:hover { color: var(--ink); background: var(--raised); }

main { max-width: 720px; margin: 0 auto; }

.intro { padding: 28px 0 26px; }
h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(3rem, 12vw, 5rem); line-height: 1; letter-spacing: -0.02em; }
.lede { margin-top: 18px; font-size: clamp(1.05rem, 2.6vw, 1.2rem); color: var(--muted); max-width: 34em; }
.lede em { color: var(--ink); font-family: var(--serif); font-size: 1.08em; }

/* ── Search ── */
.search label { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.search textarea {
  display: block; width: 100%; resize: vertical; min-height: 68px;
  padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--sheet); color: var(--ink);
  font-family: var(--mono); font-size: 16px; line-height: 1.5;
}
.search textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search textarea::placeholder { color: var(--muted); opacity: 0.7; }
.search-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-top: 12px; }
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--raised); }
.seg button { min-height: 38px; padding: 0 12px; border-radius: 7px; font-size: 13.5px; color: var(--muted); }
.seg button.active { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
.primary {
  min-height: 44px; padding: 0 22px; border-radius: 999px;
  background: var(--accent); color: var(--sheet); font-weight: 500; font-size: 15px;
}
.primary:hover { filter: brightness(1.1); }
.note { margin-top: 10px; font-size: 13px; color: var(--muted); }

/* ── Result ── */
.result { margin-top: 34px; }
.found { font-family: var(--serif); font-size: clamp(1.25rem, 3.6vw, 1.6rem); line-height: 1.3; min-height: 1.3em; }
.found small { display: block; margin-top: 6px; font-family: var(--sans); font-size: 14px; color: var(--muted); }

.address { margin-top: 18px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; font-size: 14px; }
.lbl { font-size: 11.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-right: 6px; }
.address-line { display: flex; align-items: baseline; gap: 4px 8px; flex-wrap: wrap; }
.address code { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; min-width: 0; flex: 1 1 60%; }
.address code.open { flex-basis: 100%; max-height: 180px; overflow-y: auto; padding: 8px 0; }
.address-grid { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.address-grid b { font-weight: 600; font-variant-numeric: tabular-nums; }
.link { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; font-size: 14px; min-height: 32px; }

.page {
  margin-top: 16px;
  padding: clamp(16px, 4vw, 34px) 0;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 1px 0 var(--line), 0 14px 30px -18px rgba(0, 0, 0, 0.35);
  display: flex; justify-content: center;
  overflow: hidden;
}
.page pre {
  font-family: var(--mono);
  /* 40 characters of a 0.6em-wide monospace must fit the narrowest phone */
  font-size: clamp(10.5px, calc((100vw - 76px) / 24.4), 17px);
  line-height: 1.55;
  white-space: pre;
  transition: opacity 0.18s;
}
.page pre.turning { opacity: 0.25; }
.page mark { background: var(--mark); color: inherit; border-radius: 2px; }

.nav { display: flex; gap: 8px; margin-top: 14px; }
.nav button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); font-size: 14px; font-weight: 500; white-space: nowrap;
}
.nav button:hover { background: var(--raised); }
.share { margin-top: 12px; text-align: center; font-size: 14px; color: var(--muted); }
#copied { margin-left: 10px; }

.how { margin-top: 56px; padding-top: 30px; border-top: 1px solid var(--line); }
.how h2 { font-family: var(--serif); font-weight: 400; font-size: 1.7rem; margin-bottom: 12px; }
.how p { color: var(--muted); max-width: 38em; }
.how p + p { margin-top: 12px; }
.how strong { color: var(--ink); font-weight: 500; }
.credit { font-size: 13.5px; }

@media (max-width: 520px) {
  .nav button span { display: none; }
  .nav #random { flex: 2; }
  .search-row { flex-direction: column; align-items: stretch; }
  .seg { display: flex; }
  .seg button { flex: 1; padding: 0 6px; }
}
