/* =====================================================================
   NotBroken tools — page layout for the html.app pages
   (Breathe, Calm, Sleep, Move, Track)
   ---------------------------------------------------------------------
   Colours, fonts and the navigation itself live in assets/shell.css,
   which every page loads after this file. This file only lays out the
   scrolling canvas and keeps it clear of the fixed navigation.
   ===================================================================== */

:root {
    --primary: #5B8A72;
    --secondary: #C17B4A;
    --background: #15181D;
    --text-main: #2D3748;
}

* { -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--background);
    color: var(--text-main);
}

/* --- Unified page container (base; app mode resets it below) --- */
.page-container {
    width: 100%;
    max-width: 37cm;
    margin: 1rem auto;
    padding: 4rem;
    background-color: #ffffff;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.8);
    border-radius: 25px;
}

/* --- Modal base (each tool refines these in its own <style>) --- */
.modal-overlay {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease-out;
}
.modal-content {
    position: relative;
    background-color: #fefefe;
    margin: 10px auto;
    padding: 25px;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    text-align: center;
    animation: slideIn 0.3s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ======================== */
/* APP MODE (html.app)      */
/* ======================== */

html.app {
    padding: 0 !important;
    box-shadow: none !important;
}

html.app body {
    margin: 0;
    padding: 0;
    /* keep content clear of the notch / status bar in the native app and standalone mode */
    padding-top: env(safe-area-inset-top, 0px);
    height: 100vh;
    height: 100dvh;           /* dynamic viewport height on mobile */
    width: 100%;
    overflow: hidden;
    box-sizing: border-box;
    box-shadow: none !important;
}

/* The page's own scroll container: the first <div> in <body>.
   (Modals and the nav are excluded.) */
html.app body > div:not(.modal-overlay):not(#app-footer-menu):not(#shareModal):not(.nb-consent):not(.nb-export):not(.nb-notice) {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    scrollbar-gutter: stable;
}

/* Reset the website-style card into a full-bleed app canvas */
html.app body .page-container {
    margin: 0;
    width: 100%;
    max-width: none;
    height: auto;
    min-height: 100%;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
    box-sizing: border-box;
}

/* Full-bleed centred canvas used by Breathe (colours come from shell.css) */
.gradient-bg {
    color: white;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    min-height: 500px;
}
.gradient-bg main {
    color: white;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    min-height: 500px;
}

/* Vertical centring that can still scroll. The tools centre their panel with
   `justify-content: center`, which clips the top of the panel on short
   viewports (landscape phones). Auto margins centre when there is room and
   scroll cleanly when there is not. Track lays itself out and is excluded. */
html.app:not([data-page="track"]) .page-container {
    justify-content: flex-start !important;
}
html.app:not([data-page="track"]) .page-container > main {
    margin-top: auto !important;
    margin-bottom: auto !important;
}
html.app .gradient-bg main {
    justify-content: flex-start;
}
html.app .gradient-bg main > * {
    margin-top: auto;
    margin-bottom: auto;
}

/* A tall modal (e.g. the Calm disclaimer on a phone) must scroll rather than
   clip its top and bottom: anchor to the top and let the card centre itself
   with auto margins when there is room. */
html.app .modal-overlay {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    align-items: flex-start !important;
}
html.app .modal-overlay > .modal-content {
    margin-top: auto !important;
    margin-bottom: auto !important;
}

/* Make sure the nav paints immediately (no JS involved) */
html.app #app-footer-menu {
    visibility: visible;
    opacity: 1;
}

/* --- Portrait phones / small tablets: nav is a bottom tab bar --- */
@media (max-width: 999.5px) and (orientation: portrait) {
    html.app body > div:not(.modal-overlay):not(#app-footer-menu):not(#shareModal):not(.nb-consent):not(.nb-export):not(.nb-notice) {
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    }
    html.app body .page-container {
        padding: 1px 1rem 1.5rem 1rem;
    }
    /* Track (journal): its fixed Back / Next bar is replaced by the
       in-header arrows on portrait phones, exactly as before. */
    html.app .nav-buttons {
        display: none;
    }
}

/* --- Landscape phones (short viewports): compact left rail --- */
@media (max-width: 999.5px) and (orientation: landscape) {
    html.app body > div:not(.modal-overlay):not(#app-footer-menu):not(#shareModal):not(.nb-consent):not(.nb-export):not(.nb-notice) {
        padding-left: calc(68px + env(safe-area-inset-left, 0px));
    }
    html.app body .page-container {
        padding: 0.5rem 1rem 0.5rem 1rem;
    }
    html.app .nav-buttons {
        left: calc(68px + env(safe-area-inset-left, 0px)) !important;
        width: auto !important;
        margin-left: 0 !important;
    }
    /* full-screen modals must not sit under the rail */
    html.app .modal-overlay {
        padding-left: calc(68px + env(safe-area-inset-left, 0px));
    }
}

/* --- Desktop & large tablets: full left rail --- */
@media (min-width: 1000px) {
    html.app body > div:not(.modal-overlay):not(#app-footer-menu):not(#shareModal):not(.nb-consent):not(.nb-export):not(.nb-notice) {
        padding-left: 84px;
    }
    html.app body .page-container {
        padding: 2rem 3rem;
    }
    html.app .nav-buttons {
        left: 84px !important;
        width: auto !important;
        margin-left: 0 !important;
    }
}

/* --- Print (tool pages) --- */
@media print {
    html.app body {
        height: auto;
        overflow: visible;
        background: #ffffff !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    html.app body > div:not(.modal-overlay):not(#app-footer-menu):not(#shareModal):not(.nb-consent):not(.nb-export):not(.nb-notice) {
        height: auto;
        overflow: visible;
        padding: 0 !important;
    }
    html.app .page-container {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
        box-shadow: none !important;
        background: transparent !important;
        animation: none !important;
    }
    .no-print, .nav-buttons { display: none !important; }
    section, article, header {
        break-inside: avoid-page;
        page-break-inside: avoid;
    }
}
