/* Touch controls and layouts for the card library's smaller screens. */
.menu-toggle, .mobile-draw-link { display: none; }
.starter-options { display: flex; flex-wrap: wrap; gap: 8px; max-width: 100%; }

@media (max-width: 900px) {
  html { scroll-padding-top: calc(80px + env(safe-area-inset-top)); }
  body { padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
  .skip { z-index: 30; }
  .mast {
    position: sticky; top: 0; z-index: 20;
    padding-top: env(safe-area-inset-top);
    background: #fbf3e7f5; border-bottom: 1px solid #dccab15c;
    backdrop-filter: blur(12px);
  }
  .mast-inner { position: relative; flex-direction: row; gap: 12px; padding: 9px 16px; }
  .brand { font-size: 27px; min-height: 44px; }
  .menu-toggle {
    display: inline-flex; flex: none; align-items: center; justify-content: center; gap: 9px;
    min-height: 44px; padding: 8px 12px; border: 1px solid #cbb69a; border-radius: 12px;
    background: #fff9ee; font-size: 14px; font-weight: 700; color: #365541;
  }
  .menu-toggle[aria-expanded="true"] { background: #e7eddf; border-color: #6b8165; }
  .menu-symbol { display: grid; gap: 4px; width: 16px; }
  .menu-symbol i { display: block; height: 1.5px; border-radius: 2px; background: currentColor; }
  #site-navigation {
    display: none; position: absolute; top: calc(100% + 6px); left: 12px; right: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; padding: 10px;
    max-height: calc(100dvh - 90px - env(safe-area-inset-top)); overflow-y: auto;
    border: 1px solid #ccb99e; border-radius: 16px; background: #fffaf0;
    box-shadow: 0 12px 30px #53351b26;
  }
  .menu-toggle[aria-expanded="true"] + #site-navigation { display: grid; }
  #site-navigation a {
    display: flex; align-items: center; min-height: 48px; padding: 10px 14px;
    border: 1px solid transparent; border-radius: 9px; font: 600 15px/1.5 var(--sans);
  }
  #site-navigation a[aria-current="page"] { background: #e9eedf; border-color: #bbc8ad; }
  #site-navigation a:hover { background: #f3e9d7; }
  .room .back, .back { display: inline-flex; align-items: center; min-height: 44px; margin-bottom: 4px; }
  .room { padding-top: 7px; }
  .room .portrait-selector button, .portrait-selector button, .room .chat-profile .portrait-selector button {
    min-height: 44px; padding: 10px 13px; font-size: 13px;
  }
  .gold, .quiet { min-height: 48px; }
  .chip { display: inline-flex; align-items: center; min-height: 44px; padding: 9px 13px; }
  select, .room-exhibit .formline select { min-height: 48px; font-size: 16px; }
  .text-link, .recent a, .letter-context summary, .source summary {
    display: inline-flex; align-items: center; min-height: 44px;
  }
  .letter-context summary, .source summary { display: list-item; align-content: center; padding-block: 10px; }
  .check { min-height: 44px; }
  .check input { width: 22px; height: 22px; flex: none; }
  footer { flex-wrap: wrap; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  footer a { display: inline-flex; align-items: center; min-height: 44px; }
  .room .rank-person { min-height: 44px; }
}

@media (max-width: 660px) {
  .room-head h1 { font-size: clamp(30px, 7.6vw, 38px); }
  .room .room-banner h1 { font-size: clamp(30px, 7.6vw, 38px); }
  .room-head .lede { font-size: 15px; line-height: 1.7; }
  .room .room-toolbar { align-items: flex-start; gap: 12px; }
  .room-toolbar h2 { font-size: 24px; }
  .room-toolbar .portrait-selector { margin-left: auto; }
  .archive-shelves .plate { gap: 4px; flex-wrap: wrap; }
  .guest-intro p { font-size: 14px; line-height: 1.6; }
  .room-library .detail-layout > section, .room .paper-reading, .room .rank-sheet, .room .quiz-box, .room .chat-room { padding: 18px 16px; }
  .room .character-profile, .room .chat-profile { grid-template-columns: 88px minmax(0, 1fr); gap: 8px 12px; }
  .room .character-profile .portrait-selector, .room .chat-profile .portrait-selector { align-self: end; max-width: 100%; }
  .room .character-profile .plate, .room .chat-profile .plate { padding: 6px 2px; }
  .room .character-profile .plate b, .room .chat-profile .plate b { font-size: 19px; }
  .room .character-profile .plate small, .room .chat-profile .plate small { font-size: 12px; }
  .room .character-profile .portrait-selector button, .room .chat-profile .portrait-selector button { padding-inline: 10px; }
  .detail-layout .formline { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .detail-layout .formline label, .detail-layout select { min-width: 0; width: 100%; }
  .room-exhibit .formline select { padding-left: 10px; }
  .pair-details { grid-template-columns: minmax(0, 1fr); }
  .paper-reading .note { padding: 16px; }
  .room .rank-line { grid-template-columns: 28px minmax(0, 1fr) auto; gap: 4px 10px; padding: 12px 0; }
  .room .rank-no { grid-row: 1 / 3; }
  .room .rank-person { grid-column: 2; grid-row: 1; gap: 10px; }
  .room .rank-person .character-avatar { width: 38px; height: 38px; }
  .room .rank-person > span:last-child { display: flex; gap: 6px; }
  .room .rank-person small { font-size: 12px; }
  .room .rank-value { grid-column: 3; grid-row: 1; font-size: 15px; }
  .room .rank-track { grid-column: 2 / 4; grid-row: 2; height: 6px; }
  .game-scene { max-width: 480px; justify-self: center; }
  .game-scene img { aspect-ratio: 2.5; object-position: center 35%; }
  .room .choice { padding: 14px 12px; gap: 10px; line-height: 1.65; }
  .quiz-head { gap: 10px; }
  .illustrated-note { gap: 9px; }
  .illustrated-note .character-avatar { width: 44px; height: 44px; }
  .answer { padding: 16px 12px; }
  .room-chat:has(.chat-room) .room-heading .eyebrow,
  .room-chat:has(.chat-room) .room-heading .lede { display: none; }
  .room-chat:has(.chat-room) .room-heading { padding: 0 0 10px; }
  .room-chat:has(.chat-room) .room-head { margin-bottom: 14px; }
  .room .chat-layout { gap: 16px; }
  .room .chat-top { gap: 10px; padding-bottom: 12px; }
  .chat-top h2 { font-size: 23px; }
  .chat-top .tag { flex: none; font-size: 11px; }
  .chat-log { max-height: 42vh; max-height: 42dvh; overscroll-behavior-y: contain; scroll-padding-block: 12px; }
  .chat-line { max-width: 94%; }
  .chat-line p { padding: 11px 12px; font-size: 16px; line-height: 1.7; }
  .chat-starters { padding-top: 14px; gap: 7px; }
  .starter-options { flex-wrap: nowrap; overflow-x: auto; padding: 3px 3px 9px; scroll-snap-type: x proximity; }
  .starter-options .chip { flex: none; max-width: 90%; scroll-snap-align: start; }
  #chat-form { margin-top: 12px; scroll-margin-top: 90px; }
  #chat-input { font-size: 16px; line-height: 1.6; min-height: 84px; }
  .chat-send { gap: 10px; align-items: center; }
  .chat-send .fine { font-size: 12px; }
  .chat-send .gold { padding-inline: 17px; }
  .draw-actions .gold, .draw-actions .quiet { flex: 1; padding-inline: 12px; }
  .draw-actions .text-link { flex-basis: 100%; margin: 0; }
  .message-paper h2 { font-size: clamp(22px, 5.8vw, 27px); line-height: 1.5; }
  .message-paper .advice { font-size: 17px; line-height: 1.85; }
  .recent a { max-width: 100%; padding: 8px 13px; }
}

@media (max-width: 420px) {
  .room-toolbar { flex-direction: column; }
  .room-toolbar .portrait-selector { width: 100%; margin-left: 0; }
  .room-toolbar .portrait-selector button { flex: 1; }
  .room .character-profile .portrait-selector button, .room .chat-profile .portrait-selector button { padding-inline: 7px; font-size: 12px; }
  .room-exhibit .room-intro { padding: 18px 16px; }
  .room-exhibit .formline, .detail-layout .formline { grid-template-columns: minmax(0, 1fr); }
  .room-exhibit .formline label, .detail-layout .formline label { grid-template-columns: 76px minmax(0, 1fr); align-items: center; gap: 8px; }
  .room-exhibit .formline .gold { width: 100%; }
  .room .rank-person > span:last-child { display: grid; gap: 0; }
}

@media (min-width: 661px) and (max-width: 900px) {
  .room .chat-profile .portrait-selector { display: grid; grid-template-columns: 1fr; width: 100%; }
  .room-exhibit .formline { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .room-exhibit .formline label { grid-template-columns: 76px minmax(0, 1fr); align-items: center; gap: 8px; }
  .room-exhibit .formline select { min-width: 0; width: 100%; }
}

@media (max-width: 360px) {
  .mast-inner { padding-inline: 12px; gap: 8px; }
  .brand { font-size: 24px; }
  .menu-toggle { padding-inline: 10px; }
  .room-toolbar h2 { font-size: 23px; }
  .draw-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  footer > span { display: none; }
}

@media (any-pointer: coarse) and (min-width: 901px) {
  nav a, .portrait-selector button, .chip, .text-link, .letter-context summary { min-height: 44px; }
  nav a { display: inline-flex; align-items: center; }
  select { font-size: 16px; }
}
