/* Living Drama crew chat: the Studio's dark look (web/style.css tokens), phone first. One column with 16 px
   gutters and no horizontal scroll up to 900 px; from 900 px a right rail holds Decide later and Details.
   The composer is sticky at the bottom; the checklist is a bottom sheet. Controls are at least 44 px tall.
   Class names carry a "cr-" prefix so they never collide with the player's or the Studio's. */

:root {
  --cr-bg: var(--bg, #07080b);
  --cr-panel: var(--frame, #111318);
  --cr-edge: var(--frame-edge, #1c1f27);
  --cr-raise: #171a21;
  --cr-ink: var(--ink, #eceae4);
  --cr-soft: var(--ink-soft, #a9a59b);
  --cr-faint: var(--ink-faint, #6d6a63);
  --cr-accent: var(--accent, #e7b98a);
  --cr-accent-ink: #1a130c;
  --cr-warn: #e6c170;
  --cr-danger: #ef8a7c;
  --cr-focus: #9fd0ff;
  --cr-gutter: 16px;
  --cr-touch: 44px;
  --cr-radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { max-width: 100%; overflow-x: hidden; }

body.cr-body {
  margin: 0;
  min-height: 100vh;
  background: var(--cr-bg);
  color: var(--cr-ink);
  font: 16px/1.5 var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  overflow-wrap: anywhere;
}

.cr-body :focus-visible { outline: 3px solid var(--cr-focus); outline-offset: 2px; border-radius: 6px; }
.cr-body h1, .cr-body h2, .cr-body h3 { font-family: var(--serif, Georgia, serif); font-weight: 600; line-height: 1.2; margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cr-skip { position: absolute; left: 8px; top: -60px; padding: 10px 14px; background: var(--cr-accent); color: var(--cr-accent-ink); border-radius: 8px; z-index: 50; }
.cr-skip:focus { top: 8px; }

/* -- header ------------------------------------------------------------------------------------- */
.cr-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 8px var(--cr-gutter); min-height: 56px;
  background: rgba(7, 8, 11, 0.92); border-bottom: 1px solid var(--cr-edge);
}
.cr-back { color: var(--cr-accent); font-size: 1.6rem; text-decoration: none; min-width: var(--cr-touch); min-height: var(--cr-touch); display: inline-flex; align-items: center; }
.cr-title { flex: 1 1 auto; min-width: 0; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cr-balance { margin: 0; color: var(--cr-soft); font-size: 0.9rem; white-space: nowrap; }
.cr-menu-wrap { position: relative; }
.cr-menu {
  position: absolute; right: 0; top: calc(100% + 4px); min-width: 220px; max-width: calc(100vw - 2 * var(--cr-gutter));
  background: var(--cr-panel); border: 1px solid var(--cr-edge); border-radius: var(--cr-radius); padding: 6px; z-index: 30;
}
.cr-menu-item { display: block; width: 100%; min-height: var(--cr-touch); padding: 10px 12px; text-align: left; background: none; border: 0; color: var(--cr-ink); font: inherit; border-radius: 8px; text-decoration: none; cursor: pointer; }
.cr-menu-item:hover { background: var(--cr-raise); }
.cr-menu-item:disabled { color: var(--cr-faint); cursor: default; }

/* -- buttons and chips ------------------------------------------------------------------------- */
.cr-btn {
  min-height: var(--cr-touch); padding: 8px 14px; border-radius: 999px; border: 1px solid var(--cr-edge);
  background: var(--cr-raise); color: var(--cr-ink); font: inherit; cursor: pointer; max-width: 100%;
}
.cr-btn:disabled { opacity: 0.5; cursor: default; }
.cr-primary { background: var(--cr-accent); color: var(--cr-accent-ink); border-color: var(--cr-accent); font-weight: 600; }
.cr-ghost { background: transparent; }
.cr-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.cr-chip {
  min-height: var(--cr-touch); padding: 6px 14px; border-radius: 999px; border: 1px solid var(--cr-accent);
  background: transparent; color: var(--cr-accent); font: inherit; cursor: pointer; max-width: 100%; text-align: left;
}
.cr-chip-ghost { border-color: var(--cr-edge); color: var(--cr-soft); }
.cr-link { background: none; border: 0; padding: 0 4px; color: var(--cr-accent); font: inherit; text-decoration: underline; cursor: pointer; min-height: 32px; }

/* -- state screen ------------------------------------------------------------------------------ */
.cr-state { padding: 32px var(--cr-gutter); max-width: 640px; margin: 0 auto; }
.cr-picker { list-style: none; padding: 0; }
.cr-picker a { display: block; padding: 12px 0; min-height: var(--cr-touch); color: var(--cr-accent); }

/* -- layout ------------------------------------------------------------------------------------ */
.cr-layout { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "chat" "rail" "composer"; }
.cr-main { grid-area: chat; padding: 12px var(--cr-gutter) 16px; min-width: 0; }
.cr-rail { grid-area: rail; padding: 0 var(--cr-gutter) 16px; min-width: 0; }
.cr-composer {
  grid-area: composer; position: sticky; bottom: 0; z-index: 10;
  padding: 8px var(--cr-gutter) calc(8px + env(safe-area-inset-bottom, 0px));
  background: rgba(7, 8, 11, 0.96); border-top: 1px solid var(--cr-edge); min-width: 0;
}

/* -- messages ---------------------------------------------------------------------------------- */
.cr-empty { padding: 16px 0; }
.cr-idea { margin: 0 0 12px; padding: 8px 12px; border-left: 3px solid var(--cr-accent); color: var(--cr-soft); font-style: italic; }
.cr-prompt { margin: 0; font-size: 1.1rem; }
.cr-older { margin-bottom: 8px; }
.cr-messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.cr-msg { min-width: 0; }
.cr-bubble { margin: 0; padding: 10px 14px; border-radius: var(--cr-radius); background: var(--cr-panel); border: 1px solid var(--cr-edge); white-space: pre-wrap; }
.cr-creator .cr-bubble { background: var(--cr-raise); margin-left: 24px; }
.cr-critic .cr-bubble { border-color: var(--cr-warn); }
.cr-system .cr-bubble { background: transparent; color: var(--cr-soft); font-style: italic; }
.cr-unsent .cr-bubble { opacity: 0.6; }
.cr-noted { margin: 6px 0 0; color: var(--cr-soft); font-size: 0.95rem; }

.cr-card { margin-top: 8px; padding: 12px; border-radius: var(--cr-radius); border: 1px solid var(--cr-edge); background: var(--cr-panel); min-width: 0; }
.cr-card-head { margin: 0; color: var(--cr-soft); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
.cr-card-text { margin: 4px 0 0; }
.cr-why { margin: 4px 0 0; color: var(--cr-faint); font-size: 0.9rem; }
.cr-answer { margin: 6px 0; color: var(--cr-soft); }
.cr-urgent { border-color: var(--cr-accent); box-shadow: 0 0 0 1px var(--cr-accent) inset; }
.cr-settled { opacity: 0.85; }
.cr-dismissed { opacity: 0.5; }
.cr-typed { display: flex; gap: 8px; margin-top: 8px; }
.cr-answer-input { flex: 1 1 auto; min-width: 0; min-height: var(--cr-touch); padding: 8px 12px; border-radius: 10px; border: 1px solid var(--cr-edge); background: var(--cr-bg); color: var(--cr-ink); font: inherit; }

.cr-status { margin-top: 12px; padding: 10px 14px; border-radius: var(--cr-radius); background: var(--cr-panel); color: var(--cr-soft); }
.cr-stale { color: var(--cr-warn); border: 1px solid var(--cr-warn); }
.cr-spinner { display: inline-block; animation: cr-spin 1.2s linear infinite; }
.cr-status-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
@keyframes cr-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cr-spinner { animation: none; } }

/* -- rail: decide later and details ---------------------------------------------------------------- */
.cr-rail h2 { font-size: 1rem; margin: 12px 0 4px; }
.cr-rail h3 { font-size: 0.95rem; margin: 12px 0 0; color: var(--cr-soft); }
.cr-disclosure { background: none; border: 0; padding: 0; color: var(--cr-ink); font: inherit; min-height: var(--cr-touch); cursor: pointer; }
.cr-detail-list { margin: 0; display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; }
.cr-detail-list dt { color: var(--cr-soft); }
.cr-detail-list dd { margin: 0; }

/* -- composer ---------------------------------------------------------------------------------- */
.cr-stagebar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.cr-form { display: flex; gap: 8px; align-items: flex-end; }
.cr-draft { flex: 1 1 auto; min-width: 0; min-height: var(--cr-touch); max-height: 40vh; resize: vertical; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--cr-edge); background: var(--cr-panel); color: var(--cr-ink); font: inherit; }
.cr-send { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: 0 1 auto; max-width: 48%; }
.cr-left { color: var(--cr-faint); font-size: 0.85rem; }

/* -- the checklist sheet ------------------------------------------------------------------------- */
.cr-sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.6); display: flex; align-items: flex-end; justify-content: center; }
.cr-sheet-body {
  width: 100%; max-width: 640px; max-height: 85vh; overflow-y: auto;
  padding: 16px var(--cr-gutter) calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--cr-panel); border-radius: 16px 16px 0 0; border-top: 1px solid var(--cr-edge);
}
.cr-assumed { color: var(--cr-soft); }
.cr-sheet-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* -- toasts ------------------------------------------------------------------------------------ */
.cr-toasts { position: fixed; left: var(--cr-gutter); right: var(--cr-gutter); top: 64px; z-index: 50; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.cr-toast { margin: 0 auto; max-width: 560px; padding: 10px 14px; border-radius: 10px; background: var(--cr-raise); border: 1px solid var(--cr-edge); }
.cr-toast.cr-error { border-color: var(--cr-danger); }

/* -- desktop: a right rail -------------------------------------------------------------------------- */
@media (min-width: 900px) {
  .cr-layout { grid-template-columns: minmax(0, 1fr) 320px; grid-template-areas: "chat rail" "composer rail"; max-width: 1200px; margin: 0 auto; }
  .cr-rail { position: sticky; top: 56px; align-self: start; padding-top: 12px; border-left: 1px solid var(--cr-edge); }
  #laterList[hidden] { display: block !important; }
}
