.play-aux, .composer-aux, .composer-tools { display: contents; }
.composer-tools > button:not(.model) { flex-shrink: 0; }

@media (max-width: 999px) {
  body > .masthead, body > #reading, body > .bottom { min-inline-size: 0; }
  body > .masthead {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(13em, auto) auto;
    grid-template-areas: 'title note hud screen';
    align-items: center;
    gap: 0 6px;
    padding: 2px 8px;
  }
  .masthead > .mast-rule { display: none; }
  .masthead > .bookplate { grid-area: title; min-width: 0; }
  .bookplate .scene-plaque {
    position: relative; display: flex; flex-direction: column; justify-content: center;
    min-width: 0; min-height: 44px; max-width: 100%;
  }
  .scene-plaque h1 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .scene-plaque button { max-width: 100%; }
  #scene-stamp::after { content: ''; position: absolute; inset: 0; }
  .scene-plaque #scene-lead { position: relative; }
  .masthead > #note-dispenser { grid-area: note; min-width: 44px; min-height: 44px; }
  .masthead > #quick-screen { grid-area: screen; white-space: nowrap; }
  .masthead > #status-hud {
    grid-area: hud; display: grid; grid-template-columns: repeat(3,minmax(0,1fr));
    width: 100%; max-width: none; min-width: 0; min-height: 44px;
    align-items: center; gap: 8px; padding: 2px 0;
  }
  .masthead #status-hud .pc-gauge { width: auto; min-width: 0; text-align: start; }
  .masthead #status-hud .pc-gauge > div:first-child { gap: 2px; flex-wrap: wrap; }
  .masthead #status-hud .pc-gauge :is(b,small) { overflow-wrap: anywhere; }
  html.reader-immersive body > .masthead { padding: 2px 8px; }
  html.reader-immersive .masthead > #status-hud { width: min(75%,320px); }

  #reading { min-height: 0; overflow: auto; overscroll-behavior-y: contain; }
  #reading .history { padding-block: 12px; }
  body > .bottom {
    --play-height: calc(var(--play-view-height,100dvh) - var(--play-safe-top,0px) - var(--play-safe-bottom,0px));
    --tool-height: 44px;
    --action-height: max(44px, 2em);
    position: relative;
    display: flex; flex-direction: column;
    width: min(calc(100% - 12px),680px);
    max-height: calc(var(--play-height) * .51);
    padding: 3px 0 5px;
  }
  .bottom .play-aux, .composer .composer-aux {
    display: block; min-height: 0; min-width: 0;
    overflow: auto; overscroll-behavior-y: contain;
    overflow-wrap: anywhere;
  }
  .bottom .play-aux { max-height: min(11rem,calc(var(--play-height) * .27)); }
  .bottom #corner-figure {
    --art-h: clamp(64px,calc(var(--play-height) * .13),100px);
    --art-w: clamp(52px,calc(var(--play-height) * .1),80px);
    position: static; display: grid; grid-template-columns: var(--art-w) minmax(0,1fr);
    align-items: end; width: 100%; margin: 0; gap: 0 6px;
  }
  #corner-figure #figure-rack {
    grid-column: 2; position: static; width: 100%; max-height: var(--art-h); max-width: 380px;
  }
  #corner-figure .figure-bar {
    position: absolute; z-index: 2; left: 6px; bottom: 10px; gap: 3px;
  }
  #corner-figure #figure-toggle {
    width: var(--tool-height); min-height: var(--tool-height); justify-content: center;
  }
  #corner-figure #figure-gear-btn {
    display: none;
  }
  .bottom #corner-figure:not(:has(#figure-inspect:not([hidden]), #figure-rack:not([hidden]))) {
    height: 0; min-height: 0; margin: 0; overflow: visible;
  }
  .bottom #composer {
    display: flex; flex-direction: column; min-width: 0;
    min-height: calc(var(--tool-height) + var(--action-height) + 12px);
    padding: 4px 5px; margin: 0;
  }
  .bottom #composer:is(:has(.composer-aux > :not([hidden])),[data-extra-open]) {
    min-height: calc(var(--tool-height) + var(--action-height) + 56px);
  }
  #composer .composer-aux { max-height: min(13rem,calc(var(--play-height) * .31)); }
  #composer #aside-panel { padding: 0 3px 4px; }
  #composer #aside-text { min-height: 2.8em; max-height: 5em; padding: 4px 6px; }
  #composer #action, #composer #aside-text { font-size: max(16px,1rem); line-height: 1.4; resize: none; }
  #composer #action {
    flex: none; height: var(--action-height); min-height: 0; max-height: none;
    padding: 5px 6px; margin: 0;
  }
  .composer .composer-bar {
    flex: none; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: end;
    padding: 1px 0 0 calc(var(--tool-height) + 3px); gap: 3px;
  }
  .composer-bar .composer-tools {
    display: flex; align-items: stretch; min-width: 0; overflow-x: auto;
    overscroll-behavior-x: contain; gap: 1px;
  }
  .composer-bar .composer-tools > button, .composer-bar #send {
    flex: none; min-width: 44px; min-height: var(--tool-height); padding: 3px 7px;
    white-space: nowrap; font-size: .875rem; line-height: 1.25;
  }
  .composer-bar .composer-tools > .model { max-width: min(9em,55%); }
  .composer-bar #send { margin: 0; padding-inline: 12px; }
  .composer-tools :focus-visible { outline-offset: -2px; }
  #composer #check-remove { flex: none; }
  #composer #check-label { min-width: 0; }
}

@media (max-width: 580px) {
  body > .masthead {
    grid-template-columns: minmax(0,1fr) auto auto;
    grid-template-areas: 'title note screen' 'hud hud hud';
  }
  .masthead #status-hud .pc-gauge > div:first-child { justify-content: start; }
}

@media (max-width: 999px) {
  html[data-soft-keyboard] body > .bottom { max-height: calc(var(--play-height) * .65); }
  html[data-soft-keyboard]:not(.reader-immersive) body > .masthead {
    grid-template-columns: minmax(3ch,1fr) auto minmax(0,2.75fr) auto;
    grid-template-areas: 'title note hud screen'; gap: 0 3px;
  }
  html[data-soft-keyboard] .masthead .bookplate-lamp,
  html[data-soft-keyboard] .masthead .bookplate h1 { display: none; }
}

@media (max-width: 580px) {
  html[data-soft-keyboard] .bottom #composer:is(:has(#aside-text:focus),[data-aside-focused]) {
    min-height: min(calc(100% - 32px), calc(var(--tool-height) + var(--action-height) + 76px));
  }
  html[data-soft-keyboard] #status-hud .pc-gauge > div:first-child {
    display: grid; grid-template-columns: auto auto; justify-content: start; gap: 0 1px; line-height: 1.1;
  }
  html[data-soft-keyboard] #status-hud .pc-gauge span { grid-column: 1/-1; }
}

@media (min-width: 581px) and (max-width: 999px) and (max-height: 520px) {
  .bottom:is(:has(#figure-inspect:not([hidden]),#record-progress:not([hidden]),#notice:not([hidden])),[data-play-extra-open]) {
    --side-width: clamp(128px,25%,180px);
    display: grid; grid-template-columns: var(--side-width) minmax(0,1fr);
    grid-template-rows: minmax(0,1fr); align-items: end; gap: 6px;
  }
  .bottom:is(:has(#figure-inspect:not([hidden]),#record-progress:not([hidden]),#notice:not([hidden])),[data-play-extra-open]) > .play-aux {
    align-self: stretch; max-height: 100%;
  }
  .bottom:is(:has(#figure-inspect:not([hidden]),#record-progress:not([hidden]),#notice:not([hidden])),[data-play-extra-open]) #figure-toggle {
    left: calc(var(--side-width) + 12px);
  }
  .bottom #composer { max-height: 100%; }
  html[data-soft-keyboard] body > .bottom { max-height: calc(var(--play-height) * .59); }
  html[data-soft-keyboard] .bottom #composer:is(:has(.composer-aux > :not([hidden])),[data-extra-open]) {
    min-height: calc(var(--tool-height) + var(--action-height) + 34px);
  }
}

/* 输入栏：模型与天意用图标，窄屏只留图标，把位置让给快捷行动 */
.composer-tools .bar-icon{width:1.15em;height:1.15em;flex:none;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round;vertical-align:-.2em}
.composer-tools :is(#configure,#heaven-open){display:inline-flex;align-items:center;justify-content:center;gap:.35em}
.composer-tools #heaven-badge{margin:0}
@media (max-width:700px){
  .composer-tools :is(#configure,#heaven-open) .bar-label{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
  .composer-bar .composer-tools > #configure{max-width:none;flex:none;min-width:2.6em}
  .composer-bar .composer-tools > #heaven-open{flex:none;min-width:2.6em;position:relative}
  .composer-tools #heaven-badge{position:absolute;top:2px;right:3px;font-size:.6rem;line-height:1;margin:0}
}
@media (max-width:380px){
  .composer-bar .composer-tools{gap:3px}
  .composer-bar .composer-tools > button{padding-inline:8px;min-width:0}
  .composer-bar .composer-tools > :is(#configure,#heaven-open,#dice-open,#aside-open){min-width:2.2em;padding-inline:6px}
}
@media (max-width:380px){
  .composer-bar .composer-tools > :is(#quick-open,#last-context){padding-inline:5px;font-size:.82rem;letter-spacing:0}
  .composer-bar .composer-tools > :is(#dice-open,#aside-open){padding-inline:5px;min-width:2em}
}
