/* Learning uses the available viewport; the home and settings keep normal scrolling.
   Keep this file identical in hanja and cheonjamun, including native web bundles. */
.app-shell[data-view=study]{height:100dvh;max-width:1224px;padding:8px max(12px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));display:flex;flex-direction:column}
.app-shell[data-view=study] .app-header,.app-shell[data-view=study] .app-footer,.app-shell[data-view=study] .course-bar,.app-shell[data-view=study] .study-shelf-art,.app-shell[data-view=study] .study-bottom{display:none}
.app-shell[data-view=study] #app{min-height:0;flex:1;display:flex;flex-direction:column;gap:8px}
.app-shell[data-view=study] .study-head{flex:none;min-height:44px;margin:0;gap:12px}
.app-shell[data-view=study] .study-head .exit{width:44px;height:44px}
.app-shell[data-view=study] .study-head-text small{margin-top:2px}
.app-shell[data-view=study] .study-scene{flex:1;min-height:0;overflow:visible}
.app-shell[data-view=study] .study-board{height:100%;min-height:0;padding:16px;overflow:visible}
.app-shell[data-view=study] .primary{min-height:48px;padding:10px 18px;flex-shrink:0}
.app-shell[data-view=study] .feedback{min-height:32px;padding:4px 0;line-height:1.5}

/* A square canvas sized by BOTH axes, without changing pointer coordinates. */
.app-shell[data-view=study] .writing-layout{display:grid;grid-template-columns:minmax(200px,280px) minmax(0,1fr);gap:24px;align-items:stretch}
.app-shell[data-view=study] .writing-info{display:flex;flex-direction:column;justify-content:center;gap:12px;min-height:0;width:100%}
.app-shell[data-view=study] .writing-info h1{font-size:20px;margin:0}
.app-shell[data-view=study] .writing-info .word-reading{font-size:24px;margin:0;line-height:1.4}
.app-shell[data-view=study] .write-counter{padding:12px;margin:0}
.app-shell[data-view=study] .write-counter strong{font-size:26px;margin:4px 0}
.app-shell[data-view=study] .write-dots{display:none}
.app-shell[data-view=study] .writing-modes{margin:0;padding:3px;gap:4px}
.app-shell[data-view=study] .writing-modes button{min-height:44px}
.app-shell[data-view=study] .writing-tools{display:flex;flex-wrap:wrap;gap:6px}
.app-shell[data-view=study] .writing-tools button{flex:1 1 auto;min-height:44px;padding:8px;font-size:13px}
.app-shell[data-view=study] .writing-buddy{display:none}
.app-shell[data-view=study] .writing-surface{width:100%;max-width:none;min-height:0;margin:0;display:flex;flex-direction:column;gap:4px}
.app-shell[data-view=study] .writing-topline{flex:none;padding:0;min-height:20px}
.app-shell[data-view=study] .writing-pad-space{flex:1;min-height:160px;container-type:size;display:grid;place-items:center}
.app-shell[data-view=study] .writing-canvas{width:min(100cqw,100cqh);height:auto;max-width:100%;min-width:0;max-height:100%;aspect-ratio:1;margin:0}
.app-shell[data-view=study] .writing-surface .feedback{flex:none;min-height:32px;margin:0}
.app-shell[data-view=study] .writing-surface .primary{margin:0}

.app-shell[data-view=study] .lesson-layout{grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:24px;align-items:center}
.app-shell[data-view=study] .lesson-character{min-height:0;height:100%;max-height:420px;width:100%;max-width:440px}
.app-shell[data-view=study] .lesson-character .hanja{font-size:clamp(90px,22vh,190px)}
.app-shell[data-view=study] .lesson-details{gap:12px;min-height:0}
.app-shell[data-view=study] .lesson-details .primary{width:100%;margin:0}
.app-shell[data-view=study] .lesson-details dl{gap:6px 20px}
.app-shell[data-view=study] .phrase{gap:6px;font-size:13px}
.app-shell[data-view=study] .phrase .hanja{font-size:22px;letter-spacing:3px}
.app-shell[data-view=study] .quiz-layout{height:100%;display:grid;grid-template-columns:minmax(0,.85fr) minmax(0,1.15fr);grid-template-rows:auto minmax(0,1fr) auto auto;gap:8px 24px;padding:0}
.app-shell[data-view=study] .quiz-layout h1{font-size:20px;line-height:1.4;margin:0}
.app-shell[data-view=study] .quiz-character{font-size:clamp(90px,22vh,190px);line-height:1.1}
.app-shell[data-view=study] .answers{height:100%;max-height:260px;align-self:center;gap:10px}
.app-shell[data-view=study] .answer{min-height:48px;padding:8px;font-size:24px}
.app-shell[data-view=study] #answer-feedback{min-height:32px;margin:0}
.app-shell[data-view=study] #after-answer{margin:0}

@media(max-width:620px){
 .app-shell[data-view=study] .study-board{padding:10px}
 .app-shell[data-view=study] .writing-layout{display:flex;flex-direction:column;gap:10px}
 .app-shell[data-view=study] .writing-info{display:grid;flex:none;grid-template-columns:1fr 1fr;gap:6px 10px}
 .app-shell[data-view=study] .writing-info h1{grid-column:1;grid-row:1;font-size:16px}
 .app-shell[data-view=study] .writing-info .word-reading{grid-column:2;grid-row:1;font-size:20px;text-align:right}
 .app-shell[data-view=study] .write-counter{grid-column:1;grid-row:2;display:flex;align-items:center;justify-content:space-between;gap:6px;padding:6px 8px;min-height:50px}
 .app-shell[data-view=study] .write-counter small{font-size:12px}
 .app-shell[data-view=study] .write-counter strong{font-size:22px;margin:0;white-space:nowrap}
 .app-shell[data-view=study] .writing-modes{grid-column:2;grid-row:2}
 .app-shell[data-view=study] .writing-tools{grid-column:1/-1;grid-row:3;flex-wrap:nowrap}
 .app-shell[data-view=study] .writing-tools button{flex:1;min-width:0;padding:6px 4px;font-size:12px}
 .app-shell[data-view=study] .writing-surface{flex:1}
 .app-shell[data-view=study] .lesson-layout{display:flex;flex-direction:column;gap:12px}
 .app-shell[data-view=study] .lesson-character{flex:1;min-height:100px;max-height:none;max-width:360px}
 .app-shell[data-view=study] .lesson-character .hanja{font-size:clamp(80px,22vh,160px)}
 .app-shell[data-view=study] .lesson-details{flex:none;width:100%;gap:8px}
 .app-shell[data-view=study] .lesson-details .eyebrow{display:none}
 .app-shell[data-view=study] .lesson-details .word-reading{font-size:26px}
 .app-shell[data-view=study] .lesson-details dl{grid-template-columns:auto auto auto auto;gap:6px 12px}
 .app-shell[data-view=study] .quiz-layout{display:flex;flex-direction:column;gap:6px}
 .app-shell[data-view=study] .quiz-character{flex:1;min-height:0;display:grid;place-items:center;font-size:clamp(80px,20vh,160px)}
 .app-shell[data-view=study] .quiz-layout h1{font-size:18px}
 .app-shell[data-view=study] .quiz-meaning{font-size:14px}
 .app-shell[data-view=study] .answers{flex:none;height:auto;min-height:116px}
 .app-shell[data-view=study] #after-answer{flex:none}
}
@media(min-width:621px) and (max-height:520px){
 .app-shell[data-view=study] .study-board{padding:10px}
 .app-shell[data-view=study] .writing-info{gap:6px}
 .app-shell[data-view=study] .writing-info h1{font-size:16px}
 .app-shell[data-view=study] .writing-info .word-reading{font-size:20px}
 .app-shell[data-view=study] .write-counter{display:flex;align-items:center;justify-content:space-between;padding:6px 8px}
 .app-shell[data-view=study] .write-counter strong{font-size:22px;margin:0}
 .app-shell[data-view=study] .lesson-details{gap:6px}
 .app-shell[data-view=study] .lesson-details .eyebrow{display:none}
 .app-shell[data-view=study] .lesson-details .word-reading{font-size:24px}
}
/* Native system bars and the app exit row reduce a landscape phone below 300px. */
@media(min-width:621px) and (max-height:360px){
 .app-shell[data-view=study] .writing-info h1{display:none}
 .app-shell[data-view=study] .writing-info{gap:4px}
 .app-shell[data-view=study] .writing-info .word-reading{font-size:18px}
 .app-shell[data-view=study] .writing-pad-space{min-height:100px}
 .app-shell[data-view=study] .writing-tools button{padding:6px 4px;font-size:12px}
 .app-shell[data-view=study] .lesson-details dl{grid-template-columns:auto auto auto auto;gap:4px 10px}
 .app-shell[data-view=study] .lesson-details .word-reading{font-size:22px}
 .app-shell[data-view=study] .lesson-character .hanja,.app-shell[data-view=study] .quiz-character{font-size:clamp(70px,28vh,100px)}
 .app-shell[data-view=study] .quiz-layout h1{font-size:16px}
 .app-shell[data-view=study] .answers{grid-template-columns:repeat(4,minmax(0,1fr));height:auto;min-height:48px;max-height:none;gap:8px}
 .app-shell[data-view=study] .answer{font-size:20px}
}
/* Outside supported phone heights, preserve access through normal scrolling. */
@media(max-height:240px){.app-shell[data-view=study]{height:auto;min-height:100dvh}.app-shell[data-view=study] .writing-pad-space{height:160px;flex:none}}

/* Recovery controls must never steal the only usable writing area. Scroll on
   small screens instead of clipping controls or shrinking the pad to a sliver.
   This patch is scoped to the Hanja recovery view, not other app bundles. */
.app-shell[data-view=study]:has(.recovery-writing){height:auto;min-height:100dvh}
.app-shell[data-view=study]:has(.recovery-writing) #app{flex:none;min-height:0}
.app-shell[data-view=study]:has(.recovery-writing) .study-scene{flex:none}
.app-shell[data-view=study] .recovery-writing{height:auto;min-height:0;align-items:start}
.app-shell[data-view=study] .recovery-writing [hidden]{display:none!important}
.app-shell[data-view=study] .recovery-writing .writing-info{display:flex;flex-direction:column;align-items:stretch;gap:10px}
.app-shell[data-view=study] .recovery-writing .writing-info>*{grid-column:auto;grid-row:auto}
.app-shell[data-view=study] .recovery-writing .writing-phase{font-size:14px;line-height:1.5}
.app-shell[data-view=study] .recovery-writing .writing-tools{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px}
.app-shell[data-view=study] .recovery-writing .writing-tools button{min-height:44px;white-space:normal}
.app-shell[data-view=study] .recovery-writing .writing-recovery{display:flex;flex-wrap:wrap;gap:8px}
.app-shell[data-view=study] .recovery-writing .writing-recovery button{flex:1;min-width:110px;padding:10px}
.app-shell[data-view=study] .recovery-writing .writing-help-note{font-size:13px;line-height:1.55}
.app-shell[data-view=study] .recovery-writing .writing-pad-space{container-type:normal;flex:none;height:auto;min-height:0;width:100%;display:block}
.app-shell[data-view=study] .recovery-writing .writing-canvas{display:block;width:100%;height:auto;min-width:0;max-height:none;aspect-ratio:1}
.app-shell[data-view=study] .recovery-writing .writing-surface{max-width:540px;justify-self:center}
.app-shell[data-view=study] .recovery-writing .memory-writing-choice{display:flex;flex-direction:column;gap:16px;padding:20px;line-height:1.6;align-self:center}
.app-shell[data-view=study]:has(.recovery-writing) .study-bottom{display:block}
@media(max-width:620px){
 .app-shell[data-view=study] .recovery-writing .writing-info .word-reading{text-align:left}
 .app-shell[data-view=study] .recovery-writing .writing-info h1{display:block}
 .app-shell[data-view=study] .recovery-writing .writing-surface{flex:none}
}

/* Keep the pad near the top on narrow phones; advanced tools follow it rather
   than pushing the writing surface a full screen below the fold. */
@media(max-width:620px){
 .app-shell[data-view=study] .recovery-writing .writing-info{display:contents}
 .app-shell[data-view=study] .recovery-writing .writing-info h1{order:0;margin:0}
 .app-shell[data-view=study] .recovery-writing .word-reading{order:1;margin:0}
 .app-shell[data-view=study] .recovery-writing .write-counter{order:2;width:100%;min-height:36px}
 .app-shell[data-view=study] .recovery-writing .writing-modes{order:3;width:100%}
 .app-shell[data-view=study] .recovery-writing .writing-surface,
 .app-shell[data-view=study] .recovery-writing .memory-writing-choice{order:4;width:100%}
 .app-shell[data-view=study] .recovery-writing .writing-recovery{order:5;width:100%}
 .app-shell[data-view=study] .recovery-writing .writing-tools{order:6;width:100%}
 .app-shell[data-view=study] .recovery-writing .writing-phase{order:7;margin:0}
 .app-shell[data-view=study] .recovery-writing .writing-help-note{order:8;margin:0}
}
