/* Project devices and the console.
   One shell for every project; family tokens tint it. Shared dv-* primitives
   give the thirteen playable models one instrument language. */

dialog { color: var(--ink); }
dialog::backdrop { background: rgb(236 228 214 / 78%); backdrop-filter: blur(6px) saturate(1.1); -webkit-backdrop-filter: blur(6px) saturate(1.1); }
dialog[open]::backdrop { animation: dv-fade .28s var(--ease); }
@keyframes dv-fade { from { opacity: 0; } }

/* Shell */
.device { width: min(1260px, calc(100vw - 32px)); height: min(920px, calc(100dvh - 32px)); max-width: none; max-height: none; margin: auto; padding: 0; border: 0; background: transparent; overflow: visible; }
.device-frame { position: relative; display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; padding: 10px; border-radius: 26px;
  /* Each project's chassis takes its family tint, so the device feels like its bench object. */
  background: linear-gradient(180deg, color-mix(in srgb, var(--fam-tint, #eee) 45%, #fff), color-mix(in srgb, var(--fam-tint, #ddd) 85%, #b9c0c5) 60%, color-mix(in srgb, var(--fam-tint, #ccc) 65%, #a9b1b7));
  box-shadow: inset 0 1px 0 #fff, inset 0 -2px 0 rgb(0 0 0 / 6%), 0 0 0 1px color-mix(in srgb, var(--fam-ink, #333) 18%, transparent), var(--shadow-3); }
.device-frame::before, .device-frame::after { content: ""; position: absolute; top: 18px; width: 9px; height: 9px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff, #aab1b6 75%); box-shadow: 0 0 0 1px rgb(0 0 0 / 12%); }
.device-frame::before { left: 18px; } .device-frame::after { right: 18px; }

.device-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px 16px; padding: 10px 12px 10px 28px; border-radius: 18px 18px 0 0; background: linear-gradient(180deg, var(--porcelain), #f4efe6); border-bottom: 1px solid var(--line); box-shadow: inset 0 4px 0 var(--fam-accent, var(--accent)); }
.device-id { min-width: 0; display: grid; gap: 2px; }
.device-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font: 600 var(--text-xs)/1.5 var(--mono); letter-spacing: .06em; color: var(--ink-3); }
.device-no { color: var(--fam-ink, var(--ink-3)); letter-spacing: .12em; }
.device-status { font-family: var(--sans); font-weight: 500; letter-spacing: 0; }
.synthetic-badge { display: inline-flex; align-items: center; gap: 7px; padding: 1px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); letter-spacing: .02em; }
.device[data-stage="placeholder"] .synthetic-badge { display: none; }
.synthetic-badge .synthetic-dot { width: 7px; height: 7px; box-shadow: none; transform: none; }
.device-head h2 { font: 700 clamp(1.1875rem, .95rem + .9vw, 1.625rem)/1.15 var(--serif); letter-spacing: -.02em; color: var(--ink); }
.device-head h2:focus { outline: none; box-shadow: none; }
.device-controls { display: flex; align-items: center; gap: 8px; }

/* Link from the model to its written case study (the project page) */
.device-read { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--paper-deep); font-size: var(--text-s); font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap; }
.device-read::before { content: ""; width: 12px; height: 14px; border-radius: 2px; border: 1.5px solid currentColor; background: linear-gradient(currentColor, currentColor) 2px 3px / 5px 1.5px no-repeat, linear-gradient(currentColor, currentColor) 2px 6.5px / 5px 1.5px no-repeat; }
.device-read:hover { background: var(--porcelain); border-color: var(--ink-2); text-decoration: none; }

.device-nav { display: inline-flex; gap: 4px; }
.device-step { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; min-width: 44px; max-width: 220px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--porcelain); font-size: var(--text-s); font-weight: 600; color: var(--ink); }
.device-step[hidden] { display: none; }
.device-step:hover { background: var(--paper-deep); }
.device-step .step-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-step .step-num { font-family: var(--mono); font-size: var(--text-xs); color: var(--fam-ink, var(--ink-3)); }
.device-step .step-arrow { flex: none; font-family: var(--sans); }

.device-close { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 1px solid #8c877b; background: var(--porcelain); font-size: 26px; line-height: 1; color: var(--ink); }
.device-close:hover { background: var(--paper-deep); }

.device-body { position: relative; min-height: 0; overflow: auto; overscroll-behavior: contain; background: var(--porcelain); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 18px 18px; }
.device-stage { --stage-pad: clamp(14px, 2.2vw, 26px); min-height: 100%; padding: var(--stage-pad); background:
    radial-gradient(900px 340px at 20% 0%, color-mix(in srgb, var(--fam-tint, #eee) 60%, transparent), transparent 70%), var(--porcelain); }

.stage-loading, .stage-placeholder { display: grid; place-items: center; min-height: 360px; text-align: center; color: var(--ink-2); }
.stage-placeholder .dv-panel { max-width: 560px; text-align: left; }
.stage-placeholder h3 { font: 700 var(--text-xl)/1.2 var(--serif); margin-bottom: 8px; color: var(--ink); }
.stage-placeholder p + p { margin-top: 10px; }

/* Shared instrument primitives for project modules */
.dv { display: grid; gap: clamp(12px, 1.6vw, 18px); }
.dv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.dv-bar-label { font: 600 var(--text-xs)/1.4 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.dv-grid { display: grid; gap: clamp(12px, 1.6vw, 18px); }

.dv-panel { position: relative; min-width: 0; padding: 14px 16px 16px; border-radius: 14px; background: linear-gradient(180deg, #fffefb, #f8f4ec); border: 1px solid rgb(120 100 70 / 20%); box-shadow: 0 1px 0 #fff inset, 0 6px 16px -12px rgb(70 52 28 / 40%); }
.dv-panel-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: -2px 0 12px; font: 700 var(--text-xs)/1.4 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--fam-ink, var(--ink-2)); }
.dv-panel-title .dv-badge { letter-spacing: .04em; }
.dv-screen { border-radius: 10px; padding: 12px 14px; background: linear-gradient(135deg, #f8fbf8, #e8eee9); border: 1px solid #c9d2cb; box-shadow: inset 0 1px 3px rgb(0 0 0 / 8%); }

.dv-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-strong); background: linear-gradient(var(--porcelain), #f0ebe2); box-shadow: 0 2px 0 var(--line-strong); font-weight: 600; font-size: var(--text-s); color: var(--ink); transition: transform .12s var(--ease), box-shadow .12s; }
.dv-btn:hover:not(:disabled) { border-color: var(--ink-2); }
.dv-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 0 0 var(--line-strong); }
.dv-btn:disabled { cursor: not-allowed; opacity: .55; box-shadow: none; }
.dv-btn-primary { background: linear-gradient(color-mix(in srgb, var(--fam-ink) 88%, #fff), var(--fam-ink)); border-color: var(--fam-deep); color: #fff; box-shadow: 0 2px 0 var(--fam-deep); }
.dv-btn-primary:hover:not(:disabled) { border-color: var(--fam-deep); filter: brightness(1.08); }
.dv-btn-accent { background: linear-gradient(#c2410c, #ab390a); border-color: #93300a; color: #fff; box-shadow: 0 2px 0 #93300a; }
.dv-btn-small { min-height: 36px; padding: 0 12px; font-size: var(--text-xs); }

.dv-seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.dv-seg legend { width: 100%; margin-bottom: 8px; padding: 0; font: 600 var(--text-xs)/1.4 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.dv-seg label { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 12px; border-radius: 10px; border: 1px solid #8c877b; background: var(--porcelain); font-size: var(--text-s); font-weight: 600; color: var(--ink-2); cursor: pointer; }
.dv-seg label small { display: block; font-weight: 400; font-size: var(--text-xs); color: var(--ink-3); }
.dv-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.dv-seg label:has(input:checked) { background: var(--fam-tint); border-color: var(--fam-ink); color: var(--fam-deep); box-shadow: inset 0 0 0 1px var(--fam-ink); }
.dv-seg label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.dv-seg label:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.dv-seg-stack { display: grid; }

.dv-field { display: grid; gap: 6px; font-size: var(--text-s); font-weight: 600; color: var(--ink-2); }
.dv-field { min-width: 0; }
.dv-field select, .dv-field input { width: 100%; min-width: 0; min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid #8c877b; background: var(--porcelain); font-size: var(--text-m); font-weight: 400; color: var(--ink); }

.dv-badge { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 2px 9px; border-radius: 999px; font: 600 var(--text-xs)/1.3 var(--mono); white-space: nowrap; background: var(--idle-soft); color: var(--idle); }
.dv-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.dv-badge[data-state="active"] { background: var(--fam-tint, #e6eef5); color: var(--fam-ink, #24425f); }
.dv-badge[data-state="active"]::before { animation: dv-pulse 1s ease-in-out infinite; }
.dv-badge[data-state="done"], .dv-badge[data-state="ok"] { background: var(--ok-soft); color: var(--ok); }
.dv-badge[data-state="warn"] { background: var(--warn-soft); color: var(--warn); }
.dv-badge[data-state="blocked"], .dv-badge[data-state="bad"] { background: var(--bad-soft); color: var(--bad); }
.dv-badge[data-state="waiting"] { background: var(--paper-deep); color: var(--ink-3); }
@keyframes dv-pulse { 50% { opacity: .25; } }

.dv-steps { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; counter-reset: dvstep; }
.dv-step { position: relative; display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 2px 12px; padding: 10px 0 12px; counter-increment: dvstep; }
.dv-step::before { content: counter(dvstep); grid-row: span 3; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--porcelain); border: 1.5px solid var(--line-strong); font: 700 var(--text-xs)/1 var(--mono); color: var(--ink-3); z-index: 1; }
.dv-step::after { content: ""; position: absolute; left: 15px; top: 40px; bottom: -10px; width: 2px; background: var(--line); }
.dv-step:last-child::after { display: none; }
.dv-step-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-height: 30px; }
.dv-step-title { font-weight: 700; font-size: var(--text-s); color: var(--ink); }
.dv-step-detail { grid-column: 2; font-size: var(--text-s); line-height: 1.5; color: var(--ink-2); }
.dv-step-detail:empty { display: none; }
.dv-step-extra { grid-column: 2; }
.dv-step-extra:empty { display: none; }
.dv-step[data-state="active"]::before { border-color: var(--fam-ink); color: var(--fam-ink); box-shadow: 0 0 0 4px var(--fam-tint); }
.dv-step[data-state="done"]::before { content: "✓"; background: var(--ok); border-color: var(--ok); color: #fff; }
.dv-step[data-state="done"]::after { background: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.dv-step[data-state="blocked"]::before { content: "!"; background: var(--bad); border-color: var(--bad); color: #fff; }
.dv-step[data-state="warn"]::before { content: "!"; background: var(--warn); border-color: var(--warn); color: #fff; }
.dv-step[data-state="waiting"] .dv-step-title { color: var(--ink-3); }

.dv-log { display: grid; gap: 4px; max-height: 220px; overflow: auto; margin: 0; padding: 10px 12px; border-radius: 10px; background: #fbf9f4; border: 1px solid var(--line); list-style: none; font: 400 var(--text-xs)/1.6 var(--mono); color: var(--ink-2); }
.dv-log li { display: grid; grid-template-columns: 3.8em minmax(0, 1fr); gap: 8px; }
.dv-log time { color: var(--ink-3); }
.dv-log .is-bad { color: var(--bad); }
.dv-log .is-ok { color: var(--ok); }
.dv-log .is-warn { color: var(--warn); }

.dv-explain { padding: 14px 16px; border-radius: 12px; background: var(--fam-tint, var(--paper-deep)); border: 1px solid color-mix(in srgb, var(--fam-ink, var(--ink)) 20%, transparent); color: var(--fam-deep, var(--ink)); font-size: var(--text-s); line-height: 1.55; }
.dv-explain strong { display: block; margin-bottom: 4px; font: 700 var(--text-xs)/1.4 var(--mono); letter-spacing: .1em; text-transform: uppercase; }

.dv-code { margin: 0; padding: 12px 14px; border-radius: 10px; background: #fbfaf6; border: 1px solid var(--line); overflow-x: auto; font: 400 0.8125rem/1.6 var(--mono); color: var(--ink-2); white-space: pre; tab-size: 2; }
.dv-code .add { display: block; color: var(--ok); background: var(--ok-soft); margin: 0 -14px; padding: 0 14px; }
.dv-code .del { display: block; color: var(--bad); background: var(--bad-soft); margin: 0 -14px; padding: 0 14px; }
.dv-code .dim { color: var(--ink-3); }

.dv-switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; font-size: var(--text-s); font-weight: 600; color: var(--ink-2); cursor: pointer; }
.dv-switch input { appearance: none; -webkit-appearance: none; position: relative; width: 44px; height: 26px; margin: 0; border-radius: 999px; background: #d3d0c8; border: 1px solid #8c877b; cursor: pointer; transition: background .2s; }
.dv-switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 30%); transition: transform .2s var(--ease); }
.dv-switch input:checked { background: var(--fam-ink); border-color: var(--fam-deep); }
.dv-switch input:checked::after { transform: translateX(18px); }

/* Pinned narration strip (shared): explanation, latest event and the next action.
   Place it as the LAST child of the module root so it sticks to the bottom of the device body. */
.dv-narration { position: sticky; bottom: 0; z-index: 3; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px 18px; margin: 0 calc(-1 * var(--stage-pad)) calc(-1 * var(--stage-pad)); padding: 12px var(--stage-pad); background: rgb(252 250 246 / 96%); border-top: 1.5px solid color-mix(in srgb, var(--fam-ink) 30%, transparent); box-shadow: 0 -10px 22px -16px rgb(40 30 15 / 45%); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.dv-narr-label { font: 700 var(--text-xs)/1.4 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--fam-ink); }
.dv-narr-text { margin-top: 2px; font-size: var(--text-s); line-height: 1.5; color: var(--ink); max-width: 80ch; }
.dv-narr-last { margin-top: 4px; font: 400 var(--text-xs)/1.5 var(--mono); color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dv-narr-last[data-tone="bad"] { color: var(--bad); }
.dv-narr-last[data-tone="warn"] { color: var(--warn); }
.dv-narr-last[data-tone="ok"] { color: var(--ok); }
.dv-narr-action { display: flex; justify-content: flex-end; }
.dv-narr-action:empty { display: none; }
.dv-narr-outcome { display: grid; gap: 8px; justify-items: end; }
.dv-narr-outcome-title { font: 700 var(--text-m)/1.3 var(--serif); color: var(--ok); }
.dv-narr-outcome .dv-bar { justify-content: flex-end; }
@media (max-width: 760px) {
  .dv-narration { grid-template-columns: minmax(0, 1fr); }
  .dv-narr-action, .dv-narr-outcome, .dv-narr-outcome .dv-bar { justify-content: stretch; justify-items: stretch; }
  .dv-narr-action .dv-btn { width: 100%; }
}

/* End-of-scenario card: result, the decision it shows, and what to try next */
.dv-outcome { display: grid; gap: 8px; padding: 14px 16px; border-radius: 12px; background: var(--porcelain); border: 1.5px solid var(--fam-ink, var(--ink)); box-shadow: 0 8px 20px -14px rgb(40 30 15 / 45%); }
.dv-outcome h3, .dv-outcome .dv-outcome-title { font: 700 var(--text-m)/1.3 var(--serif); color: var(--ink); }
.dv-outcome p { font-size: var(--text-s); line-height: 1.5; color: var(--ink-2); }
.dv-outcome .dv-bar { margin-top: 2px; }

@media (pointer: coarse) {
  .dv-btn-small { min-height: 44px; font-size: var(--text-s); }
}

/* Console */
.console { width: min(720px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 0; border-radius: 20px; background: transparent; }
.console-frame { padding: 18px 20px 20px; border-radius: 20px; background: linear-gradient(180deg, #fffdf8, #f4efe5); border: 1px solid var(--line-strong); box-shadow: var(--shadow-3); }
.console-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.console-head h2 { font: 700 var(--text-xl)/1.2 var(--serif); }
.console-note { font-size: var(--text-s); color: var(--ink-3); margin-bottom: 12px; }
.console-output { height: min(320px, 46dvh); overflow: auto; padding: 14px 16px; border-radius: 12px; background:
    repeating-linear-gradient(180deg, transparent 0 25px, rgb(120 100 70 / 6%) 25px 26px), #fffef9;
  border: 1px solid var(--line); font: 400 var(--text-s)/1.6 var(--mono); color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.console-output p { margin: 0 0 6px; }
.console-output .cmd { color: var(--accent-ink); font-weight: 600; }
.console-output .muted { color: var(--ink-3); }
.console-form { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; margin-top: 12px; font: 600 var(--text-s)/1 var(--mono); }
.console-form input { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid #8c877b; background: #fff; font: 400 1rem/1 var(--mono); }
.console-hint { margin-top: 10px; font-size: var(--text-s); color: var(--ink-3); }
kbd { padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-strong); background: var(--porcelain); font: 600 var(--text-xs)/1.6 var(--mono); color: var(--ink); }


/* Phones: devices fill the screen */
@media (max-width: 1100px) {
  /* keep the title for screen readers; show only the number */
  .device-step .step-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
}
@media (max-width: 720px) {
  .device { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; margin: 0; }
  .device-frame { padding: 0; border-radius: 0; background: var(--porcelain); box-shadow: none; }
  .device-frame::before, .device-frame::after { display: none; }
  .device-head { grid-template-columns: minmax(0, 1fr) 44px; padding: 8px 10px 8px 14px; border-radius: 0; gap: 6px 10px; }
  .device-head h2 { font-size: 1.0625rem; line-height: 1.2; }
  .device-status { display: none; }
  .badge-extra { display: none; }
  .device-meta { gap: 2px 8px; }
  .device-controls { display: contents; }
  .device-close { grid-column: 2; grid-row: 1; align-self: start; justify-self: end; }
  .device-read { grid-column: 1; grid-row: 2; justify-self: start; padding: 0 12px; }
  .device-nav { grid-column: 2; grid-row: 2; justify-self: end; }
  .device-head { grid-template-columns: minmax(0, 1fr) auto; }
  .device-step { padding: 0 10px; }
  .device-body { border: 0; border-radius: 0; }
  .dv-code { white-space: pre-wrap; overflow-wrap: anywhere; }
}

@media (prefers-reduced-motion: reduce) {
  .dv-badge[data-state="active"]::before { animation: none; }
}
@media (forced-colors: active) {
  .dv-step::before, .dv-badge, .dv-btn, .dv-seg label { border: 1px solid CanvasText; }
  .dv-seg label:has(input:checked) { outline: 3px solid Highlight; }
}
