/* Send feedback sheet (UX-004, src/feedback-ui.js). UI v2 from the start:
   tokens only (src/ui-tokens.css), the pixel frame from docs/ux-loop/UI-V2.md §2,
   everything on the 4 px grid. Self-contained: every rule is scoped to
   #feedback-dialog so older dialog/button/input rules can't leak in, and nothing
   here touches other screens. Desktop: a raised sheet docked right under the HUD
   band (top 72, right 16, 368 wide) so the player stays in view. Phones: a bottom
   sheet with 44 px targets and 16 px gutters. Type: 20 title, 16 body, 14 labels. */

#feedback-dialog {
  --fb-from: translateX(var(--ui-travel));
  position: fixed;
  inset: calc(var(--ui-s-4) + var(--ui-target) + var(--ui-s-3)) var(--ui-s-4) auto auto;
  box-sizing: border-box;
  width: min(368px, calc(100vw - var(--ui-s-6)));
  max-width: none;
  max-height: calc(100dvh - 172px);
  margin: 0;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  color: var(--ui-sheet-ink);
  background: var(--ui-frame-fill);
  border: 0;
  border-radius: 0;
  box-shadow: var(--ui-frame-raised);
  font-family: var(--ui-font-body);
  font-size: var(--ui-fs-16);
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
}
#feedback-dialog::backdrop { background: var(--ui-scrim); }
#feedback-dialog .fb-form { display: block; margin: 0; }

/* ---------- head: title + close, 1 UI px rule under it ---------- */
#feedback-dialog .fb-grab { display: none; }
#feedback-dialog .fb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ui-s-2);
  padding: var(--ui-s-3) var(--ui-s-3) var(--ui-s-3) var(--ui-s-5);
  box-shadow: inset 0 calc(var(--ui-px) * -1) 0 0 var(--ui-surface-shade);
}
#feedback-dialog .fb-title {
  margin: 0;
  color: var(--ui-ink);
  font-family: var(--ui-font-display);
  font-size: var(--ui-fs-20);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0;
}

/* ---------- body ---------- */
#feedback-dialog .fb-body { display: grid; gap: var(--ui-s-4); padding: var(--ui-s-4) var(--ui-s-5) var(--ui-s-5); }
#feedback-dialog .fb-field, #feedback-dialog .fb-moods { display: grid; gap: var(--ui-s-2); min-width: 0; margin: 0; }
#feedback-dialog .fb-label {
  display: block;
  margin: 0;
  color: var(--ui-ink);
  font-family: var(--ui-font-body);
  font-size: var(--ui-fs-14);
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: 0;
  text-transform: none;
}
#feedback-dialog .fb-optional { margin-left: var(--ui-s-1); color: var(--ui-ink-muted); font-weight: 400; }
#feedback-dialog .fb-meta {
  margin: 0;
  color: var(--ui-ink-muted);
  font-family: var(--ui-font-body);
  font-size: var(--ui-fs-14);
  font-weight: 400;
  line-height: 1.45;
}
#feedback-dialog .fb-count { justify-self: end; margin-top: calc(var(--ui-s-1) * -1); font-variant-numeric: tabular-nums; }
#feedback-dialog .fb-count.is-near { color: var(--ui-ink); font-weight: 600; }

/* The note: a flat frame with the bevel inverted, so it reads as sunk into the paper. */
#feedback-dialog .fb-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 128px;
  max-height: 40dvh;
  margin: 0;
  padding: var(--ui-s-2) var(--ui-s-3);
  resize: vertical;
  color: var(--ui-input-ink);
  background: var(--ui-frame-fill);
  border: 0;
  border-radius: 0;
  box-shadow:
    inset var(--ui-px) var(--ui-px) 0 0 var(--ui-surface-shade),
    inset calc(var(--ui-px) * -1) calc(var(--ui-px) * -1) 0 0 var(--ui-surface-hi),
    var(--ui-frame-edge);
  font-family: var(--ui-font-body);
  font-size: var(--ui-fs-16);
  line-height: 1.5;
  outline: none;
}
#feedback-dialog .fb-input::placeholder { color: var(--ui-ink-muted); opacity: 1; }

/* ---------- mood: three pixel faces as radio tiles (48 px, over the 44 px target) ---------- */
#feedback-dialog .fb-mood-row { display: flex; gap: var(--ui-s-3); }
#feedback-dialog .fb-mood-input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}
#feedback-dialog .fb-mood {
  display: grid;
  place-items: center;
  width: var(--ui-s-7);
  height: var(--ui-s-7);
  margin: 0;
  padding: 0;
  background: var(--ui-frame-fill);
  box-shadow: var(--ui-frame-rest);
  cursor: pointer;
  transition: background-color var(--ui-dur-fast) var(--ui-ease-out), transform var(--ui-dur-fast) var(--ui-ease-out);
}
#feedback-dialog .fb-mood:hover { background: var(--ui-secondary-hover); }
#feedback-dialog .fb-mood:active { box-shadow: var(--ui-frame-flat); transform: translateY(var(--ui-press)); }
#feedback-dialog .fb-mood-input:checked + .fb-mood {
  background: var(--ui-selected);
  box-shadow:
    inset var(--ui-px) var(--ui-px) 0 0 var(--ui-surface-hi),
    inset calc(var(--ui-px) * -1) calc(var(--ui-px) * -1) 0 0 var(--ui-coin-deep),
    var(--ui-frame-edge);
  transform: translateY(var(--ui-px));
}
#feedback-dialog .fb-face { display: block; image-rendering: pixelated; }
#feedback-dialog .fb-face-line { fill: var(--ui-ink-strong); }
#feedback-dialog .fb-face--happy .fb-face-fill { fill: var(--ui-coin); }
#feedback-dialog .fb-face--neutral .fb-face-fill { fill: var(--ui-surface-shade); }
#feedback-dialog .fb-face--unhappy .fb-face-fill { fill: var(--ui-info); }

/* ---------- status (errors) and actions ---------- */
#feedback-dialog .fb-status { margin: 0; color: var(--ui-danger); font-size: var(--ui-fs-14); font-weight: 600; line-height: 1.45; }
#feedback-dialog .fb-actions { display: flex; justify-content: flex-end; gap: var(--ui-s-3); }

/* Buttons: the UI v2 pixel-frame button (40 px, Pixelify 16, verb labels). */
#feedback-dialog .fb-btn {
  --f-fill: var(--ui-frame-fill);
  --f-hi: var(--ui-frame-hi);
  --f-shade: var(--ui-frame-shade);
  --f-edge: var(--ui-frame-line);
  --f-drop: var(--ui-frame-drop);
  --f-drop-y: calc(var(--ui-px) * 2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ui-s-2);
  min-width: 0;
  min-height: 40px;
  margin: 0;
  padding: 0 var(--ui-s-4);
  color: var(--ui-ink);
  background: var(--f-fill);
  border: 0;
  border-radius: 0;
  box-shadow:
    inset var(--ui-px) var(--ui-px) 0 0 var(--f-hi),
    inset calc(var(--ui-px) * -1) calc(var(--ui-px) * -1) 0 0 var(--f-shade),
    0 calc(var(--ui-px) * -1) 0 0 var(--f-edge),
    0 var(--ui-px) 0 0 var(--f-edge),
    calc(var(--ui-px) * -1) 0 0 0 var(--f-edge),
    var(--ui-px) 0 0 0 var(--f-edge),
    0 var(--f-drop-y) 0 0 var(--f-drop);
  font-family: var(--ui-font-display);
  font-size: var(--ui-fs-16);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  text-decoration: none;
  opacity: 1;
  cursor: pointer;
  filter: none;
  transition: background-color var(--ui-dur-fast) var(--ui-ease-out), transform var(--ui-dur-fast) var(--ui-ease-out);
}
#feedback-dialog .fb-btn:hover { --f-fill: var(--ui-secondary-hover); transform: none; }
#feedback-dialog .fb-btn:active:not(:disabled) { --f-drop-y: var(--ui-px); transform: translateY(var(--ui-press)); }
#feedback-dialog .fb-btn--primary {
  --f-fill: var(--ui-button-primary-bg);
  --f-hi: var(--ui-primary-hover);
  --f-shade: var(--ui-line-deep);
  --f-edge: var(--ui-line-deep);
  color: var(--ui-button-primary-ink);
}
#feedback-dialog .fb-btn--primary:hover { --f-fill: var(--ui-primary-hover); --f-hi: var(--ui-button-primary-bg); }
#feedback-dialog .fb-btn:disabled {
  --f-fill: var(--ui-disabled-bg);
  --f-hi: var(--ui-disabled-bg);
  --f-shade: var(--ui-disabled-bg);
  --f-edge: var(--ui-disabled-line);
  --f-drop-y: var(--ui-px);
  color: var(--ui-disabled-ink);
  transform: none;
  cursor: not-allowed;
}
#feedback-dialog .fb-btn--ghost { --f-fill: transparent; --f-hi: transparent; --f-shade: transparent; --f-edge: transparent; --f-drop: transparent; }
#feedback-dialog .fb-btn--ghost:hover { --f-fill: var(--ui-surface-sunk); }
#feedback-dialog .fb-btn--icon { flex: none; width: 40px; padding: 0; }
#feedback-dialog .fb-btn svg { display: block; fill: currentColor; }

/* One focus ring for everything (2 px cocoa-700, 4 px out). */
#feedback-dialog .fb-btn:focus-visible,
#feedback-dialog .fb-input:focus-visible,
#feedback-dialog .fb-mood-input:focus-visible + .fb-mood {
  outline: var(--ui-focus-ring-w) solid var(--ui-focus-ring);
  outline-offset: calc(var(--ui-px) * 2);
}

/* ---------- your notes (testers): newest first, a status chip each ---------- */
#feedback-dialog .fb-mine {
  display: grid;
  gap: var(--ui-s-2);
  margin: 0;
  padding-top: var(--ui-s-4);
  box-shadow: inset 0 var(--ui-px) 0 0 var(--ui-surface-shade);
}
#feedback-dialog .fb-mine[hidden] { display: none; }
#feedback-dialog .fb-mine-list { display: grid; gap: var(--ui-s-2); margin: 0; padding: 0; list-style: none; }
#feedback-dialog .fb-mine-item {
  display: grid;
  gap: var(--ui-s-1);
  min-width: 0;
  padding: var(--ui-s-2) var(--ui-s-3);
  background: var(--ui-surface-sunk);
  box-shadow: var(--ui-frame-flat);
}
#feedback-dialog .fb-mine-head { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-s-2); margin: 0; }
#feedback-dialog .fb-mine-text {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--ui-ink);
  font-size: var(--ui-fs-14);
  line-height: 1.45;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
#feedback-dialog .fb-mine-note { overflow-wrap: anywhere; }
#feedback-dialog .fb-chip {
  display: inline-block;
  padding: 0 var(--ui-s-2);
  color: var(--ui-ink-strong);
  background: var(--ui-frame-fill);
  box-shadow: var(--ui-frame-edge);
  font-family: var(--ui-font-body);
  font-size: var(--ui-fs-12);
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
}
#feedback-dialog .fb-chip--working { background: var(--ui-selected); }
#feedback-dialog .fb-chip--live { color: var(--ui-success-ink); background: var(--ui-success); }
#feedback-dialog .fb-chip--declined { color: var(--ui-ink); background: var(--ui-surface-shade); }

/* ---------- sent ---------- */
#feedback-dialog .fb-done { display: grid; justify-items: center; gap: var(--ui-s-2); padding: var(--ui-s-6) var(--ui-s-5); text-align: center; }

/* ---------- motion: 320 ms ease-out in with 8 px travel; 200 ms ease-in out.
   Under prefers-reduced-motion --ui-travel is 0 (src/ui-tokens.css): fades only. ---------- */
#feedback-dialog[open] { animation: fb-enter var(--ui-dur-slow) var(--ui-ease-out) both; }
#feedback-dialog[open]::backdrop { animation: fb-fade var(--ui-dur-slow) var(--ui-ease-out) both; }
#feedback-dialog.is-closing { animation: fb-exit var(--ui-dur) var(--ui-ease-in) both; }
#feedback-dialog.is-closing::backdrop { animation: fb-fade var(--ui-dur) var(--ui-ease-in) reverse both; }
#feedback-dialog .fb-done:not([hidden]) { animation: fb-fade var(--ui-dur) var(--ui-ease-out) both; }
@keyframes fb-enter { from { opacity: 0; transform: var(--fb-from); } }
@keyframes fb-exit { to { opacity: 0; transform: var(--fb-from); } }
@keyframes fb-fade { from { opacity: 0; } }

/* ---------- coarse pointers: 44 px targets ---------- */
@media (pointer: coarse) {
  #feedback-dialog .fb-btn { min-height: var(--ui-target); }
  #feedback-dialog .fb-btn--icon { width: var(--ui-target); }
}

/* ---------- phones: a bottom sheet (UI-V2.md §3.2) ---------- */
@media (max-width: 720px) {
  #feedback-dialog {
    --fb-from: translateY(var(--ui-travel));
    inset: auto 0 0 0;
    width: 100%;
    max-height: calc(100dvh - var(--ui-s-7));
  }
  #feedback-dialog .fb-grab {
    display: block;
    width: var(--ui-s-6);
    height: var(--ui-s-1);
    margin: var(--ui-s-2) auto 0;
    background: var(--ui-surface-shade);
    box-shadow: 0 0 0 var(--ui-px) var(--ui-ink-muted);
  }
  #feedback-dialog .fb-head { padding: var(--ui-s-2) var(--ui-s-3) var(--ui-s-3) var(--ui-s-4); }
  #feedback-dialog .fb-body { padding: var(--ui-s-3) var(--ui-s-4) calc(var(--ui-s-4) + env(safe-area-inset-bottom)); }
  #feedback-dialog .fb-input { min-height: 112px; }
  #feedback-dialog .fb-btn { min-height: var(--ui-target); }
  #feedback-dialog .fb-btn--icon { width: var(--ui-target); }
  /* Thumb reach: both actions share the row, the primary last (right). */
  #feedback-dialog .fb-actions .fb-btn { flex: 1 1 0; }
  #feedback-dialog .fb-done { padding: var(--ui-s-5) var(--ui-s-4) calc(var(--ui-s-6) + env(safe-area-inset-bottom)); }
}

/* ---------- who sees "Send feedback" (30 Oct, Ujjwal: invited testers only) ----------
   src/feedback-ui.js asks the server and the shell sets html.feedback-tester.
   Every other player sees no entry: the room ⋯ menu, the status ⋯ menu and
   Settings → Help (the palette filters its command in src/ui-shell.js). */
html:not(.feedback-tester) #hud-feedback-btn,
html:not(.feedback-tester) #status-menu [data-action="feedback"],
html:not(.feedback-tester) .settings-help [data-proxy="feedback-open"] { display: none; }
