/* ===========================================
   Coneix els Rius de Catalunya — v1.3
   =========================================== */

.crc-app {
    --crc-paper:    #f1ead8;
    --crc-ink:      #2b2418;
    --crc-ink-soft: #6b5e47;
    --crc-rule:     #c9bd9c;
    --crc-bg-out:   #e8e2cc;
    --crc-gold:     #b8862c;
    --crc-good:     #4a7a3a;
    --crc-bad:      #a8372b;
    --crc-water:    #13405a;

    display: grid;
    grid-template-columns: 320px 1fr;
    background: var(--crc-bg-out);
    color: var(--crc-ink);
    font-family: Georgia, 'Times New Roman', serif;
    border: 1px solid var(--crc-rule);
    border-radius: 4px;
    overflow: hidden;
    height: var(--crc-altura, 720px);
    max-width: 100%;
}

.crc-app *, .crc-app *::before, .crc-app *::after { box-sizing: border-box; }

.crc-panel {
    background: var(--crc-paper);
    border-right: 1px solid var(--crc-rule);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.crc-header {
    padding: 22px 20px 14px;
    border-bottom: 1px solid var(--crc-rule);
}

.crc-titol {
    font-size: 26px;
    font-weight: 900;
    line-height: .95;
    letter-spacing: -0.02em;
    margin: 0;
}
.crc-titol em {
    font-style: italic;
    font-weight: 500;
    color: var(--crc-gold);
}
.crc-subtitol {
    font-size: 11px;
    letter-spacing: .25em;
    text-transform: uppercase;
    color: var(--crc-ink-soft);
    font-family: 'Courier New', monospace;
    margin-top: 4px;
}

.crc-tabs {
    display: flex;
    border-bottom: 1px solid var(--crc-rule);
}
.crc-tab {
    flex: 1;
    background: transparent;
    border: none;
    border-right: 1px solid var(--crc-rule);
    color: var(--crc-ink-soft);
    padding: 12px 10px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s;
    text-transform: uppercase;
    letter-spacing: .15em;
}
.crc-tab:last-child { border-right: none; }
.crc-tab:hover { background: rgba(184,134,44,.08); color: var(--crc-ink); }
.crc-tab.crc-actiu { background: var(--crc-ink); color: var(--crc-paper); }

.crc-mode-joc {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.crc-mode-joc[hidden] { display: none; }

.crc-filtres { display: flex; flex-direction: column; gap: 6px; }
.crc-mode-btn {
    background: transparent;
    border: 1px solid var(--crc-rule);
    color: var(--crc-ink);
    padding: 9px 12px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: all .2s;
    border-radius: 2px;
}
.crc-mode-btn:hover { background: rgba(184,134,44,.08); border-color: var(--crc-gold); }
.crc-mode-btn.crc-actiu { background: var(--crc-ink); color: var(--crc-paper); border-color: var(--crc-ink); }

.crc-estat {
    background: rgba(255,255,255,.4);
    border: 1px solid var(--crc-rule);
    padding: 14px;
    border-radius: 2px;
}
.crc-pregunta {
    font-size: 10px;
    color: var(--crc-ink-soft);
    text-transform: uppercase;
    letter-spacing: .2em;
    font-family: 'Courier New', monospace;
    margin-bottom: 6px;
}
.crc-objectiu {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
    font-style: italic;
    word-break: break-word;
}
.crc-objectiu .crc-tipus {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .15em;
    color: var(--crc-gold);
    font-style: normal;
    font-family: 'Courier New', monospace;
    display: block;
    margin-bottom: 4px;
    font-weight: normal;
}

.crc-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    text-align: center;
}
.crc-stat {
    background: rgba(255,255,255,.4);
    border: 1px solid var(--crc-rule);
    padding: 8px 4px;
    border-radius: 2px;
}
.crc-stat .crc-v { font-size: 20px; font-weight: 700; line-height: 1; }
.crc-stat .crc-l {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: .15em;
    color: var(--crc-ink-soft);
    font-family: 'Courier New', monospace;
    margin-top: 4px;
}

.crc-feedback {
    min-height: 22px;
    font-size: 13px;
    font-style: italic;
    text-align: center;
    color: var(--crc-ink-soft);
}
.crc-feedback.crc-ok { color: var(--crc-good); }
.crc-feedback.crc-ko { color: var(--crc-bad); }

.crc-actions { display: flex; gap: 6px; }
.crc-pista-btn, .crc-skip-btn {
    flex: 1;
    background: transparent;
    border: 1px solid var(--crc-rule);
    color: var(--crc-ink-soft);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    transition: all .2s;
    border-radius: 2px;
    text-transform: uppercase;
    letter-spacing: .12em;
}
.crc-pista-btn:hover, .crc-skip-btn:hover {
    border-color: var(--crc-gold);
    color: var(--crc-ink);
}

.crc-mode-estudi {
    padding: 18px 20px;
    overflow-y: auto;
}
.crc-mode-estudi[hidden] { display: none; }

.crc-estudi-intro {
    font-size: 12px;
    font-style: italic;
    color: var(--crc-ink-soft);
    margin: 0 0 16px;
    line-height: 1.45;
}

.crc-conca { margin-bottom: 18px; }
.crc-conca-titol {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .22em;
    color: var(--crc-gold);
    font-family: 'Courier New', monospace;
    margin: 0 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--crc-rule);
}

.crc-llista-rius { list-style: none; padding: 0; margin: 0; }
.crc-llista-rius li {
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 2px;
    transition: background .15s;
}
.crc-llista-rius li:hover,
.crc-llista-rius li.crc-hover {
    background: rgba(184,134,44,.18);
}
.crc-nom-riu {
    font-size: 15px;
    font-weight: 700;
    color: var(--crc-ink);
    font-style: italic;
}
.crc-llista-rius li[data-nivell="2"] {
    padding-left: 22px;
    position: relative;
}
.crc-llista-rius li[data-nivell="2"]::before {
    content: "↳";
    position: absolute;
    left: 8px;
    color: var(--crc-rule);
}
.crc-llista-rius li[data-nivell="2"] .crc-nom-riu {
    font-size: 13px;
    font-weight: 500;
    color: var(--crc-ink-soft);
    font-style: normal;
}
.crc-llista-rius li[data-nivell="3"] {
    padding-left: 38px;
    position: relative;
}
.crc-llista-rius li[data-nivell="3"]::before {
    content: "↳";
    position: absolute;
    left: 24px;
    color: var(--crc-rule);
    font-size: 11px;
}
.crc-llista-rius li[data-nivell="3"] .crc-nom-riu {
    font-size: 12px;
    font-weight: 400;
    color: var(--crc-ink-soft);
    font-style: normal;
}

.crc-afluents-toggle {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--crc-ink-soft);
    font-family: 'Courier New', monospace;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .15em;
    padding: 8px 0 4px;
    cursor: pointer;
    margin-top: 10px;
    border-top: 1px dashed var(--crc-rule);
}
.crc-afluents-toggle:hover { color: var(--crc-gold); }
.crc-afluents-toggle .crc-fletxa {
    display: inline-block;
    transition: transform .2s;
    margin-right: 4px;
}
.crc-afluents-toggle.crc-obert .crc-fletxa { transform: rotate(90deg); }

.crc-afluents-llista { display: none; padding: 0; margin: 4px 0 0; list-style: none; }
.crc-afluents-llista.crc-obert { display: block; }
.crc-afluents-llista li {
    padding: 4px 8px 4px 22px;
    font-size: 12px;
    color: var(--crc-ink-soft);
    cursor: pointer;
    border-radius: 2px;
    position: relative;
}
.crc-afluents-llista li::before {
    content: "·";
    position: absolute;
    left: 10px;
    color: var(--crc-rule);
}
.crc-afluents-llista li:hover,
.crc-afluents-llista li.crc-hover {
    background: rgba(184,134,44,.15);
    color: var(--crc-ink);
}

/* ===== CAPES (toggle comarques) ===== */
.crc-capes {
    border-top: 1px solid var(--crc-rule);
    padding: 14px 20px;
    margin-top: auto;
    background: rgba(255,255,255,.25);
}
.crc-capa-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--crc-ink);
    user-select: none;
}
.crc-capa-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.crc-checkbox {
    width: 18px;
    height: 18px;
    border: 1px solid var(--crc-ink-soft);
    border-radius: 2px;
    background: var(--crc-paper);
    flex-shrink: 0;
    position: relative;
    transition: all .15s;
}
.crc-capa-toggle input:checked + .crc-checkbox {
    background: var(--crc-ink);
    border-color: var(--crc-ink);
}
.crc-capa-toggle input:checked + .crc-checkbox::after {
    content: "✓";
    color: var(--crc-paper);
    font-size: 13px;
    font-weight: 700;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -52%);
    line-height: 1;
}
.crc-capa-toggle:hover .crc-checkbox {
    border-color: var(--crc-gold);
}
.crc-capa-nom {
    font-style: italic;
}

/* Amagat quan toggle off */
.crc-app.crc-sense-comarques #crc-comarques {
    display: none;
}

/* Mode joc "Ubica els principals": amagar tot el que NO té data-ubicar="1" */
.crc-app.crc-mode-nomes-principals .crc-mapa-container .riu[data-ubicar="0"] {
    display: none;
}
.crc-app.crc-mode-nomes-principals .crc-mapa-container .rius-fora {
    display: none;
}

/* Toggle d'embassaments */
.crc-app.crc-sense-embassaments #crc-embassaments {
    display: none;
}

/* Mode joc "Ubica pantans": amagar rius decoratius però mantenir els principals com a context */
.crc-app.crc-mode-pantans .crc-mapa-container .riu[data-llistat="0"] {
    display: none;
}
.crc-app.crc-mode-pantans .crc-mapa-container .rius-fora {
    display: none;
}
/* En mode pantans els rius queden més apagats per fer ressaltar els pantans */
.crc-app.crc-mode-pantans .crc-mapa-container .riu .riu-vis {
    opacity: 0.4 !important;
}

/* Interactivitat embassaments */
.crc-mapa-container .embassament {
    cursor: pointer;
}
.crc-mapa-container .embassament:hover .emb-poli,
.crc-mapa-container .embassament.crc-hover .emb-poli {
    fill: #b8862c !important;
    stroke-width: 2 !important;
}
.crc-mapa-container .embassament:hover .emb-marker,
.crc-mapa-container .embassament.crc-hover .emb-marker {
    fill: #b8862c !important;
    r: 6;
}
.crc-mapa-container .embassament.crc-encert .emb-poli {
    fill: var(--crc-good) !important;
    stroke: var(--crc-good) !important;
    stroke-width: 2 !important;
    animation: crc-pulse-fill 1.2s ease-out;
}
.crc-mapa-container .embassament.crc-encert .emb-marker {
    fill: var(--crc-good) !important;
    r: 7;
}
.crc-mapa-container .embassament.crc-pista .emb-poli {
    fill: var(--crc-gold) !important;
    stroke: var(--crc-gold) !important;
    stroke-width: 2 !important;
    animation: crc-blink 1s ease-in-out 2;
}
.crc-mapa-container .embassament.crc-pista .emb-marker {
    fill: var(--crc-gold) !important;
    r: 7;
}

@keyframes crc-pulse-fill {
    0% { stroke-width: 0.8; }
    40% { stroke-width: 6; }
    100% { stroke-width: 2; }
}

/* En mode estudi mostrar etiquetes de pantans també */
.crc-app.crc-mode-estudi-actiu .crc-mapa-container .emb-labels {
    display: inline !important;
}
.crc-app.crc-mode-estudi-actiu .crc-mapa-container .embassament {
    cursor: default;
}

/* ===== MAPA ===== */
.crc-mapa-wrap {
    position: relative;
    background: var(--crc-bg-out);
    overflow: hidden;
}
.crc-mapa-container {
    width: 100%;
    height: 100%;
    cursor: grab;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}
.crc-mapa-container.crc-arrossegant { cursor: grabbing; }
.crc-mapa-container svg {
    width: 100%;
    height: 100%;
    display: block;
}
.crc-loading {
    color: var(--crc-ink-soft);
    font-style: italic;
    font-size: 14px;
    padding: 20px;
}

/* Controls zoom */
.crc-zoom-controls {
    position: absolute;
    top: 14px;
    right: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 20;
}
.crc-zoom-btn {
    width: 36px;
    height: 36px;
    background: var(--crc-paper);
    border: 1px solid var(--crc-rule);
    color: var(--crc-ink);
    font-family: Georgia, serif;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    transition: all .15s;
    border-radius: 2px;
    line-height: 1;
    padding: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.crc-zoom-btn:hover {
    background: var(--crc-ink);
    color: var(--crc-paper);
    border-color: var(--crc-ink);
}
.crc-zoom-btn.crc-reset { font-size: 14px; font-weight: 400; }

/* Rius */
.crc-mapa-container .riu .riu-clic { cursor: pointer; pointer-events: stroke; }
.crc-mapa-container .riu:hover .riu-vis,
.crc-mapa-container .riu.crc-hover .riu-vis {
    stroke: #b8862c !important;
    stroke-width: 5 !important;
    opacity: 1 !important;
}
.crc-mapa-container .riu.crc-encert .riu-vis {
    stroke: var(--crc-good) !important;
    stroke-width: 6 !important;
    opacity: 1 !important;
    animation: crc-pulse 1.2s ease-out;
}
.crc-mapa-container .riu.crc-pista .riu-vis {
    stroke: var(--crc-gold) !important;
    stroke-width: 5 !important;
    opacity: 1 !important;
    animation: crc-blink 1s ease-in-out 2;
}

/* Mode estudi */
.crc-app.crc-mode-estudi-actiu .crc-mapa-container .rius-labels {
    display: inline !important;
}
.crc-app.crc-mode-estudi-actiu .crc-mapa-container .riu { cursor: default; }
.crc-app.crc-mode-estudi-actiu .crc-mapa-container .riu .riu-clic { pointer-events: none; }

/* Mentre arrossega: desactivar tots els pointer-events sobre rius per màxima fluïdesa */
.crc-mapa-container.crc-arrossegant .riu .riu-clic { pointer-events: none; }
.crc-mapa-container.crc-arrossegant .riu:hover .riu-vis {
    stroke: inherit !important;
    stroke-width: inherit !important;
    opacity: inherit !important;
}

@keyframes crc-pulse {
    0% { stroke-width: 2; }
    40% { stroke-width: 10; }
    100% { stroke-width: 6; }
}
@keyframes crc-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Toast */
.crc-toast {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    background: var(--crc-ink);
    color: var(--crc-paper);
    padding: 12px 22px;
    border-radius: 2px;
    font-size: 14px;
    font-style: italic;
    transition: transform .35s cubic-bezier(.2,.8,.2,1);
    z-index: 10;
    box-shadow: 0 10px 30px rgba(0,0,0,.2);
    pointer-events: none;
    max-width: 80%;
    text-align: center;
}
.crc-toast.crc-show { transform: translateX(-50%) translateY(0); }
.crc-toast.crc-ok { background: var(--crc-good); }
.crc-toast.crc-ko { background: var(--crc-bad); }

@media (max-width: 720px) {
    .crc-app {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: auto;
        min-height: var(--crc-altura, 720px);
    }
    .crc-panel {
        border-right: none;
        border-bottom: 1px solid var(--crc-rule);
        max-height: 50vh;
    }
    .crc-titol { font-size: 22px; }
    .crc-objectiu { font-size: 20px; }
    .crc-mapa-wrap { min-height: 400px; }
}
