:root {
  --paper: #ffffff;
  --ink: #000000;
  --you: #888888;
  --ui: color-mix(in srgb, var(--ink) 70%, var(--paper));
  --panel: color-mix(in srgb, var(--paper) 88%, transparent);
  --line: color-mix(in srgb, var(--ink) 16%, transparent);
  font: 400 11px/1.3 ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
main { position: fixed; inset: 0; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: default; }
canvas.over { cursor: grab; }
canvas.dragging { cursor: grabbing; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.chrome {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 0 max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  pointer-events: none; color: var(--ui);
}
.chrome > * { pointer-events: auto; }
.chrome-right { display: flex; gap: 4px; align-items: center; }
.icon-btn {
  width: 36px; height: 36px; padding: 6px; border-radius: 50%; display: grid; place-items: center; color: var(--ink);
  /* A soft backing keeps the icons readable when letters pile up behind them. */
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.icon-btn:hover { background: var(--paper); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
kbd {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 5px;
  font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink);
  border: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 70%, transparent);
}

.keys {
  position: fixed; left: 12px; bottom: 56px; z-index: 3; padding: 14px 16px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4);
  box-shadow: 0 24px 60px -24px color-mix(in srgb, var(--ink) 40%, transparent);
}
.keys[hidden] { display: none; }
.keys dl { margin: 0; display: grid; gap: 6px; }
.keys dl > div { display: grid; grid-template-columns: 136px auto; align-items: center; column-gap: 12px; }
.keys dt { display: flex; gap: 3px; align-items: center; }
.keys .plus { font-size: 11px; color: var(--ui); margin: 0 1px; }
.keys dd { margin: 0; font-size: 12px; color: var(--ui); }
button { font: inherit; color: inherit; background: none; border: 0; padding: 4px 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

#editor {
  position: fixed; top: 12px; right: 12px; bottom: 12px; width: 380px; z-index: 3;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  border-radius: 20px; overflow: hidden; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4);
  box-shadow: 0 24px 60px -24px color-mix(in srgb, var(--ink) 40%, transparent);
  transition: opacity .25s ease, transform .4s cubic-bezier(.2, 1.2, .4, 1);
}
#editor[hidden] { display: grid; opacity: 0; transform: translateX(40px); pointer-events: none; visibility: hidden; }

.ed-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 20px; border-bottom: 1px solid var(--line); }
.ed-head h2 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .02em; }
.title { display: flex; align-items: baseline; gap: 10px; }
.fps {
  font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 3px 6px; border-radius: 6px;
  color: var(--ui); background: color-mix(in srgb, var(--ink) 7%, transparent); font-variant-numeric: tabular-nums;
}
.fps.ok { color: #1f8a3b; } .fps.slow { color: #b7791f; } .fps.bad { color: #d23b2f; }
.gravity-ctl { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; }
.gravity-ctl input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--ink); }
.gravity-ctl input[type="range"] { width: 100%; margin: 0; accent-color: var(--ink); }
.dir-pad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.dir-pad button { padding: 6px 0; border-radius: 8px; border: 1px solid var(--line); color: var(--ink); font-size: 14px; line-height: 1; }
.dir-pad button:hover { background: var(--line); }
.dir-pad button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.dir-pad.off button[aria-pressed="true"] { background: transparent; color: var(--ink); border-color: var(--ink); }
.close {
  width: 34px; height: 34px; padding: 0; border-radius: 50%; font-size: 22px; line-height: 1;
  border: 1px solid var(--line); display: grid; place-items: center;
}
.close:hover { background: var(--line); }

.ed-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px 16px; scrollbar-width: thin; }
.group { padding: 14px 0; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.group:last-child { border-bottom: 0; }
.group h3 { margin: 0; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ui); }

#word {
  width: 100%; resize: none; overflow: hidden; display: block;
  font: 800 24px/1.12 ui-rounded, "SF Pro Rounded", system-ui, sans-serif; letter-spacing: -.01em;
  text-transform: uppercase; color: var(--ink); background: color-mix(in srgb, var(--ink) 5%, transparent);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
#word:focus { outline: none; border-color: var(--ink); }
.note { margin: 0; color: var(--ui); }

/* One control per row: label on the left, control filling the rest. */
.field { display: grid; grid-template-columns: 76px minmax(0, 1fr); align-items: center; gap: 12px; color: var(--ui); font-size: 12px; }
.field input[type="range"] { width: 100%; margin: 0; accent-color: var(--ink); }
.field input[type="checkbox"] { justify-self: start; width: 18px; height: 18px; margin: 0; accent-color: var(--ink); }
.field select, .field.custom input {
  width: 100%; font: 600 13px/1 inherit; font-family: inherit; color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.field.custom { grid-template-columns: minmax(0, 1fr); padding-left: 88px; }
.field.custom input { font-weight: 400; }
.field.custom:has(input[hidden]) { display: none; }
.field[hidden] { display: none; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  /* No border: a border's anti-aliased edge let the background bleed through as a coloured rim.
     The ring is drawn on top with an inset shadow instead. */
  width: 28px; height: 28px; border-radius: 50%; padding: 0; border: 0; overflow: hidden;
  /* Paper, then your ink, then Wobbly's. */
  background: linear-gradient(135deg, var(--a) 0 42%, var(--c, var(--a)) 42% 64%, var(--b) 64% 100%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 18%, transparent);
}
.swatch[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }
.colors { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; }
.link-btn { padding: 0; font: inherit; font-size: 12px; color: var(--ui); text-decoration: underline; text-underline-offset: 2px; }
.color { display: flex; align-items: center; gap: 8px; color: var(--ui); font-size: 12px; }
.color input { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 50%; padding: 0; background: none; cursor: pointer; overflow: hidden; }
.color input::-webkit-color-swatch-wrapper { padding: 0; }
.color input::-webkit-color-swatch { border: 0; border-radius: 50%; }
.color input::-moz-color-swatch { border: 0; border-radius: 50%; }

.ed-foot { padding: 12px 20px 16px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ed-foot button { padding: 9px 4px; border-radius: 999px; border: 1px solid var(--line); font-weight: 600; font-size: 12px; }
.ed-foot button:hover { background: var(--line); }
.ed-foot .primary { background: var(--ink); color: var(--paper); border-color: var(--ink); padding: 11px; }
.ed-foot .primary:hover { background: var(--ink); opacity: .9; }
.clean-opt { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ui); cursor: pointer; }
.clean-opt input { width: 16px; height: 16px; margin: 0; accent-color: var(--ink); }
/* Clean mode: only the letters. (The editor can still be opened with E.) */
body.clean .chrome, body.clean .keys { display: none; }

/* Phones: the editor becomes a bottom sheet. */
@media (max-width: 699px) {
  #editor { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 68vh; }
  #editor[hidden] { transform: translateY(30px); }
  .ed-body { padding: 0 16px 12px; }
  .ed-foot { padding: 10px 16px 14px; }
}

/* Talk button: a ring that breathes while Wobbly is listening and fills while it talks. */
.live-btn { position: relative; }
.live-btn[aria-pressed="true"] { color: var(--paper); background: var(--ink); }
.live-btn[aria-pressed="true"] svg rect { fill: currentColor; }
.live-btn::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 2px solid var(--you); opacity: 0; pointer-events: none;
}
[data-live="listening"] .live-btn::after { opacity: 1; animation: breathe 1.6s ease-in-out infinite; }
[data-live="connecting"] .live-btn::after, [data-live="reconnecting"] .live-btn::after { opacity: 1; border-style: dashed; animation: spin 2s linear infinite; }
[data-live="speaking"] .live-btn::after { opacity: 1; border-color: var(--ink); }
@keyframes breathe { 50% { transform: scale(1.18); opacity: .35; } }
@keyframes spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { .live-btn::after { animation: none !important; } }

/* The desk mic and the security camera replace their buttons; the button stays in the page for keyboard and screen readers. */
.live-btn, #cam-toggle { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); padding: 0; }
#cam-toggle[aria-pressed="true"] { color: var(--paper); background: var(--ink); }

/* Wobbly's brain: personality and knowledge. */
.wide-btn { width: 100%; margin-top: 4px; padding: 9px 12px; border-radius: 999px; border: 1px solid var(--line); font-weight: 600; font-size: 12px; display: flex; justify-content: center; gap: 8px; align-items: center; }
.wide-btn:hover { background: var(--line); }
#brain {
  width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border-radius: 20px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); box-shadow: 0 24px 60px -24px color-mix(in srgb, var(--ink) 50%, transparent);
}
#brain::backdrop { background: color-mix(in srgb, var(--ink) 25%, transparent); backdrop-filter: blur(4px); }
.brain-body { display: grid; gap: 14px; padding: 0 20px 20px; }
.brain-body .ed-head { margin: 0 -20px; }
.brain-field { display: grid; gap: 6px; font-weight: 600; font-size: 12px; }
.brain-field small { font-weight: 400; color: var(--ui); margin-left: 6px; }
.brain-field textarea {
  width: 100%; resize: vertical; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); background: color-mix(in srgb, var(--ink) 5%, transparent);
}
.brain-field textarea.drop { outline: 2px dashed var(--ink); }
.brain-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.brain-actions button, .brain-body .primary { padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); font-weight: 600; font-size: 12px; }
.brain-actions button:hover { background: var(--line); }
.brain-body .primary { background: var(--ink); color: var(--paper); border-color: var(--ink); padding: 11px; }
.brain-switch { display: flex; gap: 10px; align-items: flex-start; font-size: 12px; color: var(--ui); cursor: pointer; }
.brain-switch b { color: var(--ink); margin-right: 6px; }
.brain-switch input { margin-top: 1px; }

/* Bottom left: the ? button, and a status line that only appears with something to say (an error). */
.chrome-left { display: flex; align-items: center; gap: 10px; }
.keys-btn { font: 700 16px/1 ui-rounded, "SF Pro Rounded", system-ui, sans-serif; }
@media (hover: none) { .keys-btn { display: none; } }
.status:empty { display: none; }
.status { font-size: 12px; color: var(--ink); padding: 6px 10px; border-radius: 999px; background: color-mix(in srgb, var(--paper) 82%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
