:root {
  --paper: #f3ead2; --paper-2: #ebdfbf; --paper-3: #e1d1a8;
  --ink: #2c3424; --ink-soft: #5d6252; --ink-faint: #8b8a74;
  --moss: #4e6b3a; --brass: #b08a4a; --rust: #a4552f;
  --line: rgba(44, 52, 36, .18);
  --serif: Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--serif); }
body { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
.loading, .error { padding: 32px 16px; text-align: center; color: var(--ink-soft); }

/* landing and level picker */
.page { max-width: 760px; margin: 0 auto; padding: 28px max(16px, env(safe-area-inset-left)) 48px; }
.page h1 { font-weight: 400; font-size: clamp(30px, 7vw, 44px); margin: 0; line-height: 1.1; }
.page .latin { font-style: italic; color: var(--ink-soft); margin: 4px 0 20px; }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.level { display: block; text-decoration: none; color: inherit; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.level img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--paper-2); }
.level div { padding: 10px 12px 12px; }
.level b { display: block; font-size: 18px; }
.level span { color: var(--ink-soft); font-size: 14px; }
.level .prog { color: var(--moss); }
.credit { margin-top: 28px; font-size: 13px; color: var(--ink-faint); }
.credit a { color: inherit; }
.kits { list-style: none; padding: 0; } .kits a { color: var(--ink); font-size: 20px; }

/* painting screen */
.paint { position: fixed; inset: 0; display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 8px; padding: max(6px, env(safe-area-inset-top)) 10px 6px;
  background: var(--paper); border-bottom: 1px solid var(--line); min-height: 52px; }
.bar .title { flex: 1; min-width: 0; line-height: 1.15; }
.bar .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 400; font-size: 18px; }
.bar .title span { font-size: 13px; color: var(--ink-soft); }
.icon { width: 44px; height: 44px; border-radius: 22px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; }
.icon:active { background: var(--paper-2); }
.icon svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stage { position: relative; flex: 1; overflow: hidden; background: #e9e4d8; touch-action: none; }
.stage canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.tools { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 8px; }
.tools .icon { background: rgba(255,255,255,.92); box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.toast { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 8px 14px; border-radius: 18px; font: 14px var(--sans); opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: .92; }
.palette { display: flex; gap: 8px; overflow-x: auto; padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1px solid var(--line); scrollbar-width: thin; }
.chip { flex: 0 0 auto; width: 54px; border: 2px solid transparent; border-radius: 12px; background: transparent; padding: 3px; cursor: pointer; text-align: center; }
.chip i { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 9px; font: 600 15px var(--sans); font-style: normal;
  border: 1px solid rgba(0,0,0,.18); }
.chip small { display: block; font: 11px var(--sans); color: var(--ink-soft); margin-top: 2px; }
.chip[aria-pressed="true"] { border-color: var(--ink); background: #fff; }
.chip.done { opacity: .45; }
.done-panel { position: absolute; inset: auto 12px 12px 12px; background: #fff; border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 4px 18px rgba(0,0,0,.2); text-align: center; }
.done-panel b { font-size: 20px; font-weight: 400; display: block; margin-bottom: 8px; }
.btn { border: 0; border-radius: 22px; padding: 10px 18px; background: var(--moss); color: #fff; cursor: pointer; margin: 4px; }
.btn.ghost { background: var(--paper-2); color: var(--ink); }
