/* Prototype only: production desktop formation is untouched. */
@media (max-width: 900px) {
  body { -webkit-text-size-adjust:100%; }
  .layout { display:block; }
  .formation-header { position:relative; flex-wrap:wrap; padding:10px 12px; }
  .formation-title { min-width:0; }
  .formation-title p { font-size:10px; }
  .header-actions { width:100%; flex-wrap:wrap; gap:6px; }
  .header-actions .chip-source { margin-right:auto; }
  .formation-header button,.formation-header a { min-height:40px; }
  .hangar { padding:16px 10px 6px; }
  .heading { margin-bottom:12px; }
  .board { gap:6px; }
  .lane-head { padding:10px 7px; }
  .lane-head strong { font-size:13px; }
  .lane-number { display:none; }
  .station { padding:9px 6px; }
  .station .slot { font-size:9px; letter-spacing:0; }
  .station .slot > span:last-child { display:none; }
  .station .name { font-size:12px; flex-direction:column; align-items:flex-start; gap:4px; }
  .scene { height:100px; }
  .scene .sprite { width:72px; height:96px; max-width:100%; }
  .plinth { width:85%; max-width:110px; height:30px; }
  .mini-chips { flex-direction:column; }
  .mini-chip { width:100%; font-size:10px; }
  .join { height:24px; font-size:8px; gap:4px; }
  .swap { min-height:44px; padding:7px 3px; font-size:10px; }
  .team-bottom { gap:10px; flex-wrap:wrap; }
  .inspector { border-left:0; border-top:1px solid var(--line); padding:18px 14px; gap:15px; }
  .chip-slot { min-height:58px; }
  .skill { min-height:44px; }
  .skill strong,.chip-slot strong { font-size:13px; }
  .description,.chip-note { font-size:12px; }
  .mode button,.primary { min-height:46px; }
  #picker { box-sizing:border-box; width:100%; max-width:100%; height:100dvh; max-height:100dvh; margin:0; padding:12px; border:0; border-radius:0; overscroll-behavior:contain; }
  #picker .dialog-heading { position:sticky; top:-12px; z-index:3; background:var(--panel); padding:10px 0; gap:8px; }
  #picker .dialog-heading h2 { font-size:17px; }
  #close-picker { min-width:44px; min-height:44px; }
  #filters { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:5px; margin:12px 0; }
  #filters button { padding:6px 2px; min-height:42px; font-size:11px; }
  .picker-content { grid-template-columns:minmax(0,1fr); gap:12px; }
  #choices { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); max-height:156px; overflow:auto; gap:6px; }
  #choices .choice { min-width:0; min-height:46px; overflow-wrap:anywhere; }
  #details-host { overflow:visible; }
  #picker .dialog-footer { bottom:-12px; z-index:3; flex-wrap:wrap; margin-top:12px; padding:10px 0 max(10px,env(safe-area-inset-bottom)); gap:8px; }
  .dialog-footer p { flex:1 0 100%; margin:0; }
  .dialog-footer button { flex:1; min-height:44px; }
  .toast { width:max-content; max-width:calc(100vw - 24px); padding:12px; }

  /* These rules also load inside the isolated production detail panel. */
  .chip-performance { display:flex; flex-direction:column; height:auto; overflow:visible; gap:10px; }
  .chip-performance__header { grid-template-columns:minmax(0,1fr); gap:8px; }
  .chip-performance__description { font-size:12px; }
  .chip-performance__upper,.chip-performance__lower { display:grid; grid-template-columns:minmax(0,1fr); height:auto; min-height:0; overflow:visible; gap:10px; }
  .chip-skill-panel { display:flex; flex-direction:column; min-height:0; }
  .chip-skill-list { display:flex; overflow-x:auto; border-right:0; border-bottom:1px solid var(--line); padding:7px; flex-shrink:0; }
  .chip-skill-item { flex:0 0 140px; min-height:56px; }
  .chip-skill-detail { overflow:visible; padding:10px; }
  .chip-skill-detail__description { font-size:12px; }
  .chip-skill-detail__data { font-size:11px; }
  .chip-skill-detail__badges button { min-height:42px; font-size:12px; }
  .chip-detail-panel__heading h4 { font-size:12px; }
  .chip-detail-panel__heading small { font-size:10px; }
  .chip-stat-panel { min-height:0; }
  .chip-stat-table { font-size:12px; }
  .chip-stat-table th,.chip-stat-table td { height:32px; }
  .chip-level-panel { height:280px; }
  .chip-level-table { font-size:11px !important; min-width:640px; }
  .chip-level-table th,.chip-level-table td { height:28px; }
  .chip-level-table-wrap { overscroll-behavior-x:contain; }
  .chip-na-panel { min-height:190px; }
}

/* Landscape formation: fixed viewport, three pairs beside equipment. */
@media (max-width:1000px) and (orientation:landscape) {
  html,body { height:100%; overflow:hidden; }
  body { height:100dvh; display:flex; flex-direction:column; }
  .formation-header { flex:0 0 46px; min-height:46px; padding:4px 10px; flex-wrap:nowrap; gap:8px; }
  .formation-title h1 { font-size:13px; }
  .formation-title p,.header-actions .chip-source,.header-actions .back-link { display:none; }
  .header-actions { width:auto; flex-wrap:nowrap; margin-left:auto; }
  .formation-header button,.formation-header a { min-height:32px; font-size:10px; padding:0 8px; }
  .layout { flex:1; min-height:0; width:100%; display:grid; grid-template-columns:minmax(0,1fr) 260px; overflow:hidden; }
  .hangar { min-height:0; padding:6px 8px; display:flex; flex-direction:column; }
  .heading { flex:0 0 22px; margin:0; }
  .heading h2 { font-size:12px; margin:0; }
  .heading .eyebrow,.heading p,.team-bottom { display:none; }
  .board { flex:1; min-height:0; gap:6px; }
  .lane { display:grid; min-height:0; grid-template-rows:28px minmax(0,1fr) 12px minmax(0,1fr) 28px; }
  .lane-head { padding:3px 6px; }
  .lane-head strong { font-size:11px; }
  .lane-head small,.lane-number { display:none; }
  .station { min-height:0; padding:3px 6px; display:grid; grid-template-rows:12px minmax(0,1fr) 20px; }
  .station .slot { font-size:8px; }
  .station .slot > span:last-child,.station .mini-chips,.station .role { display:none; }
  .station .name { margin:0; font-size:11px; display:block; text-align:center; }
  .scene { height:auto; min-height:0; }
  .scene .sprite { height:100%; max-height:90px; width:auto; max-width:100%; }
  .plinth { height:18px; width:75%; bottom:0; }
  .join { height:12px; font-size:7px; }
  .swap { min-height:28px; padding:2px; font-size:8px; }
  .inspector { min-height:0; padding:8px 10px; gap:7px; border-top:0; border-left:1px solid var(--line); }
  .unit-header { gap:8px; }
  .unit-header .sprite { width:30px; height:40px; }
  .inspector h2 { font-size:17px; margin:2px 0; }
  .unit-header .eyebrow { font-size:8px; }
  .inspector > section:nth-of-type(2),.inspector > .description,.inspector .chip-note { display:none; }
  .label { margin-bottom:4px; font-size:10px; }
  .chip-slot { min-height:42px; padding:5px 7px; gap:8px; }
  .chip-slot + .chip-slot { margin-top:5px; }
  .chip-slot strong { font-size:11px; }
  .chip-slot small { font-size:8px; margin-top:3px; }
  .chip-slot .num { width:24px; height:28px; font-size:16px; }
  .deploy { padding-top:6px; }
  .mode { margin:3px 0 5px; }
  .mode button { min-height:32px; padding:3px; font-size:9px; }
  .primary { min-height:34px; padding:5px; font-size:12px; }
}
@media (max-width:600px) and (orientation:portrait) {
  html,body { height:100%; overflow:hidden; }
  body { height:100dvh; display:flex; flex-direction:column; }
  .formation-header { flex:0 0 auto; padding:6px; gap:5px; }
  .formation-title h1 { font-size:12px; }
  .formation-title p,.header-actions .chip-source,.header-actions .back-link { display:none; }
  .formation-title { gap:6px; }
  .header-actions { width:auto; margin-left:auto; gap:4px; }
  .formation-header a,.formation-header button { min-height:32px; padding:0 6px; font-size:9px; }
  .header-actions .tutorial-page-link { display:none; }
  .layout { flex:1; min-height:0; width:100%; display:grid; grid-template-columns:minmax(0,1.4fr) minmax(0,1fr); overflow:hidden; }
  .hangar { min-height:0; padding:6px 4px; display:flex; flex-direction:column; }
  .heading { flex:0 0 24px; margin:0; }
  .heading h2 { font-size:12px; margin:0; }
  .heading .eyebrow,.heading p,.team-bottom { display:none; }
  .board { flex:1; min-height:0; display:grid; grid-template-columns:minmax(0,1fr); grid-template-rows:repeat(3,minmax(0,1fr)); gap:6px; }
  .lane { min-height:0; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); grid-template-rows:26px minmax(0,1fr) 30px; }
  .lane-head { grid-column:1/-1; padding:4px 6px; }
  .lane-head strong { font-size:11px; }
  .lane-head small,.lane-number,.join { display:none; }
  .station { padding:4px; min-height:0; display:grid; grid-template-rows:14px minmax(0,1fr) 22px; }
  .station .slot { font-size:9px; }
  .station .name { display:block; text-align:center; font-size:10px; margin:0; align-self:center; }
  .station .mini-chips,.station .role { display:none; }
  .scene { min-height:0; height:auto; align-items:center; }
  .scene .sprite { width:auto; height:auto; max-width:100%; max-height:100%; object-fit:contain; }
  .plinth { bottom:15%; height:20px; width:95%; }
  .swap { grid-column:1/-1; min-height:30px; font-size:9px; padding:3px; }
  .inspector { min-width:0; min-height:0; border-top:0; border-left:1px solid var(--line); padding:10px 6px; gap:10px; }
  .unit-header { flex-direction:column; align-items:flex-start; gap:4px; }
  .unit-header .sprite { width:36px; height:48px; }
  .unit-header .eyebrow { font-size:8px; letter-spacing:0; }
  .inspector h2 { font-size:15px; margin:4px 0; }
  .inspector .label { font-size:10px; gap:3px; }
  .inspector > section:nth-of-type(2),.inspector > .description,.inspector .chip-note { display:none; }
  .chip-slot { min-width:0; min-height:70px; padding:6px; gap:4px; flex-wrap:wrap; }
  .chip-slot .num { width:20px; height:22px; font-size:14px; }
  .chip-slot .text { flex:1 0 100%; }
  .chip-slot strong { font-size:11px; white-space:normal; overflow-wrap:anywhere; }
  .chip-slot small { font-size:8px; }
  .deploy { padding-top:8px; }
  .deploy .label { flex-wrap:wrap; }
  .mode { flex-direction:column; gap:5px; }
  .mode button { min-height:38px; font-size:9px; }
  .primary { min-height:40px; padding:5px 2px; font-size:10px; letter-spacing:0; }
}

/* 16:9 portrait phone with Chrome controls visible (e.g. 360 x 500 CSS px).
   dvh already excludes browser chrome; do not subtract toolbar heights twice. */
@media (max-width:600px) and (orientation:portrait) and (max-height:700px) {
  .formation-header { min-height:42px; padding:4px 6px; }
  .formation-header a,.formation-header button { min-height:30px; }
  .heading { flex-basis:20px; }
  .lane { grid-template-rows:22px minmax(0,1fr) 26px; }
  .swap { min-height:26px; font-size:8px; }
  .station { grid-template-rows:12px minmax(0,1fr) 18px; padding:2px 4px; }
  .scene .sprite { height:100%; max-height:80px; }
  .inspector { padding:6px; gap:6px; }
  .unit-header { gap:2px; }
  .unit-header .sprite { display:none; }
  .inspector h2 { font-size:14px; margin:3px 0; }
  .inspector .rule { flex-shrink:0; }
  .inspector .label { margin-bottom:4px; }
  .chip-slot { min-height:60px; padding:5px; gap:3px; }
  .chip-slot .num { width:16px; height:18px; font-size:12px; }
  .chip-slot .text { flex-basis:calc(100% - 24px); }
  .chip-slot small { display:none; }
  .chip-slot strong { font-size:10px; }
  .deploy { padding-top:5px; }
  .mode { margin:4px 0; gap:4px; }
  .mode button { min-height:32px; padding:3px; }
  .primary { min-height:34px; }
}

/* Extra viewport height is empty space, not stretched character scenery. */
@media (max-width:600px) and (orientation:portrait) {
  .board { grid-template-rows:repeat(3,minmax(0,152px)); align-content:start; }
  .lane { grid-template-rows:22px minmax(0,1fr) 26px; }
  .station { grid-template-rows:12px minmax(0,1fr) 18px; padding:2px 4px; }
  .scene .sprite { height:100%; max-height:80px; width:auto; }
  .swap { min-height:26px; font-size:8px; }
}
@media (max-width:1000px) and (orientation:landscape) {
  .board { max-height:330px; }
}

/* Place equipment names beneath the character name without growing the pair. */
@media (max-width:600px) and (orientation:portrait),
       (max-width:1000px) and (orientation:landscape) {
  .station { grid-template-rows:12px minmax(0,1fr) 14px 14px; }
  .station .name { margin:0; line-height:14px; align-self:center; }
  .station .mini-chips { display:flex; flex-direction:row; gap:3px; min-width:0; height:14px; }
  .station .mini-chip { display:block; flex:1 1 0; min-width:0; width:auto; height:14px; padding:0; border:0; border-radius:0; background:transparent; font-size:8px; line-height:14px; text-align:left; }
  .station .mini-chip b { font-size:8px; padding-right:3px; }
}
