/* Phone viewports keep controls clear of browser chrome and the painted table. */
@media (max-width:650px), (max-width:950px) and (max-height:500px) and (orientation:landscape) {
 :root {
  --phone-top:env(safe-area-inset-top,0px);
  --phone-bottom:env(safe-area-inset-bottom,0px);
  --phone-left:max(12px,env(safe-area-inset-left,0px));
  --phone-right:max(12px,env(safe-area-inset-right,0px));
  --phone-header:calc(60px + var(--phone-top));
  --table-footer:calc(50px + var(--phone-bottom));
 }

 button {touch-action:manipulation}
 .tarot-room .t-header,.tarot-room.story-room .t-header,.words-room .w-top,.card-atlas .atlas-header,
 #modal>.modal-head,#modal:has(.moments-clock,.moments-keepsake)>.modal-head {
  width:100%;height:auto;min-height:var(--phone-header);box-sizing:border-box;
  padding:var(--phone-top) var(--phone-right) 0 var(--phone-left);
 }
 .tarot-room .t-header .t-brand,.words-room .w-top>span {min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
 .tarot-room .t-header>div,.tarot-room .t-header .t-compass,.words-room #w-exit {flex-shrink:0}
 .tarot-room .t-header button,.tarot-room .t-header .t-compass,.words-room #w-exit,.card-atlas .atlas-header button,
 #modal #close-modal,.study-detail-home,.tarot-room .t-brass,
 .connection-note-nav button,.connection-actions button,.connection-mobile-back,
 .w-tabs button,.w-photo-toolbar button,.moments-keepsake button:not(.keepsake-object,.keepsake-lid) {min-height:44px}
 .tarot-room .t-header button:not(.t-compass) {min-width:44px}
 .tarot-room .t-progress {bottom:var(--phone-bottom);pointer-events:none}
 .d-room .d-progress {bottom:var(--phone-bottom);flex-wrap:wrap}
 .tarot-room :is(textarea,input:not([type=checkbox],[type=radio]),select),
 .words-room :is(textarea,input:not([type=checkbox],[type=radio]),select),
 #modal :is(textarea,input:not([type=checkbox],[type=radio]),select) {font-size:16px;min-width:0}
 .tarot-room :is(.t-letter,.t-reading-page,.d-reading),.words-room .w-message,#modal .keepsake-text {overflow-wrap:anywhere}
 .tarot-room.story-room[data-step=letter].t-without-scene .t-main {
  padding-top:calc(var(--phone-header) + 8px);padding-bottom:calc(48px + var(--phone-bottom));
 }
 .words-room .w-layout {padding-bottom:var(--phone-bottom)}
 .moments-clock,.moments-keepsake {min-height:calc(100dvh - var(--phone-header))}
 #modal:has(.moments-clock,.moments-keepsake)>.modal-head {margin-bottom:0}
 .moments-keepsake {padding-bottom:calc(24px + var(--phone-bottom))}

 .tarot-room.story-room:is([data-step=shuffle],[data-step=draw]) .t-main>.t-draw-controls {bottom:var(--table-footer)}
 .tarot-room.story-room[data-step=shuffle] .t-main>#t-shuffle-status,
 .tarot-room.story-room[data-step=draw] .t-main>#t-draw-status {bottom:calc(var(--table-footer) + 48px)}
 .tarot-room.story-room[data-step=reveal] .t-main>.t-actions {bottom:var(--table-footer);flex-wrap:wrap}
 .tarot-room.story-room[data-step=reveal] #t-envelope-space {bottom:var(--table-footer)}
 .tarot-room.story-room[data-step=reveal]:has(#t-open-letter) .t-main>.t-actions {
  top:calc(var(--phone-header) + 6px);bottom:auto;left:auto;right:var(--phone-right);width:auto;
 }
 .tarot-room.story-room[data-step=reveal] .t-main>.t-actions .t-quiet {min-height:44px}
 .tarot-room.story-room[data-step=reveal] #t-reveal-hint {bottom:calc(var(--table-footer) + 48px)}
}

@media (max-width:650px) and (orientation:portrait) {
 .tarot-room.story-room[data-step=verify] .t-header {height:var(--phone-header);margin:0}
 .tarot-room.story-room[data-step=verify] .t-main,.tarot-room.story-room[data-step=verify] .t-scene-window {
  height:100dvh;min-height:0;
 }
 .tarot-room.story-room[data-step=verify] .connection-intro {top:30dvh}
 .tarot-room.story-room[data-step=verify] .t-table-content {top:44dvh;height:calc(56dvh - 12px - var(--phone-bottom))}
 .tarot-room.story-room[data-step=verify] .connection-dice-stage {justify-content:flex-start}
 .tarot-room.story-room[data-step=verify][data-connection-page=notes] .connection-note {
  top:calc(var(--phone-header) + 6px);bottom:calc(119px + var(--phone-bottom));
 }
 .tarot-room.story-room[data-step=verify][data-connection-page=notes] .connection-decision {bottom:calc(8px + var(--phone-bottom));height:104px}
 .connection-note-body {overflow:auto;overscroll-behavior:contain}
 .connection-note-nav,.connection-note-heading,.connection-mobile-back {flex-shrink:0}
 .connection-clues label {min-height:44px}
 .tarot-room.story-room[data-step=tuning] .t-main>.t-actions {bottom:var(--table-footer)}
 .tarot-room.story-room[data-step=tuning] .t-main>.t-whisper {bottom:calc(var(--table-footer) + 56px)}
 .tarot-room.story-room:is([data-step=shuffle],[data-step=draw],[data-step=reveal]) .t-table-content {
  left:11%;width:78%;top:58dvh;height:max(102px,calc(42dvh - 129px - var(--phone-bottom)));
  transform:perspective(950px) rotateX(30deg);
 }
 .tarot-room.story-room[data-step=reveal] .t-envelope {height:60px}
 .tarot-room.d-room .d-main {padding-inline:var(--phone-left) var(--phone-right)}
 .d-entry-grid {grid-template-columns:repeat(2,minmax(0,1fr))}
 .d-entry-grid select {width:100%;min-height:44px}
 .tarot-room.d-room[data-step=deck-wash] .d-main {padding-bottom:0}
 .d-room[data-step=deck-wash] .d-hand-wash {height:clamp(130px,calc(47dvh - 128px - var(--phone-bottom)),270px);transform:none}
 .d-room[data-step=deck-wash] .d-console {
  position:absolute;top:auto;bottom:calc(40px + var(--phone-bottom));left:var(--phone-left);right:var(--phone-right);width:auto;
 }
 .d-room[data-step=deck-wash] .d-console p {margin:0}
 .d-room[data-step=deck-wash] .d-actions {margin:5px 0}
 .d-room[data-step=deck-wash] .d-console>small {line-height:1.45}
}

@media (max-width:650px) and (max-height:700px) and (orientation:portrait) {
 .tarot-room.story-room[data-step=verify] .connection-die,
 .tarot-room.story-room[data-step=verify] .die-space {width:88px}
 .tarot-room.story-room[data-step=verify] .die-space {height:88px}
 .tarot-room.story-room[data-step=verify] .die-model {scale:.55}
}

@media (max-width:950px) and (max-height:500px) and (orientation:landscape) {
 .tarot-room.story-room .story-room-backdrop>img {object-position:center bottom}
 .tarot-room.story-room[data-step=verify] .t-main {height:100dvh;min-height:0;padding:0}
 .tarot-room.story-room[data-step=verify] .t-table-content {top:calc(var(--phone-header) + 8px);left:10%;width:46%;height:calc(100dvh - var(--phone-header) - var(--phone-bottom) - 20px)}
 .tarot-room.story-room[data-step=verify] .connection-note {top:calc(var(--phone-header) + 8px);right:4%;width:38%;height:calc(100dvh - var(--phone-header) - var(--phone-bottom) - 18px);margin:0;padding:12px 16px}
 .tarot-room.story-room[data-step=verify] .connection-note-body {overflow:auto;min-height:0}
 .tarot-room.story-room[data-step=verify] .connection-dice-stage {gap:4px}
 .tarot-room.story-room[data-step=verify] .connection-die,
 .tarot-room.story-room[data-step=verify] .die-space {width:88px}
 .tarot-room.story-room[data-step=verify] .die-space {height:88px}
 .tarot-room.story-room[data-step=verify] .die-model {scale:.55}
 .tarot-room.story-room[data-step=verify] .connection-die>span {font-size:11px}
 .tarot-room.story-room[data-step=verify] .connection-zodiac-result b {font-size:18px}
 .tarot-room.story-room[data-step=verify] .connection-zodiac-result p {font-size:11px;line-height:1.6;margin:4px 0}
 .tarot-room.story-room[data-step=verify] .connection-note h3 {font-size:18px;margin:5px 0}
 .tarot-room.story-room[data-step=verify] .connection-wait {font-size:12px;line-height:1.5}
 .tarot-room.story-room[data-step=verify] .connection-wait>span {font-size:28px}
 .tarot-room.story-room[data-step=verify] .connection-wait p {font-size:12px;line-height:1.6}
 .tarot-room.story-room[data-step=verify] .connection-note .connection-begin {margin:8px 0 0;padding:10px 8px;min-height:44px;font-size:12px}
 .tarot-room.story-room[data-step=verify] .connection-intro,
 .tarot-room.story-room[data-step=verify][data-connection-page=notes] .t-table-content,
 .tarot-room.story-room[data-step=verify][data-connection-page=dice] .connection-decision {visibility:hidden}
 .tarot-room.story-room[data-step=verify][data-connection-page=notes] .connection-note {
  position:fixed;top:calc(var(--phone-header) + 8px);bottom:calc(90px + var(--phone-bottom));
  left:10%;right:10%;width:auto;height:auto;min-height:0;transform:none;
 }
 .tarot-room.story-room[data-step=verify][data-connection-page=notes] .connection-decision {
  position:fixed;left:10%;right:10%;bottom:var(--phone-bottom);width:auto;height:78px;margin:0;
  padding:4px 8px;gap:8px;text-align:center;grid-template-columns:auto minmax(0,1fr);background:#1c141bee;
 }
 .tarot-room.story-room[data-step=verify][data-connection-page=notes] .connection-actions {grid-row:1;grid-column:2;justify-content:center}
 .tarot-room.story-room[data-step=verify] .connection-decision>p,
 .tarot-room.story-room[data-step=verify] .connection-decision>small {display:none}
 .tarot-room.story-room[data-step=verify] .connection-note-nav {flex-shrink:0}
 .tarot-room.story-room[data-step=tuning] .t-table-content {top:40dvh;height:36dvh}
 .tarot-room.story-room[data-step=tuning] .t-main>.t-actions {bottom:var(--table-footer)}
 .tarot-room.story-room[data-step=tuning] .t-main>.t-whisper {bottom:calc(var(--table-footer) + 48px)}
 .tarot-room.story-room:is([data-step=shuffle],[data-step=draw],[data-step=reveal]) .t-table-content {
  left:24%;width:52%;top:48dvh;height:max(120px,38dvh);transform:perspective(950px) rotateX(25deg);
 }
 .tarot-room.story-room:is([data-step=shuffle],[data-step=draw],[data-step=reveal]) .t-scene-window>.t-heading {
  left:3%;top:calc(var(--phone-header) + 12px);width:23%;margin:0;padding:10px;
 }
 .tarot-room.story-room:is([data-step=shuffle],[data-step=draw],[data-step=reveal]) .t-heading h1 {font-size:18px}
 .tarot-room.story-room:is([data-step=shuffle],[data-step=draw],[data-step=reveal]) .t-heading .t-eyebrow {display:none}
 .tarot-room.story-room[data-step=shuffle] .t-main>#t-shuffle-status,
 .tarot-room.story-room[data-step=draw] .t-main>#t-draw-status,
 .tarot-room.story-room[data-step=reveal] .t-main>#t-reveal-hint {left:3%;right:auto;width:20%;bottom:var(--table-footer)}
 .tarot-room.story-room:is([data-step=shuffle],[data-step=draw],[data-step=reveal]) .t-main>:is(.t-draw-controls,.t-actions,#t-envelope-space) {
  left:auto;right:2%;width:22%;bottom:var(--table-footer);flex-wrap:wrap;gap:4px;
 }
 .tarot-room.story-room[data-step=draw] .t-draw-controls .t-brass {order:-1;width:100%;min-width:0}
 .tarot-room.story-room[data-step=reveal] .t-envelope {width:min(100%,150px);height:60px}
 .tarot-room:is([data-step=draw],[data-step=reveal]) {--draw-fan-width:68px;--draw-slot-width:54px}
 .tarot-room.story-room[data-step=letter].t-without-scene .t-main {
  height:auto;min-height:100dvh;padding-bottom:calc(40px + var(--phone-bottom));
 }
 .tarot-room[data-step=letter] .t-reading-workspace {flex:none}
 .tarot-room[data-step=letter] .t-reading-pages {flex:none;height:max(180px,55dvh)}
 .tarot-room.story-room[data-step=letter] .t-main>.t-heading {margin:0}
 .tarot-room[data-step=letter] .t-heading h1 {font-size:20px}
 .tarot-room[data-step=letter] .t-heading p {display:none}
 .t-reading-question {padding-block:8px}

 .tarot-room.d-room[data-step=deck-wash] .d-main {padding:0}
 .d-room[data-step=deck-wash] .d-caption {
  top:calc(var(--phone-header) + 12px);left:4%;width:24%;text-align:left;
 }
 .d-room[data-step=deck-wash] .d-caption>span {display:none}
 .d-room[data-step=deck-wash] .d-table {position:absolute;top:40dvh;left:30%;width:65%;min-height:0}
 .d-room[data-step=deck-wash] .d-hand-wash {height:calc(58dvh - 30px - var(--phone-bottom));transform:none}
 .d-room[data-step=deck-wash] .d-console {
  position:absolute;top:auto;bottom:calc(46px + var(--phone-bottom));left:4%;width:24%;text-align:left;
 }
 .d-room[data-step=deck-wash] .d-actions {justify-content:flex-start}
}
