/* Keep essential controls in view; only audience lists scroll on desktop. */
.advanced-settings-button {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; margin-top: 10px; padding: 5px 0;
  border: 0; background: none; color: #9aa2b6; font-size: 11px;
}
.advanced-settings-button svg { width: 13px; height: 13px; }
.advanced-settings-button:hover { color: var(--gold); }
.settings-dialog { width: min(420px, calc(100% - 28px)); }
.advanced-settings-content .check-label { margin-bottom: 15px; }
.advanced-settings-content > .field-label {
  display: flex; justify-content: space-between; margin-top: 22px;
}
.advanced-settings-content input[type=range] { width: 100%; margin: 0 0 10px; }
.advanced-settings-content .fairness-note { margin-top: 18px; }
.profile-link { color: var(--gold); text-underline-offset: 3px; }
.profile-link svg { display: inline-block; width: 11px; height: 11px; margin-left: 4px; vertical-align: middle; transform: rotate(-40deg); }
.profile-link:hover { color: #fff0c4; text-decoration: underline; }
.winner-card strong .profile-link { color: inherit; text-decoration: underline; text-decoration-color: #f5c65e55; }
.winner-card strong .profile-link svg { width: .55em; height: .55em; margin-left: .25em; }
.record-winner { max-width: 100%; overflow-wrap: anywhere; }
.record-winner > .profile-link { display: flex; align-items: center; margin-top: 6px; min-height: 22px; font-size: 11px; }
.record-winner > .profile-link svg { margin-left: 5px; }
.record-winner .profile-unavailable { color: #81899b; }

@media (min-width: 761px) and (min-height: 600px) {
  body {
    height: 100dvh; min-height: 0; overflow: hidden;
    display: grid; grid-template-rows: 64px minmax(0, 1fr) 28px;
  }
  .site-header { width: 100%; height: 64px; padding: 0 26px; }
  .brand { font-size: 21px; gap: 11px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
  .brand-mark svg { width: 25px; height: 25px; }
  .brand small { margin-top: 2px; font-size: 8px; }
  .workspace, .collection-expanded .workspace {
    width: 100%; height: 100%; min-height: 0; max-height: none;
    grid-template-columns: 294px minmax(0, 1fr); gap: 16px; padding: 0 20px;
  }
  .collection-expanded .workspace { grid-template-columns: minmax(0, 1fr); }
  .page-footer {
    width: 100%; min-height: 0; height: 28px; padding: 6px 24px;
    align-items: center; font-size: 8px;
  }
  .control-panel {
    min-height: 0; padding: 16px 18px 12px; overflow: hidden;
  }
  .control-panel > :not(#audience-home) { flex-shrink: 0; }
  .panel-heading { padding-bottom: 12px; margin-bottom: 14px; }
  .panel-title { font-size: 13px; }
  .section-label { margin-bottom: 10px; font-size: 12px; }
  .room-picker { padding: 10px; gap: 9px; }
  .room-avatar { width: 34px; height: 34px; border-radius: 9px; }
  .room-copy strong { font-size: 12px; }
  .room-copy small { font-size: 9px; }
  .connection-detail { margin: 6px 0 12px; min-height: 15px; font-size: 9px; }
  .rules-section { position: relative; padding-top: 12px; }
  .rules-section > label[for=keyword] {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .keyword-field { height: 40px; padding: 0 11px; gap: 8px; }
  .keyword-field input { font-size: 15px; font-weight: 500; }
  .keyword-badge { font-size: 9px; }
  .field-label { font-size: 11px; }
  .setting-columns { gap: 12px; margin-top: 10px; }
  .number-field, .text-field { height: 36px; margin-top: 5px; }
  .number-field button { height: 30px; }
  .text-field, .text-field::placeholder { font-size: 11px; }
  .advanced-settings-button {
    position: absolute; top: 11px; right: 0; width: auto;
    margin: 0; padding: 2px 0; gap: 5px; font-size: 10px;
  }
  .advanced-settings-button svg { width: 11px; height: 11px; }
  .collect-section { margin-top: 13px; }
  .primary-button, .secondary-button { min-height: 38px; padding: 8px 12px; }
  .collection-status { font-size: 9px; margin: 8px 0 12px; }
  #audience-home { min-height: 0; }
  .participants-section { padding-top: 12px; min-height: 0; }
  .participants-heading { flex-shrink: 0; }
  .participants-list, .chat-list {
    flex: 1; min-height: 0; max-height: none; margin-top: 7px;
  }
  .participants-note, .chat-note {
    flex-shrink: 0; margin: 7px 0 9px; font-size: 9px;
  }
  .participant-row { padding: 7px 0; }
  .empty-participants { padding: 14px 0; }
  .empty-participants p { font-size: 11px; }
  .empty-participants span { font-size: 9px; }
  .demo-button { padding-top: 9px; min-height: 25px; font-size: 10px; }
  .stage-panel { min-height: 0; }
  .stage-toolbar { padding: 10px 18px; min-height: 49px; flex-shrink: 0; }
  .stage-identity > strong { font-size: 12px; }
  .studio-icon { width: 27px; height: 27px; }
  .stage-tools .icon-button { height: 30px; }
  .demo-banner { padding: 6px 18px; font-size: 9px; flex-shrink: 0; }
  .room-stats { margin: 12px 18px 0; }
  .room-stat { padding: 9px 13px; }
  .room-stat > span { font-size: 9px; }
  .room-stat strong { font-size: 26px; }
  .room-stat > div { margin-top: 4px; }
  .room-stat p { margin-top: 4px; font-size: 8px; }
  .stage-content {
    flex: 1; min-height: 0; justify-content: flex-start;
    padding: 16px 20px 14px;
  }
  .stage-intro { width: 100%; }
  .stage-kicker { margin-bottom: 7px; font-size: 8px; }
  .stage-content h1 { font-size: clamp(27px, 3vw, 37px); line-height: 1.3; }
  .stage-description { margin-top: 6px; font-size: 11px; }
  .stage-meta { margin-top: 10px; gap: 12px; }
  .stage-meta .meta-keyword { padding: 4px 9px; font-size: 12px; }
  .stage-meta .meta-keyword b {
    font-size: 18px; max-width: min(240px, 22vw);
    white-space: normal; overflow-wrap: anywhere;
  }
  .draw-arena, .stage-panel:fullscreen .draw-arena {
    flex: 1 1 0; height: auto; min-height: 0; max-height: none;
    margin: 12px 0;
  }
  .effect-stage {
    width: calc(100% / var(--scene-fit, 1)); height: 300px;
    min-height: 300px; max-height: 300px; scale: var(--scene-fit, 1);
  }
  .stage-actions { margin-bottom: 13px; flex-shrink: 0; }
  .draw-button { height: 47px; min-width: 205px; font-size: 14px; }
  .draw-hint { margin-top: 10px; min-height: 14px; font-size: 9px; }
  .style-dock { padding-top: 11px; flex-shrink: 0; }
  .dock-label { margin-bottom: 8px; font-size: 9px; }
  .style-tabs { gap: 7px; }
  .style-tab {
    min-height: 54px; padding: 8px 6px; flex-direction: row;
    gap: 8px; text-align: left;
  }
  .style-mini { width: 30px; transform: scale(.86); }
  .style-name { font-size: 10px; }
  .style-name small { font-size: 7px; margin-top: 3px; }
  .stage-footer {
    padding: 7px 18px; font-size: 8px; flex-shrink: 0;
    flex-direction: row;
  }
  .winner-result { inset: 14px 0 20px; gap: 10px; }
  .winner-cards.many { max-height: 100%; }
  .collection-expanded .stage-toolbar { padding: 10px 24px; }
  .collection-expanded .room-stats { margin: 12px 24px 0; }
  .collection-expanded .room-stat { padding: 10px 18px; }
  .collection-expanded .room-stat strong { font-size: 30px; }
  .collection-expanded .room-stat > span { font-size: 10px; }
  .collection-expanded .room-stat p { font-size: 8px; }
  .collection-focus { padding: 18px 24px; gap: 15px; }
  .focus-intro h1 { font-size: 28px; }
  .focus-intro p { margin-top: 6px; font-size: 11px; }
  .focus-total strong { font-size: 70px; }
  .collection-focus .focus-keyword { padding: 12px 20px; gap: 20px; }
  .collection-focus .focus-keyword strong {
    font-size: clamp(36px, 6dvh, 60px); line-height: 1.2;
  }
  .focus-footer button { min-height: 42px; }
  .stage-panel:fullscreen .stage-content { min-height: 0; padding: 16px 24px; }
  .stage-panel.fallback-fullscreen { height: 100dvh; min-height: 0; overflow: hidden; }
}

@media (min-width: 761px) and (max-width: 1100px) and (min-height: 600px) {
  .workspace { grid-template-columns: 270px minmax(0, 1fr); gap: 14px; padding: 0 16px; }
  .control-panel { padding-left: 15px; padding-right: 15px; }
  .stage-content { padding-left: 16px; padding-right: 16px; }
  .stage-toolbar { padding-left: 16px; padding-right: 16px; }
  .style-tab { gap: 5px; padding-left: 4px; padding-right: 4px; }
  .style-mini { width: 26px; transform: scale(.75); }
  .style-name { font-size: 9px; }
  .style-name small { font-size: 6px; }
}

@media (min-width: 761px) and (min-height: 600px) and (max-height: 820px) {
  body { grid-template-rows: 56px minmax(0, 1fr) 24px; }
  .site-header { height: 56px; }
  .page-footer { height: 24px; padding-top: 4px; padding-bottom: 4px; }
  .control-panel { padding-top: 13px; padding-bottom: 10px; }
  .panel-heading { margin-bottom: 10px; padding-bottom: 10px; }
  .room-picker { padding: 8px 9px; }
  .connection-detail { margin-bottom: 9px; }
  .stage-toolbar { padding-top: 7px; padding-bottom: 7px; min-height: 43px; }
  .room-stats { margin-top: 9px; }
  .room-stat { padding: 7px 11px; }
  .room-stat strong { font-size: 24px; }
  .stage-content { padding-top: 12px; padding-bottom: 11px; }
  .stage-content h1 { font-size: 29px; }
  .stage-description { display: none; }
  .stage-intro {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: center; gap: 4px 20px; text-align: left;
  }
  .stage-kicker { grid-column: 1; justify-content: flex-start; margin: 0; font-size: 7px; }
  .stage-content h1 { grid-column: 1; text-align: left; font-size: clamp(21px, 2.5vw, 29px); }
  .stage-meta {
    grid-column: 2; grid-row: 1 / 3; display: grid;
    grid-template-columns: auto auto; gap: 5px 12px; margin: 0; font-size: 10px;
  }
  .stage-meta > i { display: none; }
  .stage-meta .meta-keyword {
    grid-column: 1 / -1; grid-row: 1; justify-content: center;
    padding: 3px 9px;
  }
  .stage-meta .meta-keyword b { font-size: 22px; }
  .draw-arena { margin-top: 9px; margin-bottom: 9px; }
  .draw-button { height: 42px; }
  .draw-hint { margin-top: 8px; }
  .stage-actions { margin-bottom: 10px; }
  .style-dock { padding-top: 9px; }
  .dock-label { margin-bottom: 6px; }
  .style-tab { min-height: 47px; }
  .case-layout { padding: 16px 0; }
  .case-lane { height: 176px; }
  .case-strip { top: 7px; --card-width: 144px; }
  .case-card { height: 156px; gap: 7px; }
  .case-card .effect-avatar { width: 54px; height: 54px; border-radius: 15px; margin-top: 12px; }
  .case-card strong { font-size: 13px; }
  .case-focus-frame { width: 150px; top: 3px; bottom: 8px; }
  .wheel-wrap { width: 230px; height: 230px; padding: 14px; transform: translateY(-3px); }
  .wheel-center { inset: 38%; }
  .wheel-wrap:before { inset: 7px; }
  .lucky-grid { width: 310px; gap: 8px; }
  .lucky-cell { height: 66px; font-size: 11px; }
  .lucky-cell .effect-avatar { width: 30px; height: 30px; }
  .winner-result { inset: 10px 0 12px; gap: 8px; }
  .winner-label { font-size: 9px; flex-shrink: 0; }
  .winner-cards { max-height: 100%; overflow: auto; }
  .winner-card { padding: 10px 8px; gap: 6px; }
  .winner-card .effect-avatar { width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; }
  .winner-card strong { font-size: 15px; }
  .winner-position { font-size: 7px; }
  .winner-cards.single .winner-card { padding: 10px 18px; gap: 6px; }
  .winner-cards.single .effect-avatar { width: 48px; height: 48px; border-radius: 14px; margin: 0; flex-shrink: 0; }
  .winner-cards.single .winner-card strong { font-size: 22px; }
  .winner-cards.single .winner-position { font-size: 7px; }
  .stage-footer { padding-top: 6px; padding-bottom: 6px; }
  .collection-focus { padding-top: 14px; padding-bottom: 14px; gap: 12px; }
  .focus-intro h1 { font-size: 25px; }
  .focus-total strong { font-size: 60px; }
  .collection-expanded .room-stat { padding-top: 7px; padding-bottom: 7px; }
  .collection-expanded .room-stat strong { font-size: 27px; }
  .collection-focus .focus-keyword { padding-top: 10px; padding-bottom: 10px; }
  #audience-focus-home .participant-row { padding-top: 10px; padding-bottom: 10px; }
  #audience-focus-home .chat-row { padding-top: 10px; padding-bottom: 10px; }
}

@media (min-width: 761px) and (min-height: 600px) and (max-height: 700px) {
  body { grid-template-rows: 52px minmax(0, 1fr) 20px; }
  .site-header { height: 52px; }
  .page-footer { height: 20px; padding-top: 2px; padding-bottom: 2px; }
  .panel-heading { display: none; }
  .section-label { margin-bottom: 7px; }
  .step-no { width: 18px; height: 18px; font-size: 9px; }
  .connection-detail { font-size: 8px; margin-top: 5px; margin-bottom: 7px; }
  .rules-section { padding-top: 8px; }
  .advanced-settings-button { top: 7px; }
  .keyword-field { height: 36px; }
  .setting-columns { margin-top: 8px; }
  .number-field, .text-field { height: 32px; }
  .collect-section { margin-top: 10px; }
  .primary-button, .secondary-button { min-height: 35px; }
  .collection-status { margin: 6px 0 9px; }
  .stage-kicker { display: none; }
  .stage-meta { grid-row: 1; }
  .stage-content h1 { font-size: clamp(20px, 2.5vw, 25px); }
  .stage-meta .meta-keyword b { font-size: 16px; }
  .room-stat strong { font-size: 22px; }
  .room-stat {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: center; gap: 2px 6px; padding: 7px 10px;
  }
  .room-stat > span { font-size: 8px; line-height: 1.35; white-space: normal; gap: 4px; }
  .room-stat > span svg { display: none; }
  .room-stat > div { margin: 0; gap: 3px; }
  .room-stat p { grid-column: 1 / -1; margin: 0; font-size: 7px; min-height: 10px; }
  .stage-content { padding-top: 8px; padding-bottom: 8px; }
  .draw-button { height: 38px; }
  .draw-hint { margin-top: 6px; min-height: 12px; font-size: 8px; }
  .stage-actions { margin-bottom: 8px; }
  .style-dock { padding-top: 7px; }
  .dock-label { margin-bottom: 4px; }
  .case-layout { padding: 10px 0; }
  .case-lane { height: 146px; }
  .case-card { height: 128px; gap: 5px; }
  .case-card .effect-avatar { width: 46px; height: 46px; border-radius: 12px; margin-top: 9px; }
  .case-card-top { top: 9px; }
  .style-name small, .dock-label > span { display: none; }
  .style-tab { min-height: 40px; }
  .style-mini { height: 28px; transform: scale(.72); }
  .stage-footer { font-size: 7px; }
  .winner-cards.single .winner-card { padding: 12px 20px; gap: 6px; }
  .winner-cards.single .effect-avatar { width: 42px; height: 42px; }
  .winner-cards.single .winner-card strong { font-size: 22px; }
  .focus-intro p { display: none; }
  .collection-expanded .room-stats { margin: 8px 16px 0; }
  .collection-expanded .room-stat { padding: 7px 10px; }
  .collection-expanded .room-stat > span { font-size: 8px; }
  .collection-expanded .room-stat strong { font-size: 24px; }
  .collection-expanded .room-stat p { font-size: 7px; min-height: 10px; }
  .collection-focus { padding: 10px 16px; gap: 10px; }
  .focus-intro h1 { font-size: 21px; margin-top: 3px; }
  .focus-total strong { font-size: 46px; }
  .focus-footer > span { font-size: 10px; }
  #audience-focus-home .audience-panel { padding: 10px 16px 0; }
  #audience-focus-home .audience-tabs button { font-size: 13px; padding-bottom: 6px; }
}

/* Narrow windows and very short screens retain normal document scrolling. */
@media (max-width: 760px) {
  .workspace {
    display: flex; flex-direction: column-reverse; height: auto;
    min-height: 0; max-height: none; gap: 16px; padding: 0 12px;
  }
  .control-panel { min-height: 620px; overflow: visible; }
  .advanced-settings-button { margin-top: 10px; min-height: 30px; }
  .stage-panel { min-height: 0; }
  .stage-content { flex: 1 0 auto; }
  .stage-footer { flex-shrink: 0; }
}
@media (min-width: 761px) and (max-height: 599px) {
  .workspace { height: auto; min-height: 760px; max-height: none; }
  .collection-expanded .workspace { height: auto; min-height: 740px; }
}
