/* v14: touch-first layouts, scoped to phones and tablets. */
@media(max-width:900px){
 html{scrollbar-gutter:auto;scroll-padding-bottom:150px}
 body{padding-bottom:calc(142px + env(safe-area-inset-bottom));overflow-x:clip}
 header{height:auto;min-height:0;padding:12px 16px;gap:12px;align-items:flex-start;flex-direction:column}
 .brand{font-size:25px;line-height:1.4;white-space:nowrap}.brand span{display:inline;font-size:14px;margin-left:12px;letter-spacing:0}
 .header-right{display:flex;max-width:none;width:100%;gap:8px;flex-wrap:nowrap;overflow-x:auto;padding-bottom:3px;scrollbar-width:thin}
 .header-right button,.header-right #settings,#book-entry{flex:0 0 auto;max-width:none;min-height:44px;font-size:14px;padding:8px 12px;white-space:nowrap;line-height:1.4}
 #progress{display:none}.visitor-stats{flex-wrap:wrap;font-size:13px;padding:6px 16px;gap:2px 12px}#stats-status{font-size:12px}
 .toolbar{padding:10px 16px}.toolbar nav{overflow-x:auto;justify-content:flex-start;min-width:0}.toolbar nav button{flex:1 0 44px;font-size:14px;padding:8px 7px}
 .search{display:grid;grid-template-columns:minmax(0,1fr) minmax(110px,.8fr);width:100%}#search,.search select{width:100%;min-width:0;max-width:none;font-size:16px}
 .stage{padding:16px;overflow:visible}.stage-heading>div:first-child{grid-template-columns:auto minmax(0,1fr);column-gap:12px;width:100%}.stage-heading{gap:0}
 h1{font-size:48px}#year-title{font-size:19px;overflow-wrap:anywhere}.stage-heading .eyebrow{font-size:13px}
 #same-year button{min-height:44px;font-size:14px}.globe-wrap{height:clamp(300px,85vw,430px)}
 .globe-wrap .map-meta{font-size:12px;gap:8px;letter-spacing:0}.map-meta span:last-child{display:none}
 .map-modes{top:38px;left:8px;max-width:calc(100% - 16px);gap:5px}.map-modes button{min-height:44px;font-size:14px;padding:6px 9px}
 .globe-controls button{min-height:44px;min-width:44px}.map-card{padding:16px}.map-card p{font-size:16px}.map-card .actions{gap:8px}.map-card .actions button{min-height:44px;font-size:14px}
 .map-caption{font-size:12px;line-height:1.7}.event small,.event p{font-size:14px}#events{max-height:380px}
 footer{height:calc(136px + env(safe-area-inset-bottom));padding:10px 16px calc(8px + env(safe-area-inset-bottom))}
 #time-rail{display:none}.timeline-top{display:grid;grid-template-columns:88px minmax(0,1fr) 88px;gap:8px}.timeline-top button{min-width:0;min-height:44px;padding:6px;font-size:14px}
 #current-label{max-width:none;font-size:13px;text-align:center;line-height:1.5;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
 #slider{min-height:32px;height:32px;margin:4px 0 0}.ruler{font-size:12px}.ruler span:nth-child(5){display:none}
 .view-content{overflow-x:auto}.card{padding:18px}.contradiction{padding:20px;font-size:22px}
 dialog{width:calc(100% - 20px);max-width:none;max-height:calc(100dvh - 24px);padding:22px 18px;overscroll-behavior:contain}dialog h2{font-size:24px;overflow-wrap:anywhere}
 body:has(dialog[open]){overflow:hidden}#toast{max-width:calc(100vw - 32px);width:max-content;bottom:calc(150px + env(safe-area-inset-bottom));font-size:14px;padding:10px 16px}
 input,select,textarea{font-size:16px}
 #book-hub{width:100%;padding:20px 16px 32px}.book-top{align-items:flex-start;flex-wrap:wrap;gap:12px}.book-top h1{font-size:26px}
 .book-controls{flex-wrap:wrap}#book-tabs{width:100%;flex:none;overflow-x:auto;justify-content:flex-start}#book-tabs button{flex:1 0 auto;min-height:44px;font-size:14px;padding:7px 10px}
 .book-search{width:100%;display:grid;grid-template-columns:minmax(0,1fr) 125px}.book-search input,.book-search select{width:100%;min-width:0;font-size:16px}
 .book-layout{display:block}.chapter-list{position:static;max-height:240px;margin-bottom:20px}.chapter-list button{width:100%}.chapter-heading>div{min-width:0}.chapter-heading{flex-wrap:wrap;gap:12px}
 .point-grid,.bridge-grid{grid-template-columns:1fr}.source-head,.reader-heading{flex-wrap:wrap}#book-reader{padding:16px}.page-nav button,.book-tags button{min-height:44px;font-size:14px}
 #story-dialog{width:100%;max-width:100%;height:100dvh;max-height:100dvh;margin:0;border-radius:0;padding:calc(12px + env(safe-area-inset-top)) 12px calc(20px + env(safe-area-inset-bottom));overflow-x:hidden}
 .story-heading{gap:10px}.story-heading h2{font-size:22px;margin:4px 0 16px}#story-close{flex:none;align-self:flex-start;min-height:44px;min-width:44px}
 .story-layout{display:block}.story-source{gap:12px}.story-source label{min-width:0}.story-source select,.story-source input{font-size:16px;width:100%;max-width:none}.story-filter,.story-picker{flex-basis:100%}
 #story-canvas{display:block;border-radius:8px}.story-playbar{gap:8px;padding:10px}.story-playbar button,.story-export button{min-height:44px;font-size:14px}.story-speed select{width:auto;min-height:44px;font-size:16px}
 .story-voice{min-height:44px;font-size:14px}.story-voice input{width:20px;height:20px}.story-export>*{max-width:100%}#story-seek{min-height:44px}
 #story-caption{font-size:17px;line-height:1.85;padding:12px 14px}#story-current{font-size:16px}#story-chapters{flex-wrap:nowrap;overflow-x:auto;padding-bottom:8px}#story-chapters button{flex:none;min-width:44px;min-height:44px}
 .story-editor{max-height:none;border-left:0;padding:20px 0 0}.story-editor input,.story-editor textarea,.scene-theme-label select{font-size:16px}.story-editor-pages{flex-wrap:wrap;position:static}.story-editor-pages button{min-height:44px}
 .story-focused #story-canvas{max-height:none}.story-focused .story-player{width:100%}
}
@media(max-width:360px){.brand span{font-size:12px}.search,.book-search{grid-template-columns:1fr}.timeline-top{grid-template-columns:76px minmax(0,1fr) 76px}.stage{padding:12px}.map-modes button{font-size:13px;padding:6px 8px}}
@media(max-width:900px) and (orientation:landscape) and (max-height:500px){body{padding-bottom:0}footer{position:static;height:auto;padding-bottom:max(10px,env(safe-area-inset-bottom))}.globe-wrap{height:320px}#story-dialog{padding-top:10px}.story-focused #story-canvas{max-height:calc(100dvh - 85px);width:100%;object-fit:contain}}
@media(max-width:900px){.header-right{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));overflow:visible}.header-right button,.header-right #settings,#book-entry{width:100%;padding:8px 5px;white-space:normal}#story-entry,#book-entry{color:var(--gold);border-color:#506067}}
