#help-dialog {
  width: min(1040px, calc(100vw - 32px));
  max-width: none;
  height: min(760px, calc(100dvh - 40px));
  max-height: min(760px, calc(100dvh - 40px));
  padding: 0;
  overflow: hidden;
  background: var(--ui-panel);
}
#help-dialog[open] { display: flex; flex-direction: column; }
.guide-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--ui-border); flex-shrink: 0; }
.guide-header h2 { margin: 4px 0 0; font-size: 22px; }
#help-dialog .dialog-close { position: static; width: 44px; height: 44px; flex-shrink: 0; padding: 0; }
#help-dialog .guide-kicker { margin: 0; color: var(--text-accent); font-size: 11px; }
.guide-layout { display: grid; grid-template-columns: 184px minmax(0, 1fr); min-height: 0; }
#guide-nav { padding: 14px 10px; border-right: 1px solid var(--ui-border); overflow-y: auto; }
#guide-nav button { display: flex; align-items: flex-start; gap: 10px; width: 100%; min-height: 59px; padding: 11px 10px; text-align: left; background: transparent; border: 1px solid transparent; color: var(--text-secondary); }
#guide-nav button small { display: block; margin-top: 5px; font-size: 10px; color: var(--text-muted); }
#guide-nav button:hover { background: var(--ui-hover); }
#guide-nav button[aria-current="page"] { border-color: var(--ui-border); background: var(--ui-surface); color: var(--text-primary); }
.guide-nav-number { color: var(--text-muted); font-size: 10px; padding-top: 3px; }
#guide-content { min-height: 0; min-width: 0; padding: 22px 24px 16px; overflow-y: auto; overscroll-behavior: contain; }
.guide-topic-heading h3 { margin: 6px 0 8px; font-size: 20px; line-height: 1.45; }
.guide-topic-heading > p:last-child { margin: 0 0 20px; font-size: 12px; line-height: 1.8; }
.guide-cases { display: grid; gap: 18px; }
.guide-case { display: grid; grid-template-columns: minmax(240px, 0.9fr) minmax(0, 1.3fr); gap: 18px; padding-top: 18px; border-top: 1px solid var(--ui-border); }
.guide-case figure { align-self: start; margin: 0; padding: 16px 8px 10px; background: var(--ui-surface); }
.guide-flow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; list-style: none; margin: 0; padding: 0; }
.guide-flow li { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; min-width: 0; }
.guide-flow li + li::before { content: '→'; position: absolute; left: -10px; top: 26px; color: var(--text-muted); font-size: 12px; }
.guide-flow li > span:last-child { font-size: 10px; line-height: 1.6; word-break: keep-all; }
.guide-flow .animal-portrait { width: 64px; height: 64px; min-width: 64px; display: block; }
.guide-ui-image { width: 64px; height: 64px; display: grid; place-items: center; image-rendering: pixelated; }
.guide-case figcaption { margin-top: 14px; text-align: center; color: var(--text-muted); font-size: 10px; line-height: 1.6; }
.guide-instructions h4 { margin: 0 0 8px; font-size: 13px; line-height: 1.6; }
.guide-instructions > ol { margin: 0; padding-left: 19px; font-size: 12px; line-height: 1.8; color: var(--text-secondary); }
.guide-instructions > ol li { padding-left: 3px; margin-bottom: 4px; }
.guide-instructions li::marker { color: var(--text-muted); }
.guide-instructions details { margin-top: 10px; font-size: 11px; }
.guide-instructions summary { cursor: pointer; color: var(--text-accent); padding: 5px 0; }
.guide-instructions details p { margin: 5px 0 0; font-size: 11px; }
#help-dialog .guide-shortcuts { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; margin: 20px 0 0; font-size: 10px; color: var(--text-muted); }
.guide-shortcuts span { white-space: nowrap; }
.guide-shortcuts kbd { padding: 2px 5px; margin-right: 4px; border: 1px solid var(--ui-border); color: var(--text-secondary); font: inherit; }
.guide-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--ui-border); padding: 12px 24px; flex-shrink: 0; }
.guide-pagination { display: flex; align-items: center; gap: 12px; }
.guide-pagination button { font-size: 12px; min-height: 36px; }
#guide-position { min-width: 38px; text-align: center; color: var(--text-muted); font-size: 11px; }
#help-dialog button:focus-visible, #help-dialog summary:focus-visible, #guide-topic-title:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 3px; }
@media (max-width: 760px), (max-width: 1000px) and (max-height: 600px) {
  #help-dialog {
    inset: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    width: calc(100vw - 20px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    height: calc(100dvh - 20px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 20px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  .guide-header { padding: 16px; }
  .guide-header h2 { font-size: 19px; }
  .guide-layout { display: flex; flex-direction: column; }
  #guide-nav { display: flex; flex-shrink: 0; gap: 6px; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--ui-border); overflow-x: auto; }
  #guide-nav button { width: auto; min-height: 44px; flex-shrink: 0; align-items: center; gap: 6px; padding: 9px; font-size: 12px; }
  #guide-nav button small { display: none; }
  #guide-content { padding: 18px 16px; }
  .guide-case { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .guide-case figure { padding: 10px; }
  .guide-flow { max-width: 330px; margin-inline: auto; }
  .guide-flow li + li::before { left: -8px; }
  .guide-case figcaption { margin-top: 8px; }
  .guide-footer { padding: 10px 12px; gap: 8px; }
  .guide-pagination { gap: 5px; }
  .guide-pagination button, #help-dialog #start { padding: 8px; min-height: 44px; font-size: 11px; }
  .guide-topic-heading h3 { font-size: 18px; }
}
/* Keep the expanded reference searchable without making the dialog taller. */
.guide-search { padding: 10px 24px; border-bottom: 1px solid var(--ui-border); flex-shrink: 0; }
.guide-search label { font-size: 11px; color: var(--text-secondary); margin-right: 12px; }
#guide-search { width: min(360px, 70%); padding: 8px 10px; font: inherit; }
#help-dialog #guide-context { margin: 8px 0 0; color: var(--text-accent); font-size: 11px; line-height: 1.6; }
.guide-layout { flex: 1 1 auto; overflow: hidden; }
.guide-case-current { border-top-color: var(--text-accent); background: var(--ui-surface); }
.guide-case:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: -2px; }
.guide-search-result { display: block; width: 100%; padding: 16px; margin-bottom: 8px; text-align: left; }
.guide-search-result small { display: block; margin-bottom: 6px; color: var(--text-muted); }
#guide-notices { max-height: 35vh; overflow-y: auto; overscroll-behavior: contain; }
#guide-notices:empty { display: none; }
.guide-notices-heading { margin: 5px 0; font-size: 10px; color: var(--text-muted); }
.guide-notice { display: flex; border-left: 2px solid var(--text-accent); background: var(--ui-panel); margin: 4px 0; }
.guide-notice.urgent { border-left-color: var(--status-danger-text); }
.guide-notice > button:first-child { flex: 1; min-width: 0; background: transparent; border: 0; text-align: left; padding: 9px 8px; }
.guide-notice b, .guide-notice span, .guide-notice small { display: block; line-height: 1.6; }
.guide-notice b { font-size: 11px; }
.guide-notice span { font-size: 10px; color: var(--text-secondary); }
.guide-notice small { margin-top: 3px; font-size: 10px; color: var(--text-accent); }
.guide-notice-dismiss { align-self: start; padding: 4px 8px; min-height: 28px; background: transparent; border: 0; }
#guide-notices summary { font-size: 10px; cursor: pointer; padding: 6px; }
@media (max-width: 760px), (max-width: 1000px) and (max-height: 600px) {
  .guide-search { padding: 8px 16px; }
  #guide-notices { max-height: 24vh; }
  .guide-notice-dismiss { min-width: 36px; min-height: 36px; }
}
.activity-guide-link { padding: 3px 8px; font-size: 10px; color: var(--text-accent); }
.activity-notice { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px; }
.activity-notice .activity-alert { min-width: 0; gap: 4px; }

/* Intermediate widths cannot fit an illustration and instructions side by side. */
@media (max-width: 1000px) {
  .guide-case { grid-template-columns: minmax(0, 1fr); }
}
/* Landscape keeps the contents beside the article to leave room for reading. */
@media (min-width: 600px) and (max-width: 1000px) and (max-height: 600px) {
  .guide-header { padding: 4px 12px; }
  .guide-header h2 { margin: 0; font-size: 16px; }
  .guide-header .guide-kicker { display: none; }
  .guide-search { padding: 4px 12px; }
  #guide-search { padding: 4px 8px; }
  .guide-layout { display: grid; grid-template-columns: 136px minmax(0, 1fr); }
  #guide-nav { display: block; padding: 4px; border-right: 1px solid var(--ui-border); border-bottom: 0; overflow-y: auto; }
  #guide-nav button { width: 100%; }
  #guide-content { padding: 12px; }
  .guide-footer { padding: 4px 12px; }
}

/* Keep reading space when a phone keyboard reduces the available height. */
@media (max-width: 599px) and (max-height: 500px) {
  .guide-header { padding: 4px 12px; }
  .guide-header h2 { margin: 0; font-size: 16px; }
  .guide-header .guide-kicker { display: none; }
  .guide-search { padding: 4px 12px; }
  #guide-nav { padding: 4px 8px; }
  #guide-content { padding: 12px; }
  .guide-footer { padding: 4px 8px; }
}
