/* ============================================================================
 * game.css — styling for the Stardew-style town (game.html)
 * ==========================================================================*/

* { box-sizing: border-box; }

html { height: 100%; }

body {
    margin: 0;
    padding: 0;
    /* dvh = dynamic viewport height: fixes iOS Safari's 100vh cutting content
       off behind the URL bar. Falls back to vh on older browsers. */
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: #1b2330;
    font-family: "Poppins", sans-serif;
    color: #f4f1ec;
    overflow: hidden;
    overscroll-behavior: none; /* no rubber-band scroll on mobile */
}

/* keep the existing nav readable on the dark game background */
.topnav {
    background: rgba(12, 16, 24, 0.85);
    flex: 0 0 auto; /* never let the nav get squashed */
}

.game-stage {
    display: flex;
    flex-direction: column;
    flex: 1;          /* fill whatever height is left under the nav */
    min-height: 0;
    padding: 0.4rem 0.8rem calc(0.8rem + env(safe-area-inset-bottom));
    gap: 0.5rem;
}

.game-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0 0.4rem;
}

.game-title {
    font-family: "Space Mono", monospace;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

.game-controls-hint {
    font-size: 0.85rem;
    opacity: 0.75;
}

.game-controls-hint b {
    font-family: "Space Mono", monospace;
    color: #ffd23f;
}

/* ---- the canvas viewport ------------------------------------------------ */
#game-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), inset 0 0 0 3px rgba(255, 255, 255, 0.06);
    background: #4d8a40;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
}

/* ---- quest tracker HUD -------------------------------------------------- */
.game-hud {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(20, 26, 36, 0.82);
    border: 2px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.82rem;
    line-height: 1.7;
    backdrop-filter: blur(4px);
    pointer-events: none;
    user-select: none;
}

.game-hud-title {
    font-family: "Space Mono", monospace;
    font-weight: 700;
    margin-bottom: 4px;
    color: #ffd23f;
}

.game-quest { opacity: 0.85; transition: color 0.3s, opacity 0.3s; }
.game-quest .box { display: inline-block; width: 1.1em; color: #cdd6e2; }
.game-quest.done { color: #8fe388; opacity: 1; text-decoration: line-through; }
.game-quest.done .box { color: #8fe388; }

/* ---- interaction hint --------------------------------------------------- */
.game-hint {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 26, 36, 0.9);
    border: 2px solid #ffd23f;
    color: #fff;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 0.9rem;
    white-space: nowrap;
    pointer-events: none;
    user-select: none;
    animation: hintpop 0.18s ease;
}

.game-hint b {
    font-family: "Space Mono", monospace;
    color: #ffd23f;
}

@keyframes hintpop { from { transform: translateX(-50%) scale(0.9); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

/* ---- content dialog ----------------------------------------------------- */
.game-dialog {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 12, 20, 0.55);
    backdrop-filter: blur(3px);
    padding: 18px;
    z-index: 20;
}

.game-dialog-card {
    position: relative;
    width: min(560px, 100%);
    max-height: 86%;
    overflow-y: auto;
    background: linear-gradient(180deg, #fffaf2 0%, #fbf3e6 100%);
    color: #2c2620;
    border: 3px solid #8a5a36;
    border-radius: 16px;
    padding: 22px 24px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    animation: cardpop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

@keyframes cardpop { from { transform: translateY(14px) scale(0.96); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }

.dclose {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: #e07a5f;
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
}
.dclose:hover { background: #c5654c; transform: rotate(90deg); }

.dhead { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.dicon { font-size: 1.8rem; }
.dhead h2 {
    margin: 0;
    font-family: "Space Mono", monospace;
    font-size: 1.4rem;
    color: #8a5a36;
}

.dblurb { margin: 0 0 14px; font-style: italic; opacity: 0.8; }

.dsec { margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px dashed rgba(138, 90, 54, 0.3); }
.dsec:last-child { border-bottom: none; }
.dsec h3 { margin: 0 0 2px; font-size: 1rem; color: #2c2620; }
.dmeta { display: block; font-family: "Space Mono", monospace; font-size: 0.75rem; color: #b06a3a; margin-bottom: 4px; }
.dsec p { margin: 0; font-size: 0.92rem; line-height: 1.5; }
.dsec a { color: #c5654c; font-weight: 600; }

.dlink {
    display: inline-block;
    margin-top: 6px;
    padding: 10px 18px;
    background: #e07a5f;
    color: #fff;
    text-decoration: none;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: transform 0.15s, background 0.15s;
}
.dlink:hover { background: #c5654c; transform: translateY(-2px); }

/* ---- completion toast --------------------------------------------------- */
.game-toast {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: linear-gradient(90deg, #ffd23f, #ff9f1c);
    color: #2c2620;
    font-weight: 600;
    padding: 12px 22px;
    border-radius: 999px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.5s, transform 0.5s;
    z-index: 25;
    text-align: center;
    max-width: 90%;
}
.game-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- touch controls ----------------------------------------------------
 * Shown when the engine flags a touch device (body.touch) OR the browser
 * reports a coarse pointer. Driving it off a JS-set class is more reliable
 * than the media query alone (and lets ?touch=1 force it for testing). */
.game-touch {
    display: none;
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 15;
}
body.touch .game-touch { display: block; }
@media (pointer: coarse) { .game-touch { display: block; } }

.dpad {
    position: absolute;
    left: calc(16px + env(safe-area-inset-left));
    bottom: calc(22px + env(safe-area-inset-bottom));
    width: 156px;
    height: 156px;
    pointer-events: none;
}
.dpad-mid {
    display: flex;
    justify-content: space-between;
    width: 156px;
    margin: 5px 0;
}
.dpad button, .action-btn {
    pointer-events: auto;
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 14px;
    background: rgba(20, 26, 36, 0.55);
    color: #fff;
    font-size: 1.1rem;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    backdrop-filter: blur(2px);
}
.dpad button:active, .action-btn:active { background: rgba(255, 210, 63, 0.6); transform: scale(0.94); }
.dpad > button[data-d="up"],
.dpad > button[data-d="down"] { display: block; margin: 0 auto; }

.action-btn {
    position: absolute;
    right: calc(26px + env(safe-area-inset-right));
    bottom: calc(46px + env(safe-area-inset-bottom));
    width: 74px;
    height: 74px;
    border-radius: 50%;
    font-family: "Space Mono", monospace;
    font-weight: 700;
    font-size: 1.4rem;
    background: rgba(224, 122, 95, 0.88);
    pointer-events: auto;
}

/* on touch devices: hide the desktop key-hint and tighten the HUD */
body.touch .game-controls-hint { display: none; }
body.touch .game-hud { font-size: 0.72rem; padding: 8px 10px; top: 8px; left: 8px; line-height: 1.6; }

/* ---- "rotate for a bigger view" tip (portrait phones only) ------------- */
.rotate-tip {
    display: none;
    position: absolute;
    bottom: 96px;            /* above the side controls, clear of the top HUD */
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 18;
    background: rgba(20, 26, 36, 0.9);
    border: 1px solid rgba(255, 210, 63, 0.5);
    color: #f4f1ec;
    font-size: 0.76rem;
    padding: 6px 12px;
    border-radius: 999px;
    pointer-events: none;
    white-space: nowrap;
    max-width: calc(100% - 20px);
    animation: rotateTipFade 6s ease forwards;
}
@media (orientation: portrait) and (max-width: 760px) {
    body.touch .rotate-tip { display: block; }
}
@keyframes rotateTipFade {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; visibility: hidden; }
}

/* small screens: tighten the bar */
@media (max-width: 600px) {
    .game-stage { padding: 0.3rem 0.4rem calc(0.4rem + env(safe-area-inset-bottom)); }
    .game-title { font-size: 0.95rem; }
}
