/* Product refresh: shared visual language and focused mobile workspaces.
   Kept separate from anatomical material/scene coloring. */
:root {
  --ink: #262831;
  --bg: #f5f3ef;
  --surface: #fff;
  --surface-soft: #faf9f6;
  --line: #e2e0de;
  --line-strong: #d1cfcb;
  --muted: #666771;
  --accent: #5d50be;
  --ui-ink: #262831;
  --ui-ink-soft: #484b57;
  --ui-muted: #686a76;
  --ui-bg: #f5f3ef;
  --ui-surface: #fff;
  --ui-surface-subtle: #faf9f6;
  --ui-border: #e2e0de;
  --ui-border-strong: #ccc9cb;
  --ui-accent: #5d50be;
  --ui-accent-soft: #efecfa;
  --ui-focus: #8a7ce5;
  --ui-shadow-panel: 0 14px 42px rgba(38, 40, 49, .065);
}
body { background: var(--ui-bg); color: var(--ui-ink); }
.panel { background: var(--ui-surface-subtle); }
.question-card, .mobile-muscle-card { border-color: var(--ui-border); }
.brand h1 { color: var(--ui-ink); }
.mode-switch { background: #ece9e7; border-color: var(--ui-border); }
.mode-switch button { color: var(--ui-ink-soft); }
.mode-switch button.active,
.reference-tabs button[aria-selected="true"] { color: var(--ui-accent); }
.reference-tabs { background: #f0eef1; border-color: var(--ui-border); }
.reference-tabs button[aria-selected="true"] { border-color: #ded9f2; }
.viewer-wrap { border-color: #d9d8d7; }
.learning-start, .actions .primary, .functional-show-group {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: #fff;
}
.learning-start:not(:disabled):hover, .actions .primary:not(:disabled):hover,
.functional-show-group:not(:disabled):hover { background: #4e40a8; border-color: #4e40a8; }
.learning-field select, .search-field input {
  font-size: 15px;
  border-color: var(--ui-border-strong);
}
.reference-section p, .reference-section span, .reference-section li,
.reference-function li { color: var(--ui-ink-soft); }
.reference-section h3 { color: var(--ui-ink); }
.reference-tabs button { font-size: 14px; }
.structure-reference-grid dt { font-size: 12px; }
.structure-reference-grid dd { font-size: 14px; }
.structure-reference-head strong { font-size: 14px; }
.reference-section .structure-reference-fact > strong { font-size: 13px; }
.mobile-reference-close { display: none; }

/* Selected-muscle summary: compact, actionable, and readable on small screens. */
@media (max-width: 920px) {
  .mobile-muscle-card-copy { order: 1; gap: 3px; }
  .mobile-muscle-card-copy strong { font-size: 16px; line-height: 1.3; font-weight: 720; }
  .mobile-muscle-card-copy .mobile-muscle-latin {
    display: block; color: #74727a; font-size: 12px; line-height: 1.35;
  }
  .mobile-muscle-summary {
    order: 2; margin: 0; color: var(--ui-ink-soft); font-size: 14px;
    line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
  }
  .mobile-muscle-card .mobile-bone-reference { order: 2; }
  .mobile-muscle-card .atlas-relations { order: 3; }
  .mobile-muscle-actions { order: 4; }
  .mobile-muscle-actions .mobile-reference-open {
    min-height: 44px; padding: 8px 12px; font-size: 14px;
    color: #4c409f; background: #f1eefc; border-color: #d4cdef; font-weight: 720;
  }
  .mobile-muscle-actions .mobile-reference-open:not(:disabled):active { background: #e6e1f8; }
  /* The detailed muscle reference lives in one place: a reading panel opened
     from the compact card. Other reference types retain their current flow. */
  body.mobile-muscle-selected.explore-mode .panel .question-card > :is(#question-label, #question, #feedback, #selected-structure-actions) {
    display: none !important;
  }
  body.explore-mode:not(.mobile-reference-open) #structure-reference[data-reference-kind="muscle"] {
    display: none !important;
  }
  body.mobile-reference-open #structure-reference[data-reference-kind="muscle"]:not([hidden]) {
    position: fixed; z-index: 61; left: 0; right: 0; bottom: 0;
    top: max(30dvh, 145px); width: 100%; max-height: none;
    display: block; overflow-y: auto; overscroll-behavior: contain;
    box-sizing: border-box; margin: 0; padding: 18px 18px max(22px, env(safe-area-inset-bottom));
    border: 1px solid var(--ui-border); border-radius: 22px 22px 0 0;
    background: #fff; box-shadow: 0 -14px 48px rgba(38, 40, 49, .20);
  }
  body.mobile-reference-open .structure-reference-head {
    position: sticky; top: -18px; z-index: 5; display: grid;
    grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px;
    padding: 5px 0 13px; margin-bottom: 8px;
    background: #fff; border-bottom: 1px solid var(--ui-border);
  }
  body.mobile-reference-open .structure-reference-head strong {
    grid-column: 1; grid-row: 1; font-size: 17px; line-height: 1.25;
  }
  body.mobile-reference-open .structure-reference-head span {
    grid-column: 1; grid-row: 2; font-size: 13px; text-align: left;
  }
  body.mobile-reference-open .mobile-reference-close {
    display: inline-flex; align-items: center; justify-content: center;
    grid-column: 2; grid-row: 1 / span 2; align-self: center;
    min-height: 44px; padding: 9px 13px; color: #5043a9;
    background: #f0edfb; border: 1px solid #dcd5f3; border-radius: 11px;
    font-size: 14px; font-weight: 700;
  }
  body.mobile-reference-open .reference-tabs { top: 65px; }
  body.mobile-reference-open .structure-reference-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  body.mobile-reference-open .structure-reference-grid dd {
    font-size: 13px; overflow-wrap: anywhere;
  }
  body.mobile-reference-open .reference-section p,
  body.mobile-reference-open .reference-section li,
  body.mobile-reference-open .reference-section span { font-size: 15px; }
  body.mobile-reference-open .reference-tabs button { min-height: 46px; font-size: 14px; }
  body.mobile-reference-open .functional-show-group { min-height: 48px; }
}

/* Mobile training: the model and its answer card are siblings, so neither
   blocks gestures on the other. The answer card scrolls when content is long. */
@media (max-width: 920px) {
  body.training-layout { overflow: hidden; }
  body.training-layout .app-shell {
    display: block; height: 100dvh; min-height: 0; margin-right: 0; overflow: hidden;
  }
  body.training-layout .stage {
    box-sizing: border-box; display: flex; flex-direction: column;
    width: 100%; height: 100dvh; min-height: 0; gap: 10px;
    padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  }
  body.training-layout .topbar,
  body.training-layout .panel,
  body.training-layout .attribution,
  body.training-layout .mobile-muscle-card { display: none !important; }
  body.training-layout .viewer-wrap {
    flex: 1 1 auto; height: auto !important;
    min-height: min(280px, 43dvh) !important;
    border-radius: 16px; overflow: hidden;
  }
  body.training-layout .stage > .question-card {
    flex: 0 1 auto; min-width: 0; max-height: min(44dvh, 390px);
    overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
    margin: 0; padding: 14px 15px 12px; border-radius: 16px;
    background: #fff; box-shadow: 0 5px 22px rgba(38,40,49,.08);
  }
  body.training-layout .stage > .question-card h2 {
    font-size: clamp(19px, 5vw, 25px); line-height: 1.2; margin: 4px 0 9px;
  }
  body.training-layout .stage > .question-card .feedback {
    font-size: 14px; line-height: 1.45;
  }
  body.training-layout .stage > .question-card .question-label { font-size: 11px; }
  body.training-layout .stage > .question-card #quiz-actions:not([hidden]) {
    position: sticky; z-index: 3; bottom: -12px; margin-top: 10px;
    padding: 10px 0 0; background: #fff;
    border-top: 1px solid var(--ui-border);
  }
  body.training-layout .stage > .question-card #quiz-actions button { min-height: 44px; }
  body.training-layout .name-choice { min-height: 44px; font-size: 14px; }
}
@media (max-width: 390px) {
  body.mobile-reference-open #structure-reference[data-reference-kind="muscle"]:not([hidden]) {
    padding-left: 12px; padding-right: 12px;
  }
  body.mobile-reference-open .structure-reference-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  body.training-layout .stage > .question-card { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  body.mobile-reference-open #structure-reference { scroll-behavior: auto; }
}


/* Cohesive interaction accents and readable feedback. */
:where(.loading-recovery, .webgl-status) button,
:where(.actions, .quiz-muscle-actions, .viewer-settings) button.primary,
#loading-retry, #webgl-reload {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  color: #fff;
}
:where(button, a, summary, select, input):focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 3px;
}
:where(.question-card, .mobile-muscle-card, .display-panel, .structure-reference) {
  box-shadow: var(--ui-shadow-panel);
}
body.mobile-reference-open { overflow: hidden; }

@media (max-width: 920px) {
  /* Reserve space for the selected muscle instead of filling the screen with the model. */
  body:not(.session-active):not(.motion-mode)
  .stage:has(.mobile-muscle-card:not([hidden])) .viewer-wrap {
    flex: 0 0 auto;
    height: clamp(240px, 46dvh, 440px) !important;
    min-height: clamp(240px, 46dvh, 440px) !important;
  }
  .mobile-muscle-card-copy { order: 1; gap: 3px; }
  .mobile-muscle-card-copy strong { font-size: 16px; }
  .mobile-muscle-summary {
    order: 2;
    -webkit-line-clamp: 3;
    font-size: 13px;
    line-height: 1.4;
  }
  .mobile-muscle-primary {
    order: 3;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .mobile-muscle-primary button {
    min-height: 46px;
    border-radius: 12px;
    padding: 8px 9px;
    font-size: 14px;
    line-height: 1.25;
    font-weight: 720;
  }
  .mobile-muscle-primary .mobile-reference-open {
    color: #fff;
    background: var(--ui-accent);
    border: 1px solid var(--ui-accent);
  }
  .mobile-muscle-primary .mobile-quick-practice {
    color: #493d99;
    background: var(--ui-accent-soft);
    border: 1px solid #dcd5f3;
  }
  .mobile-muscle-primary button:active { filter: brightness(.94); }
  .mobile-muscle-more { order: 4; min-width: 0; }
  .mobile-muscle-more > summary {
    list-style: none;
    min-height: 38px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    border-radius: 10px;
    color: var(--ui-ink-soft);
    background: var(--ui-surface-subtle);
    border: 1px solid var(--ui-border);
    font-size: 13px;
    font-weight: 650;
  }
  .mobile-muscle-more > summary::-webkit-details-marker { display: none; }
  .mobile-muscle-more > summary::after {
    content: "⌄";
    font-size: 18px;
    line-height: 1;
    transition: transform .16s ease;
  }
  .mobile-muscle-more[open] > summary::after { transform: rotate(180deg); }
  .mobile-muscle-more .mobile-muscle-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;
  }
  .mobile-muscle-more .mobile-muscle-actions button {
    flex: 1 1 auto;
    min-height: 44px;
    font-size: 13px;
    line-height: 1.25;
    padding: 9px 12px;
    background: var(--ui-surface);
    color: var(--ui-ink);
    border-color: var(--ui-border-strong);
  }
  .mobile-muscle-more .atlas-relations { margin-top: 10px; }
  .mobile-muscle-card:has(.atlas-relations[data-expanded="true"]) .mobile-muscle-more {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }
  body:not(.session-active):not(.motion-mode)
  .mobile-muscle-card:has(.atlas-relations[data-expanded="true"]) {
    max-height: 56dvh;
  }
  body.mobile-reference-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(21, 20, 34, .40);
  }
  body.mobile-reference-open #structure-reference[data-reference-kind="muscle"]:not([hidden]) {
    box-shadow: 0 -16px 52px rgba(20, 18, 33, .25);
  }
  body.training-layout .stage > .question-card {
    max-height: min(51dvh, 420px);
  }
  body.training-layout .viewer-wrap {
    min-height: min(240px, 39dvh) !important;
  }
  body.training-layout .session-exit:not([hidden]) {
    position: sticky;
    top: -14px;
    z-index: 4;
    width: 100%;
    min-height: 44px;
    background: var(--ui-accent-soft);
    color: #493d99;
    border-color: #dcd5f3;
  }
}

@media (max-width: 360px) {
  .mobile-muscle-primary button { font-size: 13px; padding-inline: 6px; }
}
