:root {
  --bg: #f5f0e8;
  --surface: #fffdf9;
  --ink: #2a2520;
  --muted: #74695d;
  --line: #e2d9cc;
  --accent: #a4561f;
  --accent-ink: #ffffff;
  --ok: #2f7d4f;
  --open: #8a5700;
  --fail: #b3362b;
  --info: #74695d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(42, 37, 32, .06), 0 4px 16px rgba(42, 37, 32, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a17;
    --surface: #26221e;
    --ink: #efe8de;
    --muted: #a99d8f;
    --line: #3a342e;
    --accent: #e08a4c;
    --accent-ink: #1d1a17;
    --ok: #6cc28f;
    --open: #e2a94a;
    --fail: #ef7a6e;
    --info: #a99d8f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* a rule's display (buttons: inline-flex) must not undo it */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button, .button {
  font: inherit; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); padding: .5rem 1rem; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; min-height: 44px;
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; }
button.icon { width: 44px; justify-content: center; padding: 0; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- the frame ------------------------------------------------------------------- */

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .5rem max(16px, env(safe-area-inset-left)); padding-top: max(.5rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; letter-spacing: .01em; }
.top-actions { display: flex; align-items: center; gap: .25rem; }
#share svg { width: 22px; height: 22px; }
#install svg { width: 22px; height: 22px; }
#install[hidden] { display: none; }
@media (max-width: 420px) { .top { gap: .5rem; } .top-actions { gap: .15rem; } .chip { padding: .3rem .6rem; } }
.toast {
  position: fixed; top: 4rem; left: 50%; transform: translateX(-50%); z-index: 10; margin: 0;
  background: var(--ink); color: var(--bg); padding: .45rem .9rem; border-radius: 999px; font-size: .9rem;
}
.toast:empty { display: none; }
.chip { white-space: nowrap; }
.chip { min-height: 36px; padding: .3rem .8rem; font-size: .9rem; }
.chip .dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); }
.chip.ready .dot { background: var(--ok); }

main {
  max-width: 1040px; margin: 0 auto;
  padding: 1.25rem 16px calc(9rem + env(safe-area-inset-bottom));
}
main:focus { outline: none; }

/* --- the prompt bar --------------------------------------------------------------- */

.ask {
  position: fixed; left: 0; right: 0; bottom: var(--keyboard, 0px); z-index: 5;
  padding: .5rem 16px max(.5rem, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
/* The prompt field as chat apps draw it: one rounded box, the text growing from one line to a
   few, and a round send button inside it at the bottom right. */
.composer {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: .25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
  padding: 5px 5px 5px 16px; box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: transparent; color: var(--ink);
  font-family: inherit; font-size: 16px; line-height: 1.4; padding: 9px 0; margin: 0; min-height: 40px; max-height: 30vh;
}
button.send {
  flex: none; width: 38px; height: 38px; min-height: 0; padding: 0; justify-content: center;
  border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
}
button.send svg { width: 20px; height: 20px; }
button.send:disabled { background: var(--line); color: var(--muted); opacity: 1; }
.ask-note { max-width: 760px; margin: .35rem auto 0; font-size: .85rem; color: var(--muted); min-height: 0; }
.ask-note:empty { display: none; }

/* --- the list of pieces ----------------------------------------------------------- */

.page-head { margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.page-head button { min-height: 40px; }
.form { display: grid; gap: 1rem; }
.form label { display: grid; gap: .35rem; font-weight: 600; font-size: .95rem; }
.form input[type=text], .form textarea, .form select {
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; width: 100%;
}
.form textarea { resize: vertical; min-height: 6rem; }
.form input:focus, .form textarea:focus, .form select:focus { outline: none; border-color: var(--accent); }
.form input[type=file] { font: inherit; font-size: .95rem; font-weight: 400; }
.form p { margin: 0; }
.form-error { color: var(--fail); }
.form-error:empty { display: none; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; color: inherit; text-decoration: none; box-shadow: var(--shadow);
}
.card:hover { border-color: var(--accent); }
.thumb { aspect-ratio: 4 / 3; background: var(--bg); display: grid; place-items: center; border-bottom: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumb .letter { font-size: 3rem; color: var(--muted); font-weight: 600; }
.card-body { padding: .8rem 1rem 1rem; display: grid; gap: .25rem; }
.card-body h2 { font-size: 1.05rem; }
.meta { font-size: .88rem; color: var(--muted); }
.badge { justify-self: start; font-size: .8rem; padding: .1rem .55rem; border-radius: 999px; border: 1px solid currentColor; }
.badge.open { color: var(--open); }
.badge.fail { color: var(--fail); }
.badge.ok { color: var(--ok); }
.empty { padding: 2rem 0; }

/* --- one piece -------------------------------------------------------------------- */

.back { display: inline-block; margin-bottom: .75rem; font-size: .92rem; text-decoration: none; }
.title-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem .75rem; }
.version { font-size: .85rem; padding: .1rem .55rem; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.piece { display: grid; gap: 1.25rem; }
.layout { display: grid; gap: 1.25rem; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
  .layout > .side { position: sticky; top: 4.5rem; }
}
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.panel > h2 { margin-bottom: .6rem; }

/* A wide screen: the page is as tall as the window, the 3D view fills what the title and the
   prompt bar leave, and only the column beside it scrolls. */
body.desk-on { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.desk-on main {
  flex: 1; min-height: 0; width: 100%; max-width: none; display: flex; flex-direction: column;
  padding: 1rem 24px calc(var(--ask-h, 5rem) + 1rem);
}
.desk { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 1rem; }
/* The title takes one line, so the height goes to the 3D view. */
.desk-head { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .75rem; }
.desk-head .back { margin: 0 .5rem 0 0; }
.desk-head .badge { justify-self: auto; }
.desk-body {
  flex: 1; min-height: 0; display: grid; gap: 1.25rem;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 24vw, 480px);
}
.desk-view { padding: 0; overflow: hidden; background: #fff; position: relative; }
.desk-view iframe { display: block; width: 100%; height: 100%; border: 0; }
.desk-full { position: absolute; left: 12px; bottom: 12px; box-shadow: var(--shadow); }
.desk-side { min-height: 0; overflow-y: auto; display: grid; gap: 1rem; align-content: start; overscroll-behavior: contain; padding: 2px; }

.tiles { display: grid; gap: .75rem; align-content: start; }
.tile {
  display: flex; align-items: center; gap: .9rem; width: 100%; text-align: left;
  border-radius: var(--radius); padding: .9rem 1rem; background: var(--surface); box-shadow: var(--shadow);
}
.tile:hover { border-color: var(--accent); }
.tile-icon { flex: none; width: 48px; height: 48px; border-radius: 10px; background: var(--bg); color: var(--accent); display: grid; place-items: center; }
.tile-icon svg { width: 28px; height: 28px; }
.tile-body { flex: 1; min-width: 0; display: grid; gap: .15rem; }
.tile-title { font-weight: 600; font-size: 1.05rem; }
.tile-sum { color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .chev { flex: none; color: var(--muted); font-size: 1.5rem; line-height: 1; }
.sum-fail { color: var(--fail); }
.sum-open { color: var(--open); }
.sum-ok { color: var(--ok); }
.error { border-color: var(--fail); }
.error pre { white-space: pre-wrap; font-size: .8rem; overflow-x: auto; color: var(--muted); }

.files { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
.files a { display: flex; justify-content: space-between; gap: .75rem; padding: .55rem .2rem; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); min-height: 44px; align-items: center; }
.files li:last-child a { border-bottom: 0; }
.files .kind { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.files a:hover .label { color: var(--accent); }
.sketches { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.sketches img { height: 96px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
details > summary { cursor: pointer; padding: .4rem 0; color: var(--muted); min-height: 44px; display: flex; align-items: center; }
.actions { margin-top: .75rem; display: flex; gap: .5rem; flex-wrap: wrap; }

.findings { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.findings li { display: grid; grid-template-columns: 1.4rem 1fr; gap: .5rem; }
.findings .mark { font-weight: 700; text-align: center; }
.findings .ok .mark { color: var(--ok); }
.findings .open .mark { color: var(--open); }
.findings .fail .mark { color: var(--fail); }
.findings .info .mark { color: var(--info); }
.findings .req { font-weight: 600; }
.findings .res { color: var(--muted); font-size: .92rem; }
.note-lang { font-size: .82rem; margin: .6rem 0 0; }

.prose { overflow-wrap: anywhere; }
.prose h1, .prose h2, .prose h3 { margin: 1rem 0 .4rem; font-size: 1.05rem; }
.prose ul, .prose ol { padding-left: 1.3rem; margin: .4rem 0; }
.prose p { margin: .5rem 0; }
.prose code { font-size: .9em; background: var(--bg); padding: 0 .25rem; border-radius: 4px; }
.prose .table { overflow-x: auto; margin: .6rem 0; }
.prose table { border-collapse: collapse; font-size: .9rem; min-width: 100%; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: .35rem .5rem; text-align: left; vertical-align: top; overflow-wrap: normal; }
.prose th { font-weight: 600; }
.history { list-style: none; padding: 0; margin: 0; font-size: .9rem; display: grid; gap: .3rem; }

/* --- the assistant setup ---------------------------------------------------------- */

dialog {
  border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.setup { padding: 1rem 1.1rem 1.2rem; display: grid; gap: .8rem; }
.setup-head { display: flex; justify-content: space-between; align-items: center; }
.choices { display: flex; flex-wrap: wrap; gap: .5rem; }
.choices button[aria-checked="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.steps { margin: 0; padding-left: 1.3rem; display: grid; gap: .35rem; }
.copyrow { display: flex; align-items: center; margin-top: .35rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.copyrow code { font-size: .85rem; padding: .4rem .6rem; overflow-wrap: anywhere; flex: 1; min-width: 0; }
.copyrow button { flex: none; color: var(--ink); }
.copyrow svg { width: 20px; height: 20px; }
.connected { color: var(--ok); font-weight: 600; margin: 0; }

/* --- a card's sheet --------------------------------------------------------------- */

body:has(dialog[open]) { overflow: hidden; }
dialog.sheet { width: min(760px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
dialog.sheet[open] { display: flex; flex-direction: column; }
.sheet-head {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .5rem .5rem 1.1rem;
  border-bottom: 1px solid var(--line); flex: none;
}
.sheet-head h2 { flex: 1; min-width: 0; font-size: 1.05rem; }
.sheet-extra .button { min-height: 36px; font-size: .85rem; padding: .3rem .8rem; }
.sheet-body { overflow-y: auto; padding: 1rem 1.1rem 1.4rem; overscroll-behavior: contain; }
dialog.sheet.full, dialog.sheet.full[open] { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; border: 0; border-radius: 0; }
dialog.sheet.full .sheet-body { flex: 1; padding: 0; overflow: hidden; background: #fff; }
dialog.sheet.full iframe { display: block; width: 100%; height: 100%; border: 0; }
@media (max-width: 640px) {
  dialog.sheet[open] { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; border: 0; border-radius: 0; }
  .sheet-head { padding-top: max(.5rem, env(safe-area-inset-top)); }
}

.signin { max-width: 420px; margin: 18vh auto 0; padding: 0 16px; display: grid; gap: .5rem; }
body.plain main.signin { padding-bottom: 2rem; }
.install-page { text-align: center; justify-items: center; }
.install-page img { border-radius: 16px; }
.install-page button { min-width: 10rem; justify-content: center; }

/* --- sharing a piece (app/shares.py) ---------------------------------------------- */

.guest #ask, .guest #assistant { display: none; }
.page-head.later { margin-top: 2rem; }
.banner {
  display: grid; gap: .5rem; padding: .75rem 1rem; margin: 0 0 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.banner p { margin: 0; }
.banner-actions { display: flex; justify-content: flex-end; gap: .25rem; }
.banner-actions .button { background: transparent; border-color: transparent; }
.banner-actions .button, button.text { color: var(--accent); font-weight: 600; }
.sharing { margin-top: 1.25rem; }
.sharing h3 { font-size: .9rem; font-weight: 600; margin: 1rem 0 .25rem; }
.sharing p { margin: .75rem 0 0; font-size: .9rem; }
/* Language Coach's box: the label, its (i) and the switch on one row; the switch as iOS draws it,
   a white knob that shows on the light and the dark panel alike. */
.switch-row { display: flex; align-items: center; gap: .25rem; min-height: 44px; }
.switch-row .label { flex: 1 1 auto; }
button.about-i { min-width: 32px; min-height: 32px; padding: 4px; justify-content: center; color: var(--muted); }
button.about-i svg { width: 15px; height: 15px; }
button.about-i[aria-expanded="true"] { color: var(--ink); }
.sharing .pop { margin: .25rem 0 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.sharing .pop p { margin: 0; font-size: .92rem; }
button.switch {
  flex: none; width: 51px; min-height: 31px; height: 31px; padding: 0; border-radius: 999px;
  background: rgba(120, 120, 128, .24); border: 0; position: relative;
}
button.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16); transition: left .15s;
}
@media (prefers-color-scheme: dark) { button.switch { background: rgba(120, 120, 128, .42); } }
button.switch[aria-checked="true"] { background: var(--accent); }
button.switch[aria-checked="true"]::after { left: 22px; }
@media (prefers-reduced-motion: reduce) { button.switch::after { transition: none; } }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; justify-content: space-between; gap: .75rem; min-height: 44px; border-bottom: 1px solid var(--line); }
.people li:last-child { border-bottom: 0; }
.people .who { min-width: 0; overflow-wrap: anywhere; display: flex; align-items: center; }
.people .mark { flex: none; display: inline-flex; margin-right: 12px; color: var(--muted); }
.people .mark svg { width: 20px; height: 20px; }
.people button.text { padding-inline: 0; }
dialog.confirm form { padding: 1.1rem 1.1rem 1rem; }
dialog.confirm p { margin: 0; }
dialog.confirm .actions { justify-content: flex-end; }
