/* ============================================================
   Touch layer — on-screen controls and the mobile navigation bar.

   Both are mounted by JavaScript (TouchControls.js, MobileNav.js) and only
   exist when the device profile asks for them, so nothing here needs a media
   query to hide itself on desktop: the elements simply are not in the DOM.
   ============================================================ */

:root {
    --mobile-nav-height: 58px;
    --touch-fab-size: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* ---------- Floating world controls ---------- */

.touch-controls {
    position: fixed;
    inset: 0;
    z-index: 60;
    /* The layer itself is a pass-through; only the buttons take input, so a
       tap on empty space still reaches the canvas and moves the character. */
    pointer-events: none;
}

.touch-controls-hidden {
    opacity: 0;
    visibility: hidden;
}

.touch-controls .touch-btn {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(29, 29, 33, 0.88);
    border: 1px solid var(--line-strong);
    color: var(--text-1);
    border-radius: 999px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
    /* Stops iOS from flashing its own grey overlay on every tap. */
    -webkit-tap-highlight-color: transparent;
}

.touch-controls .touch-btn:active {
    transform: scale(0.93);
}

.touch-btn-sm {
    width: 48px;
    height: 48px;
    padding: 0;
}

.touch-btn-action {
    min-height: var(--touch-fab-size);
    padding: 0 22px 0 18px;
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    max-width: min(62vw, 320px);
}

.touch-btn-action .touch-btn-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.touch-btn-confirm {
    background: var(--ok);
    border-color: var(--ok);
    color: #1a2408;
}

/* Bottom-right stack: the thumb's natural arc on a phone held one-handed. */
.touch-actions {
    position: absolute;
    right: calc(12px + var(--safe-right));
    bottom: calc(14px + var(--safe-bottom));
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Zoom cluster sits on the opposite side so it is never under the thumb that
   is pressing the action button. */
.touch-zoom {
    position: absolute;
    left: calc(12px + var(--safe-left));
    bottom: calc(14px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mobile-nav-on .touch-actions,
.mobile-nav-on .touch-zoom {
    bottom: calc(var(--mobile-nav-height) + 14px + var(--safe-bottom));
}

/* Landscape on a phone is short: shrink the controls so they do not eat the
   floor the player is trying to tap. */
.device-phone.orient-landscape .touch-btn-action {
    min-height: 50px;
    font-size: 13px;
    padding: 0 16px;
}

.device-phone.orient-landscape .touch-btn-sm {
    width: 42px;
    height: 42px;
}

/* ---------- Mobile navigation bar ---------- */

.mobile-nav {
    flex: none;
    display: flex;
    align-items: stretch;
    height: calc(var(--mobile-nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    background: var(--bg-1);
    border-top: 1px solid var(--line-strong);
    z-index: 70;
}

.mobile-nav-item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    padding: 6px 2px;
    background: none;
    border: none;
    border-radius: 0;
    color: var(--text-3);
    font-family: var(--font-display);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.mobile-nav-item:hover,
.mobile-nav-item:active {
    background: var(--bg-2);
    color: var(--accent);
    transform: none;
}

.mobile-nav-item.saved {
    color: var(--ok);
}

.mobile-nav-item.muted {
    color: var(--bad);
}

.mobile-nav-icon {
    display: flex;
    align-items: center;
    height: 22px;
}

.mobile-nav-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.1;
}

.mobile-nav-item.active {
    color: var(--accent);
    background: var(--bg-2);
}

/* ---------- Slide-out drawer ---------- */

/*
 * Kept in the DOM and moved off-screen rather than added and removed, so the
 * open/close is a single composited transform instead of a layout pass — which
 * on a mid-range phone is the difference between a slide and a stutter.
 */
.mobile-drawer {
    position: fixed;
    inset: 0;
    z-index: 90;
    pointer-events: none;
}

.mobile-drawer.open {
    pointer-events: auto;
}

.mobile-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 8, 10, 0.6);
    opacity: 0;
    transition: opacity 0.22s ease;
}

.mobile-drawer.open .mobile-drawer-backdrop {
    opacity: 1;
}

.mobile-drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(84vw, 340px);
    display: flex;
    flex-direction: column;
    background: var(--bg-1);
    border-left: 1px solid var(--line-strong);
    box-shadow: -18px 0 40px rgba(0, 0, 0, 0.5);
    transform: translateX(100%);
    transition: transform 0.24s cubic-bezier(0.22, 0.61, 0.36, 1);
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-right: var(--safe-right);
}

.mobile-drawer.open .mobile-drawer-panel {
    transform: translateX(0);
}

.mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--line);
}

.mobile-drawer-title {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-1);
}

.mobile-drawer-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--sp-2) var(--sp-3) var(--sp-5);
}

.mobile-drawer-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    min-height: 50px;
    padding: 12px var(--sp-3);
    background: none;
    border: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    color: var(--text-1);
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    justify-content: flex-start;
    text-align: left;
}

.mobile-drawer-item:hover,
.mobile-drawer-item:active {
    background: var(--bg-2);
    color: var(--accent);
    transform: none;
}

.mobile-drawer-item.muted {
    color: var(--bad);
}

.mobile-drawer-ic {
    display: flex;
    align-items: center;
    color: var(--text-3);
}

.mobile-drawer-item:hover .mobile-drawer-ic {
    color: inherit;
}

.mobile-drawer-hint {
    margin-top: var(--sp-4);
    padding: var(--sp-3);
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-lg);
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-2);
}

.mobile-drawer-hint p {
    margin-bottom: var(--sp-2);
}

.mobile-drawer-hint p:last-child {
    margin-bottom: 0;
}

.mobile-drawer-hint-title {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-1);
    margin-bottom: var(--sp-2);
}

@media (prefers-reduced-motion: reduce) {
    .mobile-drawer-panel,
    .mobile-drawer-backdrop {
        transition: none;
    }
}

/* Landscape phones have almost no vertical room; drop to icons only. */
.device-phone.orient-landscape .mobile-nav {
    height: calc(46px + var(--safe-bottom));
}

.device-phone.orient-landscape .mobile-nav-label {
    display: none;
}

/* ---------- Transient status toasts ---------- */

/*
 * The stack hangs from the top of the screen, directly under the HUD.
 *
 * It used to float above the bottom controls, and its distance from the bottom
 * edge was a sum of whatever happened to be mounted — the nav bar, the action
 * button, the safe-area inset. So the same message appeared at a different
 * height depending on the screen, the orientation and which controls were on,
 * which is what made the messages feel like they landed at random. Anchoring
 * to the top instead gives one fixed place for the eye to return to, keeps the
 * stack clear of the thumb zone entirely, and never overlaps the action button
 * it is usually commenting on.
 */
.toast-stack {
    position: fixed;
    top: calc(var(--hud-height) + 10px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 80;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: max-content;
    max-width: min(92vw, 480px);
    /* The host is a layout box only; each toast opts back in for tap-to-dismiss. */
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: baseline;
    gap: 8px;
    width: 100%;
    padding: 9px 14px;
    background: rgba(24, 24, 28, 0.96);
    border: 1px solid var(--line-strong);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-lg);
    color: var(--text-1);
    font-size: 13px;
    line-height: 1.35;
    text-align: left;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    -webkit-tap-highlight-color: transparent;
    /* Enter and leave are the same move in reverse: a short drop from above,
       which reads as "this arrived" rather than "this appeared". */
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast-in {
    opacity: 1;
    transform: translateY(0);
}

.toast-out {
    opacity: 0;
    transform: translateY(-6px);
}

.toast-text {
    flex: 1;
    min-width: 0;
}

/* Repeat counter. Hidden until a message actually arrives twice, so the
   common case carries no extra furniture. */
.toast-count {
    flex: none;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
}

.toast-good { border-left-color: var(--ok); }
.toast-bad  { border-left-color: var(--bad); }
.toast-warn { border-left-color: var(--warn); }

/* The desktop status bar already shows this text permanently, so the toast is
   redundant noise there. Toast.enabled keeps JavaScript from queueing them at
   all; this is the matching guarantee for anything already on screen when the
   window is dragged wide. */
.device-desktop .toast-stack {
    display: none;
}

/* The phone HUD is shorter than the desktop one and its height is not fixed,
   so the offset is measured from the top of the screen instead. */
.device-phone .toast-stack {
    top: calc(50px + var(--safe-top));
    max-width: 94vw;
}

/* Landscape phones have so little height that a stack under the HUD would
   cover the world. Two lines maximum, tighter type. */
.device-phone.orient-landscape .toast-stack {
    top: calc(42px + var(--safe-top));
    max-width: min(66vw, 420px);
}

.device-phone.orient-landscape .toast {
    padding: 7px 12px;
    font-size: 12px;
}

@media (prefers-reduced-motion: reduce) {
    .toast,
    .touch-controls .touch-btn {
        transition: none;
    }
}
