/* Touchscreens use the warehouse itself as the playing surface. */
@media (pointer: coarse), (max-width: 700px) and (orientation: portrait), (max-height: 540px) and (orientation: landscape) {
  :root {
    --game-top: calc(env(safe-area-inset-top, 0px) + 12px);
    --game-right: calc(env(safe-area-inset-right, 0px) + 13px);
    --game-bottom: calc(env(safe-area-inset-bottom, 0px) + 15px);
    --game-left: calc(env(safe-area-inset-left, 0px) + 13px);
    --pad-size: clamp(100px, 26vw, 125px);
    --stick-diameter: 44%;
    --action-size: clamp(78px, 21vw, 103px);
    --glass: linear-gradient(148deg, #2c4b3ff2, #193629ed 85%);
    --glass-line: 1px solid #f1e5b86b;
    --glass-shadow: inset 0 1px 0 #f4f3c71f, 0 2px 5px #17201745;
  }

  html, body {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }
  body { display: block; }
  .machine, .cabinet, .screen {
    display: block;
    width: 100%;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .machine {
    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    isolation: isolate;
    overflow: hidden;
  }
  .cabinet, .screen { height: 100%; }
  .mast, .foot, .deck .screw { display: none; }
  #scene { position: absolute; inset: 0; width: 100%; height: 100%; }
  .screen::after {
    content: '';
    position: absolute;
    inset: auto 0 0;
    height: min(22%, 142px);
    pointer-events: none;
    background: linear-gradient(transparent, #2c25151c);
  }

  .hud {
    inset: var(--game-top) calc(var(--game-right) + 50px) auto var(--game-left);
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
    gap: clamp(5px, 1.5vw, 9px);
    z-index: 2;
  }
  .hud-panel, .location, .minimap, #mobile-menu {
    color: #fff2cd;
    background: var(--glass);
    border: var(--glass-line);
    border-radius: 8px;
    box-shadow: var(--glass-shadow);
  }
  .hud-panel {
    min-width: 0;
    min-height: 47px;
    padding: 6px clamp(6px, 1.8vw, 10px);
  }
  .hud-info, .readout { gap: clamp(4px, 1.3vw, 8px); }
  .hud .micro {
    margin: 0 0 2px;
    font-size: clamp(8px, 1.99vw, 10px);
    line-height: 1.1;
    letter-spacing: .025em;
    white-space: nowrap;
    color: #c6d8bb;
  }
  .hud .digits, .load-panel .digits {
    font-size: clamp(17px, 4.45vw, 22px);
    line-height: 1.05;
    letter-spacing: -.015em;
  }
  .time-panel {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .time-panel .digits { color: #ffe4a0; }
  .time-panel.urgent .digits { color: #ffae83; }
  .time-track { height: 2px; margin-top: 4px; border-radius: 3px; }
  .load-panel { align-items: center; gap: clamp(5px, 1.4vw, 10px); }
  .item-readout { padding-left: clamp(5px, 1.4vw, 10px); border-left: 1px solid #b2c3a74d; }
  .hud .timer-icon, .hud .coin-icon { width: 16px; height: 18px; }
  .hud .box-icon { width: 15px; height: 16px; }
  #mobile-menu {
    position: absolute;
    z-index: 3;
    top: var(--game-top);
    right: var(--game-right);
    width: 45px;
    height: 47px;
    padding: 0;
    display: grid;
    place-items: center;
    touch-action: manipulation;
  }
  #mobile-menu .icon { width: 19px; height: 19px; }
  #mobile-menu:active, .minimap:active { background: #385c48; }
  .location {
    top: calc(var(--game-top) + 54px);
    left: var(--game-left);
    bottom: auto;
    z-index: 2;
    gap: 6px;
    min-height: 25px;
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 11px;
    letter-spacing: .03em;
    line-height: 1.15;
    background: #233c30d9;
    pointer-events: none;
  }
  .location .icon { width: 11px; height: 12px; }
  .location .latin { font-size: 10px; }
  .minimap {
    position: absolute;
    z-index: 2;
    display: grid;
    place-items: center;
    top: calc(var(--game-top) + 54px);
    right: var(--game-right);
    bottom: auto;
    padding: 5px 6px;
    min-width: 45px;
    border-radius: 6px;
    touch-action: manipulation;
    cursor: pointer;
  }
  .minimap::before { display: none; }
  .minimap #map {
    width: clamp(61px, 16vw, 82px);
    height: auto;
    aspect-ratio: 156 / 166;
  }

  .deck {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 0;
    margin: 0;
    z-index: 3;
    pointer-events: none;
    color: #fff0c7;
    background: none;
  }
  .move-control, #act {
    position: absolute;
    bottom: var(--game-bottom);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    padding: 0;
    margin: 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .move-control { left: var(--game-left); flex-direction: column; pointer-events: none; }
  #act {
    right:var(--game-right);
    display:flex;
    flex-flow:column-reverse nowrap;
    align-items:center;
    width:var(--action-size);
    height:auto;
    pointer-events:auto;
    appearance:none;
    -webkit-appearance:none;
    -webkit-touch-callout:none;
  }
  #act .deck-label { flex:none; max-width:100%; }
  .deck-label {
    padding: 4px 8px 5px;
    margin: 0;
    min-width: 38px;
    border-radius: 12px;
    color: #fff4d0;
    background: #263c2ee8;
    box-shadow: inset 0 0 0 1px #f1e5b841, 0 1px 3px #28261650;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.12;
    letter-spacing: .03em;
    text-align: center;
  }
  .deck-label small { display: none; }
  #dpad {
    position: relative;
    display: grid;
    place-items: center;
    width: var(--pad-size);
    height: var(--pad-size);
    background: linear-gradient(150deg, #334d3c85, #1a352b94);
    border: 2px solid #fff3c78a;
    border-radius: 50%;
    box-shadow: inset 0 0 0 3px #f5f3cf27, inset 0 -5px 12px #172c2640, 0 3px 9px #27261744;
    pointer-events: auto;
    touch-action: none;
    -webkit-touch-callout: none;
  }
  #dpad .pad-shadow, #dpad .pad-face, #dpad .pad-center { display: none; }
  #dpad button[data-dir] {
    position: absolute;
    left: 50%;
    top: 50%;
    right: auto;
    bottom: auto;
    overflow: hidden;
    clip-path: inset(50%);
    width: 1px;
    height: 1px;
    pointer-events: none;
  }
  #dpad .stick-field {
    position: absolute;
    display: block;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background:
      linear-gradient(#f9f1ccac, #f9f1ccac) center 9% / 3px 6px no-repeat,
      linear-gradient(#f9f1ccac, #f9f1ccac) center 91% / 3px 6px no-repeat,
      linear-gradient(#f9f1ccac, #f9f1ccac) 9% center / 6px 3px no-repeat,
      linear-gradient(#f9f1ccac, #f9f1ccac) 91% center / 6px 3px no-repeat;
  }
  #dpad .stick-field::before {
    content: '';
    position: absolute;
    inset: 17%;
    border: 1px solid #fff4c747;
    border-radius: 50%;
  }
  #dpad .stick-knob {
    position: absolute;
    display: block;
    z-index: 1;
    top: 28%;
    left: 28%;
    width: var(--stick-diameter);
    height: var(--stick-diameter);
    border-radius: 50%;
    border: 2px solid #f6efd4b0;
    background: linear-gradient(150deg, #92a888f2, #58785ef2 63%, #43624bf2);
    box-shadow: inset 0 3px 0 #f1f0ca57, inset 0 -3px 0 #34503c80, 0 2px 4px #20352680;
    transform: translate(var(--stick-x, 0px), var(--stick-y, 0px));
    pointer-events: none;
  }
  #act .button-well {
    position:relative;
    display:block;
    flex:none;
    width:var(--action-size);
    height:var(--action-size);
    aspect-ratio:1;
    padding:0;
    border-radius:50%;
    border: 1px solid #f9ebbc9c;
    background: #354535bd;
    box-shadow: inset 0 2px 0 #eeedc766, 0 2px 6px #302b2060;
  }
  #act .button-cap {
    position:absolute;
    top:4px;
    left:6px;
    width:calc(var(--action-size) - 14px);
    height:calc(var(--action-size) - 14px);
    max-width:none;
    max-height:none;
    min-width:0;
    min-height:0;
    display:flex;
    align-items:center;
    justify-content:center;
    border-radius:50%;
    box-sizing:border-box;
    border: 1px solid #d9672e;
    background: linear-gradient(155deg, #ffac56, #fa8a3c 70%, #f37d33);
    color: #fff6db;
    box-shadow: inset 0 3px #ffc789, 0 4px 0 #a3552f, 0 5px 0 #403e2f;
  }
  #act .button-cap .icon {
    width:calc(var(--action-size) * .28);
    height:calc(var(--action-size) * .28);
    display:block;
    flex:none;
  }
  #act:active .button-cap, #act.pressed .button-cap {
    transform: translateY(3px);
    box-shadow: inset 0 2px #ffc789, 0 1px 0 #a3552f;
  }

  .mission {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    bottom: var(--game-bottom);
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: min(325px, calc(100% - var(--game-left) - var(--game-right) - var(--pad-size) - var(--action-size) - 12px));
    gap: 6px;
    margin: 0;
    padding: 6px 10px;
    border: var(--glass-line);
    border-radius: 7px;
    color: #fff3cf;
    background: #233c30e6;
    box-shadow: var(--glass-shadow);
    pointer-events: none;
  }
  .mission::after, .mission .printed, .mission-icon { display: none; }
  .mission p { margin: 0; max-width: none; font-size: 12px; line-height: 1.45; text-align: center; }
  #notify {
    z-index: 3;
    bottom: calc(var(--game-bottom) + 35px);
    max-width: min(80vw, 375px);
    padding: 8px 12px;
    font-size: 13px;
    text-align: center;
    pointer-events: none;
  }
  .dialog {
    width: min(390px, calc(100% - var(--game-left) - var(--game-right)));
    max-height: calc(100dvh - var(--game-top) - var(--game-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

@media (max-width: 370px) and (orientation: portrait) {
  .hud .box-icon { display: none; }
  .mission p { font-size: 11px; }
  .hud .digits, .load-panel .digits { font-size: 16px; }
}
@media (max-width: 350px) and (orientation: portrait) {
  .mission { display: none; }
}
@media (pointer: coarse) and (orientation: landscape), (max-height: 540px) and (orientation: landscape) {
  :root {
    --game-top: calc(env(safe-area-inset-top, 0px) + 9px);
    --game-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    --game-left: calc(env(safe-area-inset-left, 0px) + clamp(13px, 2.8vw, 28px));
    --game-right: calc(env(safe-area-inset-right, 0px) + clamp(13px, 2.8vw, 28px));
    --pad-size: clamp(96px, 25vh, 117px);
    --action-size: clamp(75px, 21vh, 91px);
  }
  .mission { bottom: calc(var(--game-bottom) + 4px); padding: 6px 12px; }
  .minimap #map { width: clamp(49px, 12.8vh, 64px); }
}

@media (max-width: 390px) and (orientation: portrait) {
  .load-panel .icon { display: none; }
  .hud .load-panel { padding-inline: 7px; }
}
@media (pointer: coarse), (max-width: 700px) and (orientation: portrait), (max-height: 540px) and (orientation: landscape) {
  #act[data-available="true"] .button-well { border-color:#fff2b9; box-shadow:0 0 0 2px #f1ca8055,0 2px 7px #302b2060; }
  .minimap::after { content:""; position:absolute; right:3px; bottom:3px; width:5px; height:5px; border-right:1px solid #e8dab1; border-bottom:1px solid #e8dab1; }
}
@media (pointer: coarse), (max-width: 700px) and (orientation: portrait), (max-height: 540px) and (orientation: landscape) {
  .scene-tools{top:calc(var(--game-top) + 54px);left:var(--game-left);gap:5px}
  .scene-tools button{min-height:44px;padding:5px 7px;font-size:12px;gap:5px;background:var(--glass);border:var(--glass-line);box-shadow:var(--glass-shadow);border-radius:6px}
  .scene-tools .icon{width:14px;height:14px}.scene-tools .stage-full{display:none}.scene-tools .stage-short{display:inline}
  .location{top:calc(var(--game-top) + 104px)}
  .dialog[data-page="stages"]{max-height:calc(100dvh - var(--game-top) - var(--game-bottom))}
}
@media (pointer: coarse), (max-width: 700px) and (orientation: portrait), (max-height: 540px) and (orientation: landscape) {
  .shelf-picker{
    position:absolute;z-index:4;left:50%;bottom:calc(var(--game-bottom) + var(--pad-size) + 35px);
    transform:translateX(-50%);width:min(292px,calc(100% - var(--game-left) - var(--game-right)));
    min-height:53px;pointer-events:auto;background:#2a4739f2;border-color:#e1dab78c;
    box-shadow:0 3px 7px #1f342e55
  }
  .browsing-shelf .mission{display:none}
}
@media (pointer: coarse) and (orientation: landscape), (max-height:540px) and (orientation:landscape){
  .shelf-picker{bottom:var(--game-bottom);width:min(292px,calc(100% - var(--pad-size) - var(--action-size) - var(--game-left) - var(--game-right) - 20px))}
  .browsing-shelf #notify{bottom:calc(var(--game-bottom) + 65px)}
}
