/*
 * Shared iPhone Duo layout helpers. Spec: docs/IPHONE_DUO_DESIGN.md.
 * Variables are set by /js/duo-layout.js; every use has a fallback so pages
 * without the script still lay out.
 */

/* iOS enlarges text when a page is turned sideways unless this is set, which
   is why toasts and labels came out oversized on the cover screen. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* Full-screen surface. Never size the game with 100vh/lvh/dvh — they come out
   short in the home-screen app. */
.duo-fixed-fill { position: fixed; inset: 0; width: 100%; height: 100%; }

/* HUD corner helpers: inset from the HUD insets (0 on the rail side), and
   clear of the keep-out box when it's in that corner. */
.duo-hud-tl { position: fixed; top: calc(8px + var(--sat, env(safe-area-inset-top, 0px))); left: calc(8px + var(--sal, env(safe-area-inset-left, 0px)) + var(--ctl, 0px)); }
.duo-hud-tr { position: fixed; top: calc(8px + var(--sat, env(safe-area-inset-top, 0px))); right: calc(8px + var(--sar, env(safe-area-inset-right, 0px)) + var(--ctr, 0px)); }
.duo-hud-bl { position: fixed; bottom: calc(8px + var(--sab, env(safe-area-inset-bottom, 0px))); left: calc(8px + var(--sal, env(safe-area-inset-left, 0px)) + var(--cbl, 0px)); }
.duo-hud-br { position: fixed; bottom: calc(8px + var(--sab, env(safe-area-inset-bottom, 0px))); right: calc(8px + var(--sar, env(safe-area-inset-right, 0px)) + var(--cbr, 0px)); }

/* Menus, dialogs and dense panels stay inside the full safe area. */
.duo-safe-panel {
    box-sizing: border-box;
    padding-top: var(--rsat, env(safe-area-inset-top, 0px));
    padding-right: var(--rsar, env(safe-area-inset-right, 0px));
    padding-bottom: var(--rsab, env(safe-area-inset-bottom, 0px));
    padding-left: var(--rsal, env(safe-area-inset-left, 0px));
    max-height: calc(var(--ph, 100%) - 16px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* ---- "⋯" slide menus (js/duo-fan.js) ------------------------------------ */

.fan-t { display: none; }

[data-fan].fan-active {
    display: flex;
    flex-wrap: wrap-reverse;
    align-items: flex-end;
}
[data-fan].fan-active > [data-fan-keep],
[data-fan].fan-active > .ready,
[data-fan].fan-active > .lit,
[data-fan].fan-active > .fan-t { order: -1; }

[data-fan].fan-active > .fan-hidden { display: none !important; }
[data-fan].fan-active.fan-open > .fan-hidden { display: revert !important; }

[data-fan].fan-active > .fan-t {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 10px;
    background: rgba(20, 22, 34, 0.85);
    color: #f3e6c8;
    font: 600 18px/1 system-ui, -apple-system, sans-serif;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}
[data-fan].fan-active > .fan-t .fan-n { font-size: 12px; opacity: 0.85; }
[data-fan].fan-active.fan-open > .fan-t { background: rgba(201, 165, 102, 0.9); color: #111; }

[data-fan].fan-active.fan-open > .fan-hidden { min-width: 44px; min-height: 44px; }
[data-fan].fan-active > .fan-hov { outline: 3px solid #c9a566; outline-offset: 1px; }

/* Row anchored on the right: kept items + toggle stay at the right edge and
   opened items extend leftward. */
[data-fan].fan-active.fan-rtl:not(.fan-col) { flex-direction: row-reverse !important; }

/* Column direction: opened items stack above the toggle. */
[data-fan].fan-active.fan-col {
    flex-direction: column-reverse !important;
    /* Extra columns open to the left, so the toggle never moves. */
    flex-wrap: wrap-reverse !important;
    align-content: flex-start;
    max-height: calc(var(--ph, 100%) - 24px - var(--rsat, 0px) - var(--rsab, 0px));
}
