/* =====================================================================
   portal.css - Shell + core components
   Cozy MapleStory-storybook. Soft "game window" surfaces, depth,
   pixel-font accents reserved for game moments.
   ===================================================================== */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--sans);
    font-size: var(--text-base);
    font-weight: 400;
    line-height: 1.6;
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* The portal lives inside a phone-width column */
#app {
    position: relative;
    width: 100%;
    min-height: 100dvh;
    max-width: var(--content-max);
    margin: 0 auto;
    background: var(--paper);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* soft paper grain + vignette so flat cream reads as "world" not blank */
#app::before {
    content: '';
    position: fixed;
    inset: 0;
    max-width: var(--content-max);
    margin: 0 auto;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(120% 60% at 50% -10%, transparent 60%, rgba(74,46,12,.03) 100%),
        repeating-linear-gradient(45deg, rgba(0,0,0,.008) 0 2px, transparent 2px 5px);
    mix-blend-mode: multiply;
}

/* =========================== HEADER ============================= */
#app-header {
    position: sticky;
    top: 0;
    z-index: 60;
    padding: calc(var(--space-lg) + env(safe-area-inset-top, 0)) var(--page-pad) 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    background: linear-gradient(var(--paper-2), color-mix(in srgb, var(--paper) 84%, transparent));
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: var(--bw) solid var(--line);
    box-shadow: 0 10px 22px -18px rgba(120,80,40,.4);
}
#app-header .brand {
    font-family: var(--serif);
    font-weight: 600;
    font-size: var(--text-lg);
    letter-spacing: .02em;
    color: var(--ink);
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    flex: none;
}
#app-header .brand::before {
    content: '';
    width: 10px; height: 10px; flex: none;
    background: var(--accent);
    border-radius: 50% 50% 50% 0;
    transform: rotate(45deg);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
#app-header .brand .amp { font-style: italic; color: var(--accent); }

#app-header .crumb {
    font-family: var(--pixel);
    font-weight: 600;
    font-size: var(--px-xs);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--accent-deep);
    background: var(--card);
    border: 1.5px solid var(--card-border-col);
    border-radius: var(--radius-pill);
    padding: 6px 10px;
    box-shadow: var(--card-shadow);
    max-width: 116px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* mini flower counter that rides in the header */
.hud-flowers {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--pixel);
    font-weight: 600;
    font-size: var(--px-md);
    color: var(--accent-deep);
    background: var(--card);
    border: 1.5px solid var(--card-border-col);
    border-radius: var(--radius-pill);
    padding: 4px 12px 4px 8px;
    box-shadow: var(--card-shadow);
    line-height: 1;
}
.hud-flowers .blsm {
    width: 16px; height: 16px; display: inline-block;
}

/* =========================== CONTENT ============================ */
#app-content {
    position: relative;
    z-index: 10;
    flex: 1;
    padding: var(--space-sm) var(--page-pad) calc(var(--nav-height) + 28px);
    opacity: 1;
    transition: opacity .18s ease, transform .18s ease, padding-bottom .2s ease;
}
/* the guide dock reserves its own strip; content clears it */
body.dock-open #app-content {
    padding-bottom: calc(var(--nav-height) + 28px + var(--dock-h));
}
#app-content.swap { opacity: 0; transform: translateY(6px); }

/* =========================== BOTTOM NAV ========================= */
#app-nav {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 90;
    width: calc(100% - 2 * var(--page-pad));
    max-width: calc(var(--content-max) - 2 * var(--page-pad));
    height: var(--nav-height);
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: var(--card);
    border: var(--bw) solid var(--frame-ink);
    border-radius: var(--radius);
    box-shadow: var(--chrome), var(--pop-shadow);
    padding: 0 6px env(safe-area-inset-bottom, 0);
}
#app-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: var(--ink-mute);
    font-family: var(--pixel);
    font-weight: 500;
    font-size: var(--px-sm);
    letter-spacing: .02em;
    padding: 8px 2px;
    border-radius: var(--radius-sm);
    transition: color var(--ease), transform var(--ease);
}
#app-nav a .nav-ico {
    width: 26px; height: 26px;
    display: grid; place-items: center;
    transition: transform var(--ease);
}
#app-nav a.active { color: var(--accent-deep); }
#app-nav a.active .nav-ico { transform: translateY(-2px) scale(1.12); }
#app-nav a:active { transform: scale(.94); }
/* active pip */
#app-nav a.active::after {
    content: '';
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: -2px;
}

/* =========================== CARD / WINDOW ===================== */
.card {
    position: relative;
    background: var(--card);
    border: var(--card-border-w) solid var(--card-border-col);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
}
/* card with a little title bar (game window) */
.window {
    position: relative;
    background: var(--card);
    border: var(--card-border-w) solid var(--card-border-col);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    margin-bottom: var(--space-md);
}
.window > .win-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 12px var(--space-md);
    background: linear-gradient(var(--card-2), var(--card-warm));
    border-bottom: 1.5px solid var(--card-border-col);
    font-family: var(--pixel);
    font-weight: 600;
    font-size: var(--px-lg);
    letter-spacing: .02em;
    color: var(--accent-deep);
}
.window > .win-bar .dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--accent); box-shadow: 0 0 0 2px var(--card);
}
.window > .win-body { padding: var(--space-lg); position: relative; }

/* =========================== TYPE HELPERS ====================== */
.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--pixel-tight);
    font-weight: 700;
    font-size: var(--px-xs);
    letter-spacing: .06em;
    text-transform: uppercase;
    color: color-mix(in srgb, var(--page-accent) 55%, var(--ink));
    background: color-mix(in srgb, var(--page-accent) 32%, #fff);
    border-radius: var(--radius-pill);
    padding: 4px 10px;
}
.title {
    font-family: var(--serif);
    font-weight: 500;
    font-size: var(--text-2xl);
    line-height: 1.05;
    color: var(--ink);
    letter-spacing: .01em;
}
.title .amp { font-style: italic; color: var(--accent); }
.subtitle {
    font-family: var(--serif);
    font-weight: 400;
    font-size: var(--text-lg);
    color: var(--ink-soft);
}
.pixel { font-family: var(--pixel); font-weight: 600; }
.serif { font-family: var(--serif); }
.muted { color: var(--ink-mute); }
.soft  { color: var(--ink-soft); }
.tac { text-align: center; }

.page-head { position: relative; padding: var(--space-md) 2px var(--space-lg); }
.page-head .eyebrow { margin-bottom: 8px; }
.page-intro {
    font-size: var(--text-sm);
    color: var(--ink-soft);
    margin-top: 8px;
    max-width: 38ch;
}
/* little blossom duo, tinted by the page accent */
.page-head .ph-deco {
    position: absolute; right: 6px; top: var(--space-md);
    display: flex; align-items: flex-start; gap: 2px;
    opacity: .55; pointer-events: none;
}
.page-head .ph-deco .blsm:last-child { margin-top: 12px; }

/* =========================== BUTTONS =========================== */
.btn {
    -webkit-appearance: none; appearance: none;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font-family: var(--pixel);
    font-weight: 600;
    font-size: var(--px-md);
    letter-spacing: .01em;
    color: var(--ink);
    background: var(--card);
    border: var(--card-border-w) solid var(--card-border-col);
    border-radius: var(--radius-pill);
    padding: 12px 20px;
    cursor: pointer;
    box-shadow: var(--card-shadow);
    transition: transform var(--ease), box-shadow var(--ease), background var(--ease);
    white-space: nowrap;
}
.btn:active { transform: translateY(2px) scale(var(--tap-scale)); box-shadow: var(--card-shadow); }
.btn-accent {
    color: #fff;
    background: linear-gradient(var(--accent), var(--accent-deep));
    border-color: var(--accent-deep);
    text-shadow: 0 1px 0 rgba(0,0,0,.15);
}
.btn-accent:active { filter: brightness(.97); }
.btn-block { width: 100%; }
.btn-lg { padding: 16px 24px; font-size: var(--px-lg); }

/* =========================== INPUTS ============================ */
.field {
    width: 100%;
    font-family: var(--sans);
    font-size: var(--text-base);
    color: var(--ink);
    background: var(--card-2);
    border: 1.5px solid var(--card-border-col);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    outline: none;
    transition: border-color var(--ease), box-shadow var(--ease);
}
.field::placeholder { color: var(--ink-mute); }
.field:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(212,149,106,.18);
}
textarea.field { resize: none; line-height: 1.6; }

/* =========================== DIVIDER =========================== */
.divider {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    margin: var(--space-lg) 0;
    color: var(--accent-soft);
}
.divider::before, .divider::after {
    content: ''; height: 2px; width: 46px; border-radius: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-soft));
}
.divider::after { transform: scaleX(-1); }
.divider .gem { width: 8px; height: 8px; background: var(--accent); transform: rotate(45deg); border-radius: 2px; }

/* =========================== MASCOT BOX ======================== */
/* Fixed square slot for the animated character mascots. The frame art
   is bottom-anchored and contained, so violetta (tall sheets) and the
   mushroom (wide sheets) align at the feet; --cal-s / --cal-dy come
   from DATA.sprites and level out their visual mass. */
.mbox {
    width: var(--mb, var(--m-lg));
    height: var(--mb, var(--m-lg));
    display: inline-grid;
    position: relative;
    flex: none;
    vertical-align: bottom;
}
.mbox .msprite {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: contain;
    object-position: bottom center;
    image-rendering: pixelated;
    transform: translateY(var(--cal-dy, 0)) scale(var(--cal-s, 1));
    transform-origin: bottom center;
}
/* soft ground ellipse, painted under the art (home scene + dialogue) */
.mbox--shadow::before {
    content: '';
    position: absolute; bottom: -2px; left: 50%; transform: translateX(-50%);
    width: 60%; height: 10%;
    background: rgba(74,46,12,.18);
    border-radius: 50%;
    filter: blur(2px);
}

/* =========================== FLOWER BLOSSOM (css sprite) ======= */
.blsm { position: relative; display: inline-block; width: 22px; height: 22px; }
.blsm i {
    position: absolute; inset: 0; margin: auto;
    width: 42%; height: 42%; background: var(--rose); border-radius: 50% 50% 50% 0;
}
.blsm i:nth-child(1){ transform: rotate(0deg)   translateY(-30%); }
.blsm i:nth-child(2){ transform: rotate(72deg)  translateY(-30%); }
.blsm i:nth-child(3){ transform: rotate(144deg) translateY(-30%); }
.blsm i:nth-child(4){ transform: rotate(216deg) translateY(-30%); }
.blsm i:nth-child(5){ transform: rotate(288deg) translateY(-30%); }
.blsm b {
    position: absolute; inset: 0; margin: auto; width: 30%; height: 30%;
    background: var(--gold); border-radius: 50%; z-index: 2;
    box-shadow: 0 0 0 1.5px rgba(255,255,255,.5);
}

/* =========================== CHIPS / BADGES ==================== */
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    font-family: var(--pixel); font-weight: 500; font-size: var(--px-sm);
    color: var(--accent-deep);
    background: var(--card-2);
    border: 1.5px solid var(--card-border-col);
    border-radius: var(--radius-pill);
    padding: 4px 12px;
}
.badge-float {
    position: absolute; z-index: 5;
    font-family: var(--pixel); font-weight: 700; font-size: var(--px-sm);
    color: #fff; background: linear-gradient(var(--accent), var(--accent-deep));
    border: 2px solid var(--card);
    border-radius: var(--radius-pill);
    padding: 3px 10px;
    box-shadow: var(--pop-shadow);
}

/* =========================== UTILITIES ========================= */
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.gap-sm { gap: var(--space-sm); } .gap-md { gap: var(--space-md); }
.mt-xs{margin-top:var(--space-xs)} .mt-sm{margin-top:var(--space-sm)} .mt-md{margin-top:var(--space-md)} .mt-lg{margin-top:var(--space-lg)}
.mb-sm{margin-bottom:var(--space-sm)} .mb-md{margin-bottom:var(--space-md)} .mb-lg{margin-bottom:var(--space-lg)}
.hidden { display: none !important; }

/* entrance animation for swapped pages - transform-only so content is
   NEVER hidden if the animation timeline is throttled/frozen. */
@keyframes rise { from { transform: translateY(9px); } to { transform: none; } }
.rise { animation: rise .45s var(--ease) both; }
.rise-1 { animation-delay: .04s; } .rise-2 { animation-delay: .1s; }
.rise-3 { animation-delay: .16s; } .rise-4 { animation-delay: .22s; }

@media (prefers-reduced-motion: reduce) {
    .rise, .scene .who, .scene .couple-heart, .scene .orb, .scene .cloud, .scene .fl {
        animation: none !important;
        opacity: 1 !important;
    }
    .scene .petal { display: none !important; }
    .home-plate { margin-top: -54px !important; }
}
