/* ==========================================================================
   Collaborative AI Canvas — styles
   1. Tokens & reset
   2. Canvas surface
   3. Top bar (48h clock / round countdown / entries / frozen banner)
   4. Info button + about popover
   5. FAB + draw hint + pill
   6. Toasts
   7. Bottom sheet
   8. Buttons & form controls
   8b. Feedback bug + dialog
   8c. Prompt feed (sidebar / slide-over panel)
   9. Refine toolbar (stage 2 of drawing)
   10. Motion preferences / wide screens
   ========================================================================== */

/* -- 1. Tokens & reset ---------------------------------------------------- */

:root {
  --bg: #111111;
  --bg-elev: #1b1b1d;
  --bg-elev-2: #232326;
  --line: #303035;
  --ink: #f2f2f3;
  --ink-dim: #a0a0a8;
  --ink-faint: #6d6d76;
  --accent: #ffffff;
  --accent-ink: #111111;
  --danger: #ff6b5e;
  --good: #58d68d;
  --radius: 16px;
  --tap: 44px;
  /* The feed sidebar takes real estate away from the canvas on wide screens.
     --ui-right is how much, and every right-anchored or centred piece of
     chrome offsets by it so nothing ends up underneath the panel. */
  --feed-w: 300px;
  --ui-right: 0px;
  --canvas-cx: calc(50% - var(--ui-right) / 2);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

a { color: var(--ink); text-underline-offset: 3px; }
a:hover { color: #fff; }

button { font: inherit; color: inherit; }

/* -- 2. Canvas surface ---------------------------------------------------- */

/* Width is stated explicitly rather than left to `auto`: a canvas with an auto
   width takes its intrinsic size from the width *attribute*, which the render
   loop sets in device pixels — so `auto` would let the element grow itself
   bigger on every resize. --ui-right is the feed column on wide screens. */
#canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: calc(100% - var(--ui-right));
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  background: var(--bg);
}
#canvas.is-panning { cursor: grabbing; }
body.mode-draw #canvas { cursor: crosshair; }

/* -- 3. Top bar ----------------------------------------------------------- */

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 10px + var(--ui-right)) 0 calc(var(--safe-l) + 10px);
  pointer-events: none;
}

#bar {
  pointer-events: auto;
  margin-left: calc(var(--tap) + 4px); /* clear the fixed ⓘ button */
  background: rgba(24, 24, 26, 0.82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 8px 11px 9px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
}

/* The 48-hour clock leads: it is the thing that makes this an event. The round
   countdown sits under it as a labelled secondary line. */
#eventRow {
  display: flex;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
}

.icon-hourglass {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: var(--ink-dim);
  align-self: center;
}

#eventLeft {
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}

#eventSuffix {
  font-size: 12px;
  color: var(--ink-dim);
}

#eventRow .stat-dot { margin-left: auto; align-self: center; }

#roundRow {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 3px;
  margin-bottom: 7px;
  font-size: 12.5px;
  letter-spacing: 0.01em;
  color: var(--ink-dim);
  white-space: nowrap;
}

#roundLine { overflow: hidden; text-overflow: ellipsis; }
#countdown {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Sits immediately after the countdown, not pushed to the far edge — the two
   numbers are meant to be read together as the round fills up. */
#entriesHint {
  flex: 0 0 auto;
  padding: 1px 8px;
  border-radius: 999px;
  background: #2c2c32;
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#progress {
  height: 4px;
  border-radius: 999px;
  background: #37373d;
  overflow: hidden;
}

#progressFill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transform-origin: left center;
  transition: width 240ms linear;
}
#progressFill.is-low { background: var(--danger); }

.stat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex: 0 0 auto;
}
.stat-dot.is-live { background: var(--good); }
.stat-dot.is-down { background: var(--danger); }

#frozenBanner {
  pointer-events: auto;
  margin-left: calc(var(--tap) + 4px);
  margin-top: 0;
  background: rgba(24, 24, 26, 0.9);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 11px 13px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
}

/* -- 4. Info button + about popover --------------------------------------- */

#infoBtn {
  position: fixed;
  z-index: 40;
  top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 10px);
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(24, 24, 26, 0.82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--ink-dim);
  cursor: pointer;
}
#infoBtn:hover, #infoBtn[aria-expanded="true"] { color: var(--ink); }
#infoBtn svg { width: 21px; height: 21px; }

#about {
  position: fixed;
  z-index: 41;
  top: calc(var(--safe-t) + 8px + var(--tap) + 8px);
  left: calc(var(--safe-l) + 10px);
  width: min(320px, calc(100vw - var(--safe-l) - var(--safe-r) - 20px));
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px 12px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-dim);
  animation: pop 160ms ease-out;
}
#about p { margin: 0 0 9px; }
#about p:last-child { margin-bottom: 0; }
.about-anon { color: var(--ink-faint); }
.about-links { display: flex; gap: 8px; align-items: center; padding-top: 4px; }
.about-links a { color: var(--ink); }

@keyframes pop {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

/* -- 5. FAB + draw hint + pill -------------------------------------------- */

#fab {
  position: fixed;
  z-index: 35;
  right: calc(var(--safe-r) + 16px + var(--ui-right));
  bottom: calc(var(--safe-b) + 20px);
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease;
}
#fab:active { transform: scale(0.94); }
#fab svg { width: 27px; height: 27px; }
#fab .icon-close { display: none; }
body.mode-draw #fab { background: var(--danger); color: #fff; }
body.mode-draw #fab .icon-pencil { display: none; }
body.mode-draw #fab .icon-close { display: block; }

#drawHint {
  position: fixed;
  z-index: 34;
  left: var(--canvas-cx);
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 34px);
  background: rgba(24, 24, 26, 0.86);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 12.5px;
  color: var(--ink-dim);
  pointer-events: none;
  white-space: nowrap;
}

#pill {
  position: fixed;
  z-index: 34;
  left: var(--canvas-cx);
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 34px);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 10px 17px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  white-space: nowrap;
  animation: pillIn 260ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes pillIn {
  from { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.9); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* Same slot as the pill: after a lost round, one tap re-opens the sheet with
   the same shape + prompt already loaded. */
#retry {
  position: fixed;
  z-index: 34;
  left: var(--canvas-cx);
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 30px);
  min-height: var(--tap);
  /* leaves room for the feedback bug at bottom-left and the FAB at bottom-right */
  max-width: min(300px, calc(100vw - var(--safe-l) - var(--safe-r) - 150px));
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  animation: pillIn 260ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
#retry:active { transform: translateX(-50%) scale(0.96); }
#retry:hover { background: #2e2e34; }

/* #pill, #retry and #drawHint all live in the same slot above the FAB. While
   drawing or refining, the two status chips step aside for the draw hint and
   the refine toolbar — they come back on their own when the user exits. This
   matters now that submitting doesn't end your turn: you can redraw and submit
   again to replace your entry, so the pill is up while you draw. */
body.mode-draw #retry,
body.mode-refine #retry,
body.mode-draw #pill,
body.mode-refine #pill { display: none !important; }

/* -- 6. Toasts ------------------------------------------------------------ */

#toasts {
  position: fixed;
  z-index: 60;
  left: var(--canvas-cx);
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 96px);
  width: min(420px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
/* While the sheet is up, float toasts just above it (never off-screen). */
body.sheet-open #toasts {
  bottom: min(calc(var(--sheet-h, 340px) + 12px), calc(100dvh - 76px));
}

.toast {
  background: rgba(30, 30, 33, 0.95);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 15px;
  font-size: 13.5px;
  color: var(--ink);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  text-align: center;
  max-width: 100%;
  animation: toastIn 200ms ease-out;
}
.toast.is-out { animation: toastOut 220ms ease-in forwards; }
.toast.is-win { background: #fff; color: #111; border-color: #fff; font-weight: 600; }
.toast.is-error { border-color: rgba(255, 107, 94, 0.55); }

/* A toast that carries a button has to take pointer events back. */
.toast.has-action {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}
.toast-action {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.toast-action:active { transform: scale(0.96); }
.toast.is-win .toast-action { background: #111; color: #fff; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastOut {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(6px); }
}

/* -- 7. Bottom sheet ------------------------------------------------------ */

#scrim {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 220ms ease;
}
#scrim.is-open { opacity: 1; }

#sheet {
  position: fixed;
  z-index: 50;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 0 calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.6);
  transform: translateY(100%);
  transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}
#sheet.is-open { transform: translateY(var(--drag-y, 0px)); }
#sheet.is-dragging { transition: none; }

#sheetHandle {
  padding: 9px 0 6px;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
}
#sheetHandle span {
  display: block;
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: #45454c;
}

.sheet-head {
  display: flex;
  gap: 13px;
  align-items: center;
  padding: 4px 0 12px;
}
#thumb {
  width: 66px;
  height: 66px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: #0d0d0e;
  border: 1px solid var(--line);
}
.sheet-head-text h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.sheet-head-text p {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--ink-dim);
}

/* Grows with the prompt up to ~6 lines, then scrolls inside itself — long
   prompts stay comfortable without pushing the buttons under the keyboard. */
#prompt {
  display: block;
  width: 100%;
  min-height: 92px;
  max-height: 168px;
  overflow-y: auto;
  resize: none;
  padding: 12px 13px;
  font: inherit;
  font-size: 16px; /* ≥16px stops iOS zoom-on-focus */
  color: var(--ink);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
#prompt::placeholder { color: var(--ink-faint); }
#prompt:focus { border-color: #55555e; }

.counter {
  display: flex;
  justify-content: flex-end;
  font-size: 11.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  padding: 5px 2px 0;
}
.counter .is-max { color: var(--danger); }

/* Blend switch: one 44px row, no card around it — it's a default, not a decision.
   The real checkbox stays in the DOM for keyboard and a11y and drives the track. */
#blendRow {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  margin-top: 6px;
  padding: 4px 2px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.blend-text { flex: 1 1 auto; min-width: 0; display: block; }
.blend-title {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
}
/* The little "i": a quiet circle that answers "what does this toggle do?". */
#blendInfo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  padding: 0;
  border: 1px solid var(--ink-faint);
  border-radius: 50%;
  background: none;
  color: var(--ink-dim);
  font-size: 10.5px;
  font-weight: 650;
  font-style: italic;
  line-height: 1;
  vertical-align: 1px;
  cursor: pointer;
}
#blendInfo:hover { color: var(--ink); border-color: var(--ink-dim); }

#blendHint {
  margin: 2px 2px 6px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-dim);
}

.blend-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  margin: 0;
  pointer-events: none;
}

.blend-track {
  flex: 0 0 auto;
  position: relative;
  width: 40px;
  height: 23px;
  border-radius: 999px;
  background: #3a3a42;
  border: 1px solid var(--line);
  transition: background-color 150ms ease, border-color 150ms ease;
}
.blend-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform 150ms ease, background-color 150ms ease;
}
.blend-input:checked ~ .blend-track { background: #2fbf71; border-color: #2fbf71; }
.blend-input:checked ~ .blend-track::after { transform: translateX(17px); background: #fff; }
.blend-input:focus-visible ~ .blend-track { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Invisible plumbing (interaction-only): takes no space unless Cloudflare
   actually needs to show the user a challenge. */
#turnstile {
  display: flex;
  justify-content: center;
  align-items: center;
}

#sheetError {
  margin: 6px 0 0;
  padding: 9px 11px;
  font-size: 13px;
  color: #ffd9d5;
  background: rgba(255, 107, 94, 0.13);
  border: 1px solid rgba(255, 107, 94, 0.4);
  border-radius: 10px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  padding-top: 12px;
}

/* -- 8. Buttons ----------------------------------------------------------- */

.btn {
  flex: 1 1 0;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 140ms ease, transform 120ms ease;
}
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost {
  background: transparent;
  color: var(--ink-dim);
  border-color: var(--line);
  flex: 0 0 38%;
}

/* -- 8b. Feedback bug + dialog -------------------------------------------- */

#fbBtn {
  position: fixed;
  z-index: 35;
  left: calc(var(--safe-l) + 16px);
  bottom: calc(var(--safe-b) + 20px);
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(24, 24, 26, 0.7);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ink-faint);
  opacity: 0.55;
  cursor: pointer;
  transition: opacity 140ms ease, color 140ms ease, transform 120ms ease;
}
#fbBtn svg { width: 22px; height: 22px; }
#fbBtn:hover, #fbBtn:focus-visible { opacity: 1; color: var(--ink); }
#fbBtn:active { transform: scale(0.94); }

/* Never compete with the drawing tools or the prompt sheet. */
body.mode-draw #fbBtn,
body.mode-refine #fbBtn,
body.sheet-open #fbBtn { display: none !important; }

#fbScrim {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.6);
}

/* Share card: bottom-centre, no scrim — the artwork stays the hero. Sits above
   the FAB's vertical band so neither covers the other. */
#shareBox {
  position: fixed;
  z-index: 54;
  left: var(--canvas-cx);
  bottom: calc(var(--safe-b) + 96px);
  transform: translateX(-50%);
  width: min(340px, calc(100vw - var(--safe-l) - var(--safe-r) - 28px));
  padding: 14px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.5);
  /* Own keyframes: generic `pop` ends on transform:none, which would override
     the -50% centering for its whole run and make the card jump on settle. */
  animation: sharePop 240ms ease-out;
}
@keyframes sharePop {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%); }
}

#fbBox {
  position: fixed;
  z-index: 56;
  left: var(--canvas-cx);
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(400px, calc(100vw - var(--safe-l) - var(--safe-r) - 28px));
  max-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 40px);
  overflow-y: auto;
  padding: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
  animation: pop 160ms ease-out;
}
#shareBox h2,
#fbBox h2 {
  margin: 0 0 10px;
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
#shareBox p {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-dim);
}
#fbText {
  display: block;
  width: 100%;
  min-height: 104px;
  max-height: 220px;
  resize: none;
  padding: 11px 12px;
  font: inherit;
  font-size: 16px; /* ≥16px stops iOS zoom-on-focus */
  color: var(--ink);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
#fbText::placeholder { color: var(--ink-faint); }
#fbText:focus { border-color: #55555e; }
#fbError {
  margin: 6px 0 0;
  padding: 9px 11px;
  font-size: 13px;
  color: #ffd9d5;
  background: rgba(255, 107, 94, 0.13);
  border: 1px solid rgba(255, 107, 94, 0.4);
  border-radius: 10px;
}

/* -- 8c. Prompt feed ------------------------------------------------------
   Same markup in both modes. On phones it is a slide-over panel behind the 💬
   button; from 900px up it becomes a permanent column and the canvas element
   is inset to match, so the artboard re-centres in what's left of the window
   without any special-casing in the render loop. ------------------------- */

#feedBtn {
  position: fixed;
  z-index: 40;
  top: calc(var(--safe-t) + 8px);
  right: calc(var(--safe-r) + 10px);
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(24, 24, 26, 0.82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--ink-dim);
  cursor: pointer;
}
#feedBtn:hover, #feedBtn[aria-expanded="true"] { color: var(--ink); }
#feedBtn svg { width: 22px; height: 22px; }
#feedBtn.has-new::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
}
body.mode-draw #feedBtn,
body.mode-refine #feedBtn,
body.sheet-open #feedBtn { display: none !important; }

#feedScrim {
  position: fixed;
  inset: 0;
  z-index: 43;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 220ms ease;
}
#feedScrim.is-open { opacity: 1; }

#feed {
  position: fixed;
  z-index: 44;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(85vw, 340px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 44px rgba(0, 0, 0, 0.55);
  transform: translateX(100%);
  transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}
#feed.is-open { transform: translateX(0); }
#feed.is-dragging { transition: none; }

#feedHead {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-t) + 10px) 8px 10px calc(var(--safe-l) + 14px);
  border-bottom: 1px solid var(--line);
}
#feedHead h2 {
  flex: 1 1 auto;
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
/* Only there once history browsing has pushed the newest rows out. */
#feedTop {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--ink-dim);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
#feedTop:hover { color: var(--ink); background: #2e2e34; }

#feedClose {
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
}
#feedClose:hover { color: var(--ink); background: var(--bg-elev-2); }
#feedClose svg { width: 18px; height: 18px; }

#feedList {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px 10px calc(var(--safe-b) + 14px) calc(var(--safe-l) + 10px);
}

#feedStatus {
  padding: 14px 6px 4px;
  font-size: 12px;
  color: var(--ink-faint);
  text-align: center;
}
#feedStatus:empty { display: none; }

/* One prompt. The whole row is the target: tapping flies the canvas to it.
   One visual variable only (V2.5): every row shares the same flat fill, and
   status lives in a 3px left rail — amber = won, coral = yours. Calmer than
   the old tinted-fill-plus-tinted-border look. */
.fe {
  position: relative;
  padding: 9px 10px 9px 12px;
  margin-bottom: 6px;
  border-left: 3px solid transparent;
  border-radius: 11px;
  background: var(--bg-elev-2);
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, opacity 220ms ease;
}
.fe:hover { background: #2a2a2f; }
.fe:active { transform: scale(0.995); }

.fe-top {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 11.5px;
  line-height: 1.3;
}
.fe-who {
  font-weight: 650;
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}
.fe-time {
  margin-left: auto;
  flex: 0 0 auto;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.fe-trophy { flex: 0 0 auto; }

/* Share link on won rows. Bigger hit area than its glyph; quiet until hover. */
.fe-share {
  flex: 0 0 auto;
  margin: -4px 0;
  padding: 4px 6px;
  border: none;
  border-radius: 7px;
  background: none;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.65;
}
.fe-share:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }

.fe-prompt {
  font-size: 13px;
  line-height: 1.42;
  color: var(--ink);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow-wrap: anywhere;
}
.fe.is-expanded .fe-prompt {
  -webkit-line-clamp: unset;
  line-clamp: unset;
  display: block;
}

.fe-more {
  margin-top: 3px;
  padding: 2px 0;
  border: none;
  background: none;
  color: var(--ink-dim);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.fe-more:hover { color: var(--ink); }

/* Yours: coral rail + the "you:" label. */
.fe.is-mine { border-left-color: var(--danger); }
.fe.is-mine .fe-who { color: var(--danger); }

/* Won: amber rail + the trophy. A win of yours keeps the amber rail — the
   "you:" label already says whose it is. */
.fe.is-won { border-left-color: #ffc740; }

/* Lost: still readable, just stepped back. */
.fe.is-lost { opacity: 0.52; }
.fe.is-lost:hover { opacity: 0.8; }

.fe.is-new { animation: feedIn 260ms cubic-bezier(0.2, 0.9, 0.3, 1.1); }
.fe.is-bumped { animation: feedBump 900ms ease-out; }

@keyframes feedIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes feedBump {
  0%   { background: rgba(120, 205, 255, 0.35); }
  100% { background: var(--bg-elev-2); }
}

/* Wide screens: the panel stops being an overlay and becomes part of the page. */
@media (min-width: 900px) {
  :root { --ui-right: var(--feed-w); }

  /* #canvas already narrows itself via --ui-right; nothing to do here. */
  #feed {
    width: var(--feed-w);
    transform: none;
    box-shadow: none;
    transition: none;
  }
  #feedBtn, #feedScrim, #feedClose { display: none !important; }
  /* the drawing modes hide the button, but the column itself always stays */
  body.mode-draw #feed,
  body.mode-refine #feed,
  body.sheet-open #feed { display: flex; }
  #feedHead { padding-left: 14px; }
  #feedList { padding-left: 10px; }
}

/* -- 9. Refine toolbar ---------------------------------------------------- */

/* Stage 2 sits where the thumb already is: bottom of the screen, above the
   FAB slot (the FAB itself is hidden while refining — Cancel replaces it). */
#refineBar {
  position: fixed;
  z-index: 36;
  left: calc(var(--safe-l) + 8px);
  right: calc(var(--safe-r) + 8px + var(--ui-right));
  bottom: calc(var(--safe-b) + 10px);
  margin: 0 auto;
  max-width: 480px;
  padding: 8px;
  background: rgba(24, 24, 26, 0.9);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.55);
  touch-action: manipulation;
  animation: refineIn 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes refineIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

#refineSize {
  padding: 2px 4px 7px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#refineSize.is-warn { color: #ffd48a; }
#refineSize.is-bad { color: #ffb3ab; }

.refine-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.refine-row + .refine-row { padding-top: 6px; }

.rfbtn {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-elev-2);
  color: var(--ink-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 130ms ease, color 130ms ease, transform 110ms ease;
}
.rfbtn:active { transform: scale(0.96); }
.rfbtn svg { width: 17px; height: 17px; flex: 0 0 auto; }
.rfbtn.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.rfbtn[disabled] { opacity: 0.4; cursor: default; }

.rfbtn-icon {
  flex: 0 0 auto;
  width: var(--tap);
  padding: 0;
}
.rfbtn-icon svg { width: 19px; height: 19px; }

.rfseg {
  flex: 0 0 auto;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
  background: var(--bg-elev-2);
}
.rfseg button {
  width: 36px;
  min-height: var(--tap);
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.rfseg button + button { border-left: 1px solid var(--line); }
.rfseg button.is-on { background: #3a3a42; color: var(--ink); }

.refine-spacer { flex: 1 1 auto; }

/* Protect is a mode, not a brush: it reads cyan so it can't be mistaken for
   the white "selected brush" state, and it parks the brush controls. */
#rfProtect.is-on {
  background: #17515c;
  border-color: #2aa3b8;
  color: #b9f2fb;
}
body.mode-protect .rfseg,
body.mode-protect #rfAdd,
body.mode-protect #rfErase { opacity: 0.55; }
body.mode-protect #rfAdd.is-on,
body.mode-protect #rfErase.is-on {
  background: var(--bg-elev-2);
  border-color: var(--line);
  color: var(--ink-dim);
}

body.mode-refine #fab,
body.mode-refine #drawHint { display: none !important; }
body.mode-refine #toasts { bottom: calc(var(--safe-b) + 218px); }

/* -- 10. Motion preferences / wide screens -------------------------------- */

@media (min-width: 720px) {
  #sheet {
    left: var(--canvas-cx);
    right: auto;
    width: 440px;
    transform: translate(-50%, 100%);
    border-radius: 20px;
    bottom: 20px;
    border: 1px solid var(--line);
  }
  #sheet.is-open { transform: translate(-50%, var(--drag-y, 0px)); }
  body.sheet-open #toasts {
    bottom: min(calc(var(--sheet-h, 340px) + 32px), calc(100dvh - 76px));
  }
  #bar { max-width: 460px; }
  #frozenBanner { max-width: 460px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
