/* Application appearance. Canonical Buggy has its own CSS and is outside all
   application surface/control selectors below. Theme is FIXED_POLICY. */
:root {
  color-scheme:light;
  --bg:#edf2f7; --ink:#19334c; --muted:#4c6277; --accent:#225ba8;
  --accent-soft:#e7effb; --line:#cdd9e4; --error:#a52b31; --ok:#256b4a;
  --surface:#fff; --surface-soft:#f3f6fa; --surface-blue:#eaf2fc;
  --surface-teal:#e6f3ee; --surface-warm:#fff4e2; --surface-violet:#f2eef9;
  --warm-ink:#704719; --teal-ink:#1c614f; --violet-ink:#594777;
  --action-bg:#245ba9; --action-ink:#fff; --focus:#176ea5;
  --shadow:0 4px 18px #17324d09;
}
:root[data-theme="dark"] {
  color-scheme:dark;
  --bg:#101923; --ink:#e5edf5; --muted:#b2c0cf; --accent:#96c3ff;
  --accent-soft:#203a58; --line:#415369; --error:#ffb5bb; --ok:#8bd4ab;
  --surface:#192634; --surface-soft:#213040; --surface-blue:#203449;
  --surface-teal:#173b36; --surface-warm:#3b3121; --surface-violet:#302b43;
  --warm-ink:#efd1a2; --teal-ink:#b0dfcc; --violet-ink:#d5c3f5;
  --action-bg:#98c4ff; --action-ink:#10283f; --focus:#a5d9ff;
  --shadow:0 4px 18px #0002;
}
@media (prefers-color-scheme:dark) {
  :root:not([data-theme]) {
    color-scheme:dark;
    --bg:#101923; --ink:#e5edf5; --muted:#b2c0cf; --accent:#96c3ff;
    --accent-soft:#203a58; --line:#415369; --error:#ffb5bb; --ok:#8bd4ab;
    --surface:#192634; --surface-soft:#213040; --surface-blue:#203449;
    --surface-teal:#173b36; --surface-warm:#3b3121; --surface-violet:#302b43;
    --warm-ink:#efd1a2; --teal-ink:#b0dfcc; --violet-ink:#d5c3f5;
    --action-bg:#98c4ff; --action-ink:#10283f; --focus:#a5d9ff;
    --shadow:0 4px 18px #0002;
  }
}
.site-header { position:relative; background:var(--surface); border-color:var(--line); }
.brand .brand-name { color:var(--ink); }
.brand .brand-year { color:var(--teal-ink); background:var(--surface-teal); }
.role-session { max-width:none; gap:.6rem; }
.site-header .header-popover { position:relative; margin:0; padding:0; border:0; flex:0 0 auto; }
.role-student .simple-secondary-nav[open] { flex-basis:auto; }
.site-header .header-popover > summary {
  display:flex; align-items:center; gap:.4rem; padding:.6rem .75rem;
  min-height:44px; border:1px solid var(--line); border-radius:8px;
  color:var(--ink); background:var(--surface); font-size:.85rem;
  font-weight:650; cursor:pointer; list-style:none;
}
.site-header .header-popover > summary::-webkit-details-marker { display:none; }
.site-header .header-popover > summary::after {
  content:''; margin-left:.15rem; width:.45rem; height:.45rem; flex:0 0 .45rem;
  box-sizing:border-box; border:solid currentColor; border-width:0 1.5px 1.5px 0;
  transform:rotate(45deg);
}
.site-header .header-popover[open] > summary { margin-bottom:0; border-color:var(--accent); }
.site-header .header-popover[open] > summary::after { transform:rotate(225deg); }
.site-header .header-popover-panel {
  position:absolute; top:calc(100% + .45rem); right:0; z-index:20;
  transform:translateX(var(--popover-shift, 0px));
  display:flex; flex-direction:column; flex-wrap:nowrap; gap:.3rem;
  width:min(20rem, calc(100vw - 2rem)); padding:.65rem;
  max-height:min(70vh, 28rem); overflow:auto;
  background:var(--surface); color:var(--ink); border:1px solid var(--line);
  border-radius:12px; box-shadow:0 10px 35px #0003;
}
/* Native details cannot use JS viewport placement. Anchor its overlay to the
   full header, not the narrow summary; percentage width excludes the gutter. */
/* The teacher account also uses CSS placement before JS initialization. */
:root:not(.theme-enabled) .site-header .simple-secondary-nav,
.site-header .teacher-account-nav { position:static; }
:root:not(.theme-enabled) .site-header .simple-secondary-nav .header-popover-panel,
.site-header .teacher-account-nav .header-popover-panel {
  left:50%; right:auto; transform:translateX(-50%);
  width:min(20rem, calc(100% - 2rem));
}
.site-header .header-popover-panel a { display:flex; width:100%; white-space:normal; color:var(--ink); }
.site-header .header-popover-panel a:hover { background:var(--accent-soft); }
.site-header #account-popover { display:grid; gap:.3rem; }
.site-header #account-popover .account-action {
  align-items:center; justify-content:space-between; gap:.75rem;
  min-height:44px; padding:.65rem .8rem; box-sizing:border-box;
  border:1px solid transparent; border-radius:8px;
  background:var(--surface-soft); color:var(--ink);
  text-decoration:none; font-weight:650; line-height:1.4;
}
.site-header #account-popover .account-action:hover,
.site-header #account-popover .account-action:focus-visible,
.site-header #account-popover .account-action[aria-current] {
  background:var(--accent-soft); border-color:var(--accent); color:var(--ink);
}
.site-header #account-popover .account-action > [aria-hidden] {
  flex:0 0 auto; color:var(--accent); font-size:1.2rem;
}

[data-appearance-menu] { display:none; }
.theme-enabled [data-appearance-menu] { display:block; }
.appearance-nav fieldset { margin:0; padding:.25rem; border:0; min-width:0; }
.appearance-nav legend { padding:0; font-size:.95rem; font-weight:750; }
.appearance-nav .hint { margin:.15rem 0 .55rem; font-size:.8rem; }
.appearance-nav label { display:flex; align-items:center; gap:.65rem; padding:.55rem; min-height:44px; border-radius:7px; cursor:pointer; }
.appearance-nav label:has(:checked) { background:var(--accent-soft); }
.appearance-nav input { width:1.1rem; height:1.1rem; accent-color:var(--action-bg); margin:0; }
.site-header nav a:hover, .site-header nav a[aria-current] { background:var(--accent-soft); color:var(--accent); }
.site-header nav a.document-nav-link { border:1px solid var(--accent); background:var(--accent-soft); color:var(--ink); font-weight:750; }
.site-header nav a.document-nav-link:hover { background:var(--surface); color:var(--accent); }
.site-header :focus-visible, main :focus-visible, footer :focus-visible { outline:3px solid var(--focus); outline-offset:3px; }
main a:hover, footer a:hover { color:var(--accent); text-decoration-thickness:2px; }
main :is(.card,.status-panel,.save-bar,.scene-row,.role-priority,.role-section-nav,.role-phase-strip p,.role-waiting,.supporting-details,.task-explanation,.course-controls,.stats > div,.stat,.summary-card,.model-context,.model-card,.pair-context,.photo-dialog,.text-example,.legacy-reference,.simple-reference,.object-plan-preview,.guide-step,.filter-form,.response,.role-project-state) {
  background:var(--surface); border-color:var(--line); color:var(--ink);
}
/* Reading and overview surfaces share the palette with the scene editor.
   Keep illustrations/photos and the canonical Buggy outside these selectors. */
main :is(.info-note,.example,.key-states > div,.expected-states > div) { background:var(--surface-soft); color:var(--ink); border-color:var(--line); }
main :is(.workspace-stats > p,.empty-state) { background:var(--surface); color:var(--muted); border-color:var(--line); }
main .stats strong { color:var(--ink); }
main :is(.help-index a,.version-list a) { background:var(--surface); border-color:var(--line); }
main .milestone { background:var(--surface-soft); color:var(--ink); border-color:var(--line); }
main .milestone-mark { color:var(--accent); }
main .milestone span:not(.milestone-mark) { color:var(--muted); }
main #odpoved blockquote { background:var(--surface-blue); color:var(--ink); border-color:var(--accent); }
main :is(.task-focus,.task-checkpoint,.status-note,.guide-example,.guide-checkpoint,.simple-step,.role-course-steps li,.review-instructions) { background:var(--surface-blue); border-color:var(--line); color:var(--ink); }
main :is(details,fieldset,.criterion-row,.score-card,.key-card,.photo-key-card) { background:var(--surface); color:var(--ink); border-color:var(--line); }
main .photo-key-shared { background:var(--surface-teal); }
main .photo-key-purpose { color:var(--muted); }
main :is(.scene-row:hover,.role-priority:hover,.role-section-nav a:hover,.role-section-nav a[aria-current]) { background:var(--accent-soft); color:var(--ink); }
main :is(.role-priority strong,.scene-code,.student-name) { color:var(--ink); }
.journey-menu { background:var(--surface-soft); border-color:var(--line); }
.journey-step > a:hover { background:var(--surface); }
.journey-step.current > a { background:var(--accent-soft); color:var(--ink); }
.journey-step-number { background:var(--surface); color:var(--muted); border-color:var(--line); }
.journey-step.current .journey-step-number { background:var(--action-bg); color:var(--action-ink); border-color:var(--action-bg); }
.journey-step.current .journey-step-state { color:var(--muted); }
.journey-step.done .journey-step-number { background:var(--surface-teal); color:var(--ok); border-color:var(--line); }
main table { background:var(--surface); color:var(--ink); }
main :is(th,thead,.table-scroll) { background:var(--surface-soft); color:var(--ink); }
main :is(td,th) { border-color:var(--line); }
main .stacked-table tr { background:var(--surface); }
main tr:hover td { background:var(--surface-soft); }
/* The public explanation has its own layout CSS loaded after the host theme;
   scope its painted surfaces explicitly while preserving the teaching SVGs. */
main .explanation-hero { background:linear-gradient(125deg,var(--surface-teal),var(--surface-blue)); border-color:var(--line); }
main :is(.explanation-number,.explanation-contents,.explanation-photo) { background:var(--surface); color:var(--ink); border-color:var(--line); }
main .explanation-number > strong { color:var(--teal-ink); }
main :is(.explanation-number p,.explanation-demo figcaption) { color:var(--muted); }
main .explanation-demo figcaption strong { color:var(--ink); }
main :is(.explanation-demo,.explanation-table tbody th) { background:var(--surface-soft); border-color:var(--line); }
main .explanation-table { border-color:var(--line); }
main .explanation-contents a, main .explanation-photo-number { background:var(--accent-soft); color:var(--accent); }
main .explanation-direction > div { background:var(--surface-teal); color:var(--ink); border-color:var(--teal-ink); }
main .explanation-direction > div + div { background:var(--surface-blue); border-color:var(--accent); }
main :is(input,select,textarea) { background:var(--surface); color:var(--ink); border-color:var(--line); }
main input[type=file] { background:var(--surface); color:var(--ink); border-color:var(--line); }
main :is(input,textarea)::placeholder { color:var(--muted); opacity:1; }
main :is(input,select,textarea):hover { border-color:var(--muted); }
main :is(input,select,textarea):focus { border-color:var(--focus); }
main :is(button,.button), .site-header button {
  background:var(--action-bg); color:var(--action-ink); border-color:var(--action-bg);
  min-height:44px; display:inline-flex; align-items:center; justify-content:center;
  gap:.4rem; font-weight:650;
}
main :is(button,.button):hover, .site-header button:hover { background:var(--action-bg); color:var(--action-ink); filter:brightness(.95); }
main :is(button.secondary,.button.secondary), .site-header button.secondary { background:var(--surface); color:var(--ink); border-color:var(--line); }
main :is(button.secondary,.button.secondary):hover, .site-header button.secondary:hover { background:var(--accent-soft); color:var(--ink); border-color:var(--accent); }
main :is(button,.button):disabled { opacity:.55; }
main .badge { background:var(--surface-soft); color:var(--ink); border-color:var(--line); }
main :is(.badge-complete,.milestone-earned,.success) { background:var(--surface-teal); color:var(--ok); border-color:var(--line); }
main :is(.badge-waiting,.warning) { background:var(--surface-warm); color:var(--warm-ink); border-color:var(--line); }
main :is(.badge-progress,.message) { background:var(--surface-blue); color:var(--ink); border-color:var(--line); }
main :is(.badge-error,.message.error,.errorlist) { background:var(--surface); color:var(--error); border-color:var(--error); }
/* AI batch status: guided.css tints are light-only, so dark mode showed light text on a light box (Buggy #221). */
main [data-phase="waiting"] .batch-activity { background:var(--surface-warm); border-color:var(--line); }
main [data-phase="error"] .batch-activity { background:var(--surface); border-color:var(--error); }
main .scene-page-heading { background:linear-gradient(115deg,var(--surface-blue),var(--surface-teal) 72%,var(--surface-warm)); border-color:var(--line); }
main .scene-page-heading .eyebrow { color:var(--accent); }
main .scene-workspace .photo-slot { background:var(--surface-blue); border-color:var(--line); }
main .scene-workspace :is(.photo-card-heading strong,.photo-description label) { color:var(--ink); }
main .scene-workspace :is(.photo-card-heading span:not(.photo-card-number),.photo-description .hint) { color:var(--muted); }
main .scene-workspace :is(.photo-slot img,.photo-placeholder) { background:var(--surface-soft); border-color:var(--line); }
main .scene-workspace :is(.photo-slot input[type=file],.photo-slot textarea,.reference-stability textarea) { background:var(--surface); color:var(--ink); border-color:var(--line); }
main .scene-workspace .reference-stability { background:var(--surface-warm); border-color:var(--line); }
main .scene-workspace :is(.reference-stability h2,.reference-stability > .field > label) { color:var(--warm-ink); }
main .scene-workspace :is(.text-example,.legacy-reference,.card > details:not(.voice-input)) { background:var(--surface-violet); border-color:var(--line); }
main .scene-workspace :is(.text-example > summary,.legacy-reference > summary,.card > details:not(.voice-input) > summary) { color:var(--violet-ink); }
main :is(.voice-input,.voice-input[open],.voice-input.voice-input-compact:not([open]),.voice-destination) { background:var(--surface-teal); color:var(--teal-ink); border-color:var(--line); }
main .voice-input :is(.voice-browser-options,.voice-original) { background:var(--surface); border-color:var(--line); }
main .voice-input .voice-token-setup { background:var(--surface-warm); color:var(--warm-ink); border-color:var(--line); }
main .voice-input > summary, main .voice-input > summary::after { color:var(--teal-ink); }
main .voice-input > summary::after { background:var(--surface); }
main .scene-workspace .save-bar { background:var(--surface-blue); border-color:var(--line); }
main .scene-bulk-upload { background:var(--surface-soft); color:var(--ink); border-color:var(--line); }
main .scene-bulk-upload .hint { color:var(--muted); }
main input::file-selector-button { background:var(--surface-soft); color:var(--ink); border-color:var(--line); }
#photo-dialog { background:var(--surface); color:var(--ink); border-color:var(--line); }
#photo-dialog button { background:var(--surface-soft); color:var(--ink); border-color:var(--line); }
footer { background:var(--surface); border-color:var(--line); color:var(--muted); }
.scene-start-explanation { max-width:75ch; font-size:.92rem; }
@media (max-width:600px) {
  .site-header .role-session { justify-content:flex-start; width:100%; }
  .site-header .header-popover > summary { font-size:.84rem; }
  main .actions > .button { text-align:center; }
}
@media (max-width:440px) {
  .scene-workspace .photo-editor { grid-template-columns:minmax(0,1fr); }
}
@media print {
  [data-appearance-menu] { display:none!important; }
}
