/* Mobile presentation only. The desktop scene keeps its original containing
   block and coordinates: this wrapper must not generate a box above 900px. */
.scene-map-plane { display:contents; }
.game-hud > .game-hud-more { display:none; }
.hud-label-mobile { display:none; }
.mobile-menu-layer { display:none; }
.mobile-menu-layer[hidden] { display:none !important; }

@media (max-width:900px) {
  body:has(.game-hud) {
    --game-hud-height:calc(72px + env(safe-area-inset-bottom,0px));
  }

  body:has(.game-hud) #app.wrap {
    width:100%;min-width:0;max-width:100%;
    padding-inline:12px;
    padding-bottom:calc(var(--game-hud-height) + 28px);
  }

  body:has(.sect-scene) #app.wrap { padding-inline:8px; }

  /* The mark, resources and calendar share the header without squeezing the
     illustration or making the resource line horizontally scrollable. */
  body:has(.game-hud) .topbar.scene-topbar {
    display:grid;grid-template-columns:minmax(88px,1fr) minmax(0,2fr);
    align-items:center;gap:2px 12px;
    padding:10px 4px 12px;margin:0;
    min-width:0;width:100%;
  }

  body:has(.game-hud) .topbar.scene-topbar .logo-home {
    grid-column:1;grid-row:1 / 3;justify-self:start;
    display:flex;align-items:center;min-height:48px;min-width:0;
    width:100%;max-width:140px;
  }

  body:has(.game-hud) .topbar.scene-topbar .calligraphy-logo {
    width:100%;height:auto;max-width:140px;max-height:48px;
    object-position:left center;
  }

  body:has(.game-hud) .topbar.scene-topbar .res {
    display:contents;font-size:15px;line-height:1.6;
    color:#344e3e;
  }

  body:has(.game-hud) .topbar.scene-topbar .res > .currency-chip {
    grid-column:2;grid-row:1;justify-self:end;
    display:flex;flex-wrap:wrap;justify-content:flex-end;
    gap:4px;min-width:0;max-width:100%;
    font-size:15px;line-height:1.6;white-space:normal;
    overflow-wrap:anywhere;
  }

  body:has(.game-hud) .topbar.scene-topbar .res > span:not(.currency-chip):not(.cal) {
    grid-column:2;grid-row:2;justify-self:end;
    min-width:0;max-width:100%;
    font-size:15px;line-height:1.6;text-align:right;
    white-space:normal;overflow-wrap:anywhere;
  }

  body:has(.game-hud) .topbar.scene-topbar .hud-energy-next {
    display:block;color:#526452;font-size:15px;
  }

  body:has(.game-hud) .topbar.scene-topbar .res .cal {
    grid-column:1 / -1;grid-row:3;justify-self:stretch;
    margin-top:5px;padding-top:7px;
    border-top:1px solid rgba(72,98,77,.18);
    font-size:15px;line-height:1.65;text-align:left;
    white-space:normal;overflow-wrap:anywhere;
  }

  body:has(.game-hud) .topbar.scene-topbar .res .pips { display:none; }
  body:has(.game-hud) .topbar.scene-topbar .scene-dev-controls {
    grid-column:1 / -1;grid-row:4;justify-self:end;
  }

  /* Mobile is a reading flow around the original 16:9 artwork, not a shrunk
     desktop canvas. Text is never baked into or positioned over the map. */
  .sect-scene-viewport {
    width:100%;max-width:100%;min-width:0;
    overflow:visible;border:0;overscroll-behavior:auto;
  }

  .sect-scene {
    display:flex;flex-direction:column;
    width:100%;min-width:0;max-width:100%;min-height:0;
    aspect-ratio:auto;overflow:visible;isolation:auto;
    background:transparent;font-size:16px;line-height:1.65;
  }

  .sect-scene::before { display:none; }

  .sect-scene .scene-profile {
    order:1;position:relative;inset:auto;z-index:auto;
    width:100%;min-width:0;max-width:none;height:auto;min-height:88px;
    gap:12px;margin:0;padding:12px;
    border-left:2px solid rgba(49,80,59,.52);
    background:linear-gradient(105deg,rgba(248,247,234,.94),rgba(237,242,227,.66));
    box-shadow:none;
  }

  .sect-scene .scene-profile-seal { width:54px;height:54px; }
  .sect-scene .scene-profile-text { gap:2px; }
  .sect-scene .scene-profile-text small { font-size:15px;line-height:1.5; }
  .sect-scene .scene-profile-text strong { font-size:25px;line-height:1.35; }
  .sect-scene .scene-profile-text > span {
    font-size:15px;line-height:1.6;
    overflow:visible;text-overflow:clip;white-space:normal;
    overflow-wrap:anywhere;
  }

  .sect-scene .sect-scene-heading {
    order:2;position:relative;inset:auto;z-index:auto;
    display:grid;grid-template-columns:minmax(0,1fr);gap:4px;
    width:100%;min-width:0;max-width:none;
    padding:17px 12px 13px;
    pointer-events:auto;text-shadow:none;
    background:linear-gradient(180deg,rgba(246,246,232,.72),rgba(246,246,232,.28));
  }

  .sect-scene .sect-scene-heading .eyebrow {
    flex-wrap:wrap;gap:5px 8px;margin:0;
    font-size:15px;line-height:1.6;letter-spacing:.025em;
  }

  .sect-scene .sect-scene-heading .scene-countdown { font-size:15px; }
  .sect-scene .sect-scene-heading :is(h1,h2) {
    flex-wrap:wrap;gap:2px 9px;
    font-size:30px;line-height:1.4;letter-spacing:.025em;
    text-wrap:wrap;word-break:keep-all;overflow-wrap:anywhere;
  }

  .sect-scene .sect-scene-heading :is(h1,h2) small {
    font-size:17px;line-height:1.5;
  }

  .sect-scene .sect-scene-heading .scene-competition-owner {
    flex-wrap:wrap;margin:2px 0 0;font-size:15px;line-height:1.6;
  }

  .sect-scene .scene-competition-owner strong { font-size:16px; }
  .sect-scene .scene-competition-rank {
    flex-wrap:wrap;gap:4px 16px;margin-top:3px;
    font-size:15px;line-height:1.6;
  }

  .sect-scene .scene-competition-rank strong { font-size:24px; }
  .sect-scene .scene-competition-rank strong small { font-size:15px; }
  .sect-scene .scene-competition-enter {
    justify-self:start;min-height:44px;margin:0;
    padding:5px 0;font-size:15px;text-shadow:none;
  }

  .scene-map-plane {
    order:3;display:block;position:relative;isolation:auto;
    width:100%;min-width:0;max-width:100%;aspect-ratio:16 / 9;
    overflow:visible;background:#d5dfd6;
  }

  .scene-map-plane .sect-scene-art {
    position:absolute;inset:0;z-index:0;
    width:100%;height:100%;object-fit:contain;
  }

  .scene-map-plane .sect-scene-mist { display:none; }

  /* The location wrapper has no transform/box. A fixed mobile explanation
     therefore remains anchored to the viewport, never to a 48px marker. */
  .sect-scene .scene-map-plane .scene-location {
    display:contents;position:static;inset:auto;
    width:auto;height:auto;transform:none;z-index:auto;
  }

  .sect-scene .scene-map-plane .scene-hotspot {
    position:absolute;left:var(--x,50%);top:var(--y,50%);z-index:2;
    transform:translate(-50%,-50%);
    width:48px;height:48px;min-width:48px;min-height:48px;
    padding:0;margin:0;
  }

  .sect-scene .scene-map-plane .scene-hotspot-ring {
    width:36px;height:36px;
    border:2px solid #684c2c;background:rgba(255,229,150,.9);
    box-shadow:0 0 0 2px rgba(255,252,229,.96),0 2px 7px rgba(49,44,21,.38),inset 0 0 0 2px rgba(255,251,226,.65);
  }

  .sect-scene .scene-map-plane .scene-hotspot-ring::before { width:12px;height:2px; }
  .sect-scene .scene-map-plane .scene-hotspot-ring::after { width:2px;height:12px; }
  .sect-scene .scene-map-plane .scene-hotspot[aria-expanded="true"] .scene-hotspot-ring {
    background:#ffe49a;border-color:#593c1e;
    box-shadow:0 0 0 3px #fff8db,0 0 0 5px #765c32;
  }

  .sect-scene .scene-map-plane .scene-location .scene-popover {
    position:fixed;inset:auto 12px calc(var(--game-hud-height) + 12px);
    z-index:65;transform:none;
    width:auto;min-width:0;max-width:none;
    max-height:calc(100vh - var(--game-hud-height) - 48px);
    max-height:min(48dvh,calc(100dvh - var(--game-hud-height) - 48px));
    overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;
    padding:16px 18px 12px;gap:7px;
    border:1px solid #99aa8f;border-radius:10px;
    background:#f5f4e8;box-shadow:0 8px 32px rgba(29,48,34,.24);
  }

  .sect-scene .scene-map-plane .scene-popover::before,
  .sect-scene .scene-map-plane .scene-popover::after { display:none; }
  .sect-scene .scene-popover-title { font-size:19px; }
  .sect-scene .scene-popover-detail { font-size:15px;line-height:1.75; }
  .sect-scene .scene-popover-action { min-height:48px;font-size:16px; }
  .scene-scroll-hint { display:none; }

  .sect-scene .scene-status {
    order:4;position:relative;inset:auto;z-index:auto;
    display:grid;grid-template-columns:repeat(2,minmax(0,1fr));
    align-items:stretch;gap:0;
    width:100%;min-width:0;max-width:none;
    padding:10px 0 6px;
    background:linear-gradient(180deg,rgba(244,244,229,.8),rgba(240,242,227,.38));
  }

  .sect-scene :is(.scene-cult-summary,.scene-pantry-summary) {
    width:100%;min-width:0;max-width:none;min-height:132px;
    padding:8px 12px;gap:7px;
    background:transparent;border-left:1px solid rgba(70,100,78,.25);
  }

  .sect-scene .scene-cult-summary { border-left:0; }
  .sect-scene .scene-summary-title {
    display:flex;flex-direction:column;align-items:flex-start;
    gap:3px;font-size:15px;line-height:1.5;
  }

  .sect-scene .scene-summary-title strong { font-size:24px;line-height:1.35; }
  .sect-scene .scene-summary-title small { font-size:15px; }
  .sect-scene .scene-summary-meta { font-size:15px;line-height:1.7;overflow-wrap:anywhere; }
  .sect-scene .scene-meter { min-width:0;height:5px; }

  .scene-journal {
    display:block;width:100%;min-width:0;
    padding:10px 12px;margin-top:6px;
  }

  .scene-journal .scene-latest {
    display:grid;grid-template-columns:minmax(0,1fr) auto;
    align-items:start;gap:5px 10px;width:100%;
    font-size:15px;line-height:1.75;
  }

  .scene-latest > span:first-child { grid-column:1;grid-row:1; }
  .scene-latest > span:nth-child(2) {
    grid-column:1 / -1;grid-row:2;
    overflow:visible;text-overflow:clip;white-space:normal;
    word-break:keep-all;overflow-wrap:anywhere;
  }

  .scene-latest > b { grid-column:2;grid-row:1;margin:0; }

  /* Five permanent destinations remain consistent on every map. The full
     destination set lives in the adjacent menu, with no horizontal nav drag. */
  body:has(.game-hud) .game-hud {
    left:0;right:0;bottom:0;transform:none;
    display:grid;grid-template-columns:repeat(5,minmax(0,1fr));
    align-items:stretch;gap:0;width:100%;min-width:0;max-width:none;
    height:var(--game-hud-height);
    padding:0 4px env(safe-area-inset-bottom,0px);
    background:rgba(244,243,230,.98);
    box-shadow:0 -3px 18px rgba(41,63,44,.12);
  }

  body:has(.game-hud) .game-hud-scroll { display:contents; }
  body:has(.game-hud) .game-hud .game-hud-scroll > button { display:none; }

  body:has(.game-hud) .game-hud .game-hud-scroll > button:is([data-view="lobby"],[data-view="realm"],[data-view="market"],[data-view="craft"]),
  body:has(.game-hud) .game-hud > .game-hud-more {
    display:flex;flex-direction:column;align-items:center;justify-content:center;
    gap:2px;min-width:0;width:100%;min-height:64px;
    margin:0;padding:5px 2px 7px;
    font-size:15px;line-height:1.4;letter-spacing:0;
    white-space:normal;word-break:keep-all;
  }

  body:has(.game-hud) .game-hud :is(i,.hz) { font-size:20px;line-height:1.25; }
  body:has(.game-hud) .game-hud button:focus-visible { outline-offset:-4px; }
  .game-hud-scroll .hud-label-full { display:none; }
  .game-hud-scroll .hud-label-mobile { display:inline; }

  /* A normal-flow account line cannot obscure page actions above the HUD. */
  body:has(.game-hud) .netchip {
    position:relative;inset:auto;z-index:1;
    flex-wrap:wrap;gap:4px 9px;
    width:calc(100% - 24px);min-width:0;max-width:none;
    margin:8px 12px calc(var(--game-hud-height) + 16px);
    padding:8px 12px;border-radius:4px;
    font-size:15px;line-height:1.6;box-shadow:none;
  }

  body:has(.game-hud):has(.netchip) #app.wrap { padding-bottom:20px; }
  body:has(.game-hud) .netchip :is(b,span) { min-width:0;max-width:100%;overflow-wrap:anywhere; }
  body:has(.game-hud) .netchip button { min-height:44px;font-size:15px; }
  body:has(.game-hud) .netchip i { flex:0 0 8px; }

  body:has(.game-hud) .chatfab {
    right:12px;bottom:calc(var(--game-hud-height) + 12px);
    min-height:44px;padding:8px 12px;font-size:15px;
  }

  body:has(.game-hud) .chatpanel {
    right:8px;left:8px;bottom:calc(var(--game-hud-height) + 8px);
    width:auto;max-width:none;
    height:min(540px,calc(100vh - var(--game-hud-height) - 32px));
    height:min(540px,calc(100dvh - var(--game-hud-height) - 32px));
  }

  body:has(.game-hud) .chatpanel header button { min-height:44px;font-size:15px; }
  body:has(.game-hud) :is(input,textarea,select) { font-size:16px; }
  body:has(.game-hud) .toast {
    bottom:calc(var(--game-hud-height) + 66px);
    max-height:calc(100dvh - var(--game-hud-height) - 90px);
    overflow-y:auto;
  }

  /* #app is a stacking context; avoid outside floating UI covering an open
     explanation or the mobile menu placed inside it. */
  body:has(.scene-location.is-open) :is(.chatfab,.chatpanel,.netchip),
  body:has(.mobile-menu-layer:not([hidden])) :is(.chatfab,.chatpanel,.netchip,.toast) { visibility:hidden; }
  body:has(.game-hud):has(#sheetRoot .sheet[role="dialog"]) :is(.chatfab,.chatpanel) { visibility:hidden; }
  body:has(.mobile-menu-layer:not([hidden])) { overflow:hidden; }

  .mobile-menu-layer:not([hidden]) {
    position:fixed;inset:0;z-index:75;display:block;
    color:#294234;font-family:"Noto Serif KR",serif;
  }

  .mobile-menu-scrim {
    position:absolute;inset:0;width:100%;height:100%;
    margin:0;padding:0;border:0;border-radius:0;
    background:rgba(25,42,33,.46);
  }

  .mobile-menu-dialog {
    position:absolute;inset:auto 0 0;
    display:flex;flex-direction:column;
    width:100%;min-width:0;
    max-height:80vh;max-height:80dvh;
    padding:0 16px calc(16px + env(safe-area-inset-bottom,0px));
    border:1px solid #b9b99c;border-bottom:0;border-radius:16px 16px 0 0;
    background:#f3f2e7;box-shadow:0 -10px 44px rgba(26,45,32,.22);
    overflow:hidden;box-sizing:border-box;
  }

  .mobile-menu-dialog > header {
    display:flex;align-items:center;justify-content:space-between;
    flex:none;gap:12px;padding:12px 0;
    border-bottom:1px solid rgba(83,111,83,.25);
  }

  .mobile-menu-dialog #mobileMenuTitle {
    margin:0;color:#314b39;font-size:20px;font-weight:600;line-height:1.4;
  }

  .mobile-menu-dialog > header button {
    min-width:48px;min-height:44px;padding:7px 10px;
    border:1px solid #afb9a4;border-radius:4px;
    background:#e9eddf;color:#34503d;
    font:inherit;font-size:15px;
  }

  .mobile-menu-grid {
    display:grid;grid-template-columns:repeat(3,minmax(0,1fr));
    gap:10px;min-height:0;min-width:0;
    padding:14px 2px 2px;overflow-y:auto;overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
  }

  .mobile-menu-grid button {
    display:flex;flex-direction:column;align-items:center;justify-content:center;
    gap:6px;min-width:0;min-height:84px;margin:0;padding:12px 6px;
    border:1px solid #bac3ac;border-radius:6px;
    background:rgba(255,255,247,.65);color:#324f3d;
    font-family:inherit;font-size:15px;line-height:1.5;
    word-break:keep-all;overflow-wrap:anywhere;
  }

  .mobile-menu-grid :is(i,.hz) { font-style:normal;font-size:24px;color:#8a7445; }
  .mobile-menu-grid button:is([aria-current="page"],[aria-expanded="true"]) {
    border-color:#6c8965;background:#e0e8d7;color:#254732;font-weight:600;
  }

  .mobile-menu-dialog button:focus-visible {
    outline:3px solid #426345;outline-offset:2px;
  }
}

@media (max-width:359px) {
  /* Adjacent hall/field markers retain their art coordinates. On 320px
     screens a 44px touch target avoids overlap while retaining a 32px ring. */
  .sect-scene .scene-map-plane .scene-hotspot {
    width:44px;height:44px;min-width:44px;min-height:44px;
  }
  .sect-scene .scene-map-plane .scene-hotspot-ring { width:32px;height:32px; }
  .mobile-menu-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .sect-scene .scene-profile { padding-inline:10px;gap:9px; }
  .sect-scene .scene-profile-seal { width:48px;height:48px; }
  .sect-scene :is(.scene-cult-summary,.scene-pantry-summary) { padding-inline:10px; }
}

@media (max-width:900px) and (prefers-reduced-motion:reduce) {
  .sect-scene .scene-map-plane .scene-hotspot-ring { transition:none; }
}
