:root {
    --bg-main: #F4F1EC;
    --card-bg: #FFFFFF;
    --text-dark: #42474A;
    --text-muted: #666E73;
    --accent-blue: #5A6B8C;
    --accent-green: #7D8F69;
    --accent-glow: rgba(125, 143, 105, 0.4);
    --border-soft: #DFD8CB;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Montserrat', sans-serif;
}

body {
    background-color: var(--bg-main);
    display: flex;
    justify-content: center;
    align-items: flex-start; /* ABANS: center. Ara comença a dalt de tot */
    min-height: 100dvh;
    margin: 0;
    padding: 0;
    /* TREU el overflow: hidden, deixa que la pàgina faci scroll si cal */
}

/* Contenidor fluid: s'adapta de manera natural */
.app-container {
    width: 100%;
    max-width: 430px;
    min-height: 100dvh; /* ABANS: height. Ara min-height perquè creixi si cal */
    background-color: var(--bg-main);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 6px;
    position: relative;
    overflow-y: auto; /* Permet scroll intern si el contingut és molt gran */
    overflow-x: hidden;
    padding: 8px 0 85px 0; /* 85px a baix per assegurar que el menú no tapi res */
    box-shadow: 0 10px 25px rgba(0,0,0,0.08);
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top); /* Això està bé, però ara no crearà espai extra perquè el body ja no està centrat */
}
/* Header fluid */
.app-header {
    text-align: center;
    padding: 2px 16px;
    flex-shrink: 0;
}

.header-top {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-logo {
    height: 100px;       /* Pots provar 48px, 52px o 58px segons t'agradi */
    width: auto;
    object-fit: contain;
}

.btn-icon-settings {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    transition: color 0.2s, transform 0.2s;
}

.btn-icon-settings:hover {
    color: var(--accent-blue);
    transform: translateY(-50%) rotate(30deg);
}

.subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 300;
}

/* Selector d'Estat d'Ànim */
.mood-container {
    margin: 4px 16px;
    background: rgba(255, 255, 255, 0.65);
    padding: 6px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-soft);
    flex-shrink: 0;
}

.mood-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.64rem;
    color: var(--text-muted);
    margin-bottom: 2px;
    font-weight: 500;
}

.mood-slider {
    width: 100%;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

/* --- SECCIÓ DEL CAMÍ SINUÓS (S'expandeix de manera flexible) --- */
.path-section {
    position: relative;
    margin: 0 16px;
    padding: 2px 0;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 0; /* Vital perquè flexbox s'encongeixi si el mòbil és petit */
    overflow: hidden;
}

.path-title-box {
    margin-bottom: 2px;
}

.path-title-box h2 {
    font-size: 0.85rem;
    color: var(--text-dark);
    font-weight: 600;
}

.path-title-box p {
    font-size: 0.64rem;
    color: var(--text-muted);
}

/* Línia corba SVG adaptativa */
.curved-path-svg {
    position: absolute;
    top: 25px;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.stones-container {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly; /* Distribueix les pedres proporcionalment */
    height: 100%;
}

.stone-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

/* Posicionament Sinuós en Zig-Zag */
.pos-right { justify-content: flex-end; padding-right: 40px; }
.pos-center { justify-content: center; padding-left: 25px; }
.pos-left { justify-content: flex-start; padding-left: 20px; }
.pos-center-right { justify-content: center; padding-left: 60px; }

.stone-item {
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.stone-item:hover {
    transform: scale(1.05);
}

.stone-img {
    width: 58px; /* Mida ideal per no sobrecarregar pantalles petites */
    height: auto;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

.check-icon {
    position: absolute;
    top: 28%;
    left: 40%;
    color: #FFFFFF;
    font-size: 0.75rem;
    font-weight: bold;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.check-icon.hidden {
    display: none;
}

.completed .stone-img {
    filter: sepia(0.3) hue-rotate(-20deg) contrast(1.1) drop-shadow(0 2px 4px rgba(0,0,0,0.12));
}

.active .stone-img {
    width: 68px;
    filter: hue-rotate(60deg) saturate(0.8) drop-shadow(0 4px 8px var(--accent-glow));
}

.stone-glow {
    position: absolute;
    width: 90px;
    height: 45px;
    background: radial-gradient(circle, var(--accent-glow) 0%, rgba(244, 241, 236, 0) 70%);
    top: -4px;
    left: -10px;
    z-index: -1;
    border-radius: 50%;
}

.locked .stone-img { opacity: 0.45; filter: grayscale(0.5); }
.locked-far .stone-img { opacity: 0.25; filter: grayscale(0.8); }

/* Popover Desplegable d'Acció */
.stone-popover {
    position: absolute;
    left: 90px;
    top: -5px;
    background: #FFFFFF;
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 8px 10px;
    width: 170px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    z-index: 10;
    animation: fadeIn 0.3s ease-in-out;
}

.stone-popover::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 18px;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-right: 7px solid #FFFFFF;
}

.popover-badge {
    color: var(--accent-green);
    font-size: 0.60rem;
    font-weight: 600;
    display: block;
    margin-bottom: 2px;
}

.stone-popover h4 {
    font-size: 0.68rem;
    color: var(--text-dark);
    font-weight: 600;
    margin-bottom: 6px;
    line-height: 1.2;
}

.btn-start {
    background-color: var(--accent-green);
    color: #FFFFFF;
    border: none;
    padding: 5px 8px;
    border-radius: 16px;
    font-size: 0.65rem;
    font-weight: 600;
    width: 100%;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-start:hover {
    background-color: #697857;
}

/* Targetes inferiors */
.card-section {
    padding: 0 16px;
    margin-bottom: 4px;
    flex-shrink: 0;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 8px 12px;
    border: 1px solid var(--border-soft);
    box-shadow: 0 1px 4px rgba(0,0,0,0.02);
}

.card-tag {
    font-size: 0.58rem;
    font-weight: 600;
    color: var(--accent-blue);
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 1px;
}

.card h3 {
    font-size: 0.75rem;
    color: var(--text-dark);
    margin-bottom: 1px;
}

.card p {
    font-size: 0.66rem;
    color: var(--text-muted);
    line-height: 1.2;
}

/* --- MODALS --- */
/* --- MODALS ACTUALITZATS AMB SCROLL INTERN --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh; /* Ocupa tota la pantalla de manera dinàmica al mòbil */
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    padding: 16px; /* Evita que el modal pegui a les vores de la pantalla */
    box-sizing: border-box;
}

.modal-overlay.hidden {
    display: none;
}

.modal-card {
    background: #FFFFFF;
    border-radius: 18px;
    padding: 18px;
    width: 100%;
    max-width: 350px;
    max-height: 85dvh; /* 🔒 Limita l'alçada màxima al 85% de la pantalla */
    overflow-y: auto;  /* 📜 Habilita l'scroll vertical si el contingut és llarg */
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    border: 1px solid var(--border-soft);
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch; /* Scroll suau per a dispositius tàctils */
}

.modal-card h3 {
    font-size: 0.90rem;
    color: var(--text-dark);
    margin-bottom: 6px;
}

.modal-card p {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.modal-card input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    font-size: 0.80rem;
    margin-bottom: 10px;
    outline: none;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text-muted);
    cursor: pointer;
}

.setting-group {
    margin-bottom: 10px;
    text-align: left;
}

.setting-group label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-dark);
    display: block;
    margin-bottom: 2px;
}

.instructions-box {
    background: var(--bg-main);
    padding: 8px 10px;
    border-radius: 8px;
}

.instructions-box h4 {
    font-size: 0.72rem;
    color: var(--text-dark);
    margin-bottom: 4px;
}

.instructions-box p {
    font-size: 0.65rem;
    margin-bottom: 3px;
    line-height: 1.25;
}
/* --- Nova Barra de Progrés Diari (Substitueix l'antic estat d'ànim) --- */
.daily-progress-container {
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 8px 14px;
    margin: 4px 16px;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
}

.daily-progress-labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.progress-label {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-muted);
}

.progress-value {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent-green);
}

.daily-progress-track {
    width: 100%;
    height: 6px;
    background-color: var(--border-soft);
    border-radius: 3px;
    overflow: hidden;
}

.daily-progress-fill {
    height: 100%;
    background-color: var(--accent-green);
    border-radius: 3px;
    transition: width 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}