@font-face { font-family: 'CamelotCaps'; src: url('assets/fonts/Camelotcaps-aW2x.ttf') format('truetype'); }
@font-face { font-family: 'DeRoos'; src: url('assets/fonts/DeroosCaps-p78BO.ttf') format('truetype'); }

:root {
    --terracotta: #d97757;
    --ink: #000;
    --ink-soft: #2c2416;
    --gold: #b28d1e;
    --panel: rgba(0, 0, 0, 0.08);
}

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

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background: var(--terracotta);
    color: var(--ink);
    line-height: 1.7;
    padding: 20px;
    overflow-x: clip;
}

.container { max-width: 1000px; margin: 0 auto; }

/* ---- topbar ---- */
.topbar { margin-bottom: 24px; }
.brand { display: flex; align-items: center; gap: 16px; }
.brand-shield { width: 64px; height: auto; }
h1 { font-family: 'DeRoos', 'Courier New', monospace; font-size: 1.9em; line-height: 1.1; }
.subtitle { font-family: 'Courier New', monospace; font-size: 0.8em; opacity: 0.75; }

/* ---- tabs ---- */
.tabbar {
    display: flex; gap: 3px; background: var(--ink); border-radius: 8px; padding: 6px;
    margin-bottom: 28px; overflow-x: auto; scrollbar-width: none; position: sticky; top: 8px; z-index: 40;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
}
.tabbar::-webkit-scrollbar { display: none; }
.tab {
    font-family: 'DeRoos', 'Courier New', monospace; color: var(--terracotta); text-decoration: none;
    font-size: 1em; padding: 10px 14px; min-height: 44px; display: flex; align-items: center;
    justify-content: center; border-radius: 5px; white-space: nowrap; flex: 1 0 auto;
    transition: background-color 0.2s, color 0.2s;
}
.tab:hover { background: var(--ink-soft); }
.tab.active { background: var(--terracotta); color: var(--ink); }

#panel { min-height: 60vh; }
h2 { font-family: 'DeRoos', 'Courier New', monospace; font-size: 1.6em; margin-bottom: 14px; }
h3 { font-size: 1.2em; margin: 18px 0 8px; }
p { margin-bottom: 0.8em; }
a { color: var(--ink); }

/* ---- fan chart ---- */
.fan-wrap { text-align: center; }
.fan-legend { display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: center; margin: 14px 0; font-family: 'Courier New', monospace; font-size: 13px; }
.fan-legend span { display: inline-flex; align-items: center; gap: 6px; }
.fan-legend .dot { width: 14px; height: 14px; border-radius: 3px; border: 1.5px solid #000; }
.fan-seg { cursor: pointer; stroke: var(--terracotta); stroke-width: 1.5; transition: filter 0.15s; }
.fan-seg:hover { filter: brightness(1.15); }
.fan-label { font-family: 'Georgia', serif; pointer-events: none; }
.fan-tip {
    background: #000; color: var(--terracotta); border-radius: 8px; padding: 10px 14px;
    max-width: 320px; margin: 12px auto 0; font-size: 0.9em; text-align: left; min-height: 1px;
}

/* ---- mapa scrollytelling ---- */
.scrolly { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.scrolly-graphic { position: sticky; top: 70px; height: 78vh; align-self: start; }
.scrolly-graphic svg { width: 100%; height: 100%; border: 2px solid #000; border-radius: 8px; background: var(--terracotta); }
.scrolly-steps { padding-bottom: 45vh; }
.step {
    min-height: 62vh; display: flex; flex-direction: column; justify-content: center;
    padding: 20px; margin-bottom: 8px; opacity: 0.35; transition: opacity 0.3s;
}
.step.active { opacity: 1; }
.step .cap-title { font-family: 'DeRoos', 'Courier New', monospace; font-size: 1.4em; margin-bottom: 10px; }
.land { fill: #000; opacity: 0.82; }
.graticule { stroke: rgba(0,0,0,0.15); stroke-width: 0.5; fill: none; }
.mig-arc { fill: none; stroke: var(--gold); stroke-width: 2.5; opacity: 0; transition: opacity 0.5s, stroke-dashoffset 1.2s ease-out; }
.mig-arc.on { opacity: 1; }
.mig-pt { fill: var(--terracotta); stroke: #000; stroke-width: 1.5; }
.mig-pt.focus { fill: var(--gold); }
.mig-lbl { fill: var(--terracotta); font-family: 'Courier New', monospace; font-size: 11px; paint-order: stroke; stroke: #000; stroke-width: 2.5px; }

@media (max-width: 780px) {
    .scrolly { grid-template-columns: 1fr; }
    .scrolly-graphic { position: sticky; top: 60px; height: 46vh; z-index: 5; background: var(--terracotta); }
    .step { min-height: 40vh; }
}

/* ---- cronologia ---- */
.timeline { border-left: 3px solid #000; margin-left: 12px; padding-left: 22px; }
.tl-event { position: relative; margin-bottom: 18px; }
.tl-event::before { content: ''; position: absolute; left: -30px; top: 6px; width: 12px; height: 12px; background: var(--gold); border: 2px solid #000; border-radius: 50%; }
.tl-year { font-family: 'DeRoos', 'Courier New', monospace; font-size: 1.2em; }
.tl-bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; margin: 20px 0; }
.tl-bar { background: #000; flex: 1; min-width: 8px; border-radius: 3px 3px 0 0; position: relative; }
.tl-bar span { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 10px; font-family: 'Courier New', monospace; }

/* ---- checklist ---- */
.progress { font-family: 'Courier New', monospace; margin-bottom: 20px; }
.progress-bar { height: 10px; background: rgba(0,0,0,0.15); border: 1.5px solid #000; border-radius: 6px; overflow: hidden; margin-top: 6px; }
.progress-bar > div { height: 100%; background: var(--gold); }
.lin-card { background: var(--panel); border: 2px solid #000; border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.lin-card h3 { margin-top: 0; font-family: 'DeRoos', 'Courier New', monospace; }
.lin-sub { font-family: 'Courier New', monospace; font-size: 0.8em; opacity: 0.7; margin-bottom: 8px; }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; border-top: 1px solid rgba(0,0,0,0.12); }
.task .box { font-family: 'Courier New', monospace; font-weight: bold; }
.task.fet { opacity: 0.55; text-decoration: line-through; }
.prio { font-size: 0.9em; }
.tasca-persones { display: block; font-size: 0.8em; opacity: 0.7; }
.tramits { background: var(--panel); border: 2px solid #000; border-radius: 10px; padding: 16px; margin-top: 10px; }
.chk { font-family: 'Courier New', monospace; font-weight: bold; font-size: 1.05em; background: none; border: none; cursor: pointer; padding: 0 2px; color: #000; line-height: 1; }
.chk:disabled { cursor: default; opacity: 0.75; }
.chk:not(:disabled):hover { color: var(--gold); }

/* ---- targetes ---- */
.targetes-wrap { margin-top: 34px; }
.targeta-form { background: var(--panel); border: 2px solid #000; border-radius: 10px; padding: 16px; margin-bottom: 18px; }
.targeta-form textarea, .targeta-form input, .targeta-form select { font-family: 'Georgia', serif; width: 100%; padding: 8px 10px; border: 2px solid #000; border-radius: 6px; background: rgba(255,255,255,0.35); font-size: 0.95em; }
.targeta-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.targeta-row > * { flex: 1 1 140px; }
.foto-label { flex: 0 0 auto; background: #000; color: var(--terracotta); padding: 8px 12px; border-radius: 6px; cursor: pointer; font-family: 'Courier New', monospace; font-size: 0.85em; }
.foto-nom { flex: 1 1 auto; font-family: monospace; font-size: 0.8em; opacity: 0.7; }
.targeta-form button[type=submit] { flex: 0 0 auto; background: var(--gold); color: #000; border: 2px solid #000; border-radius: 6px; padding: 9px 16px; font-family: 'DeRoos', 'Courier New', monospace; cursor: pointer; }
.targeta-msg { font-family: monospace; font-size: 0.85em; margin-top: 8px; min-height: 1em; }
.targetes-llista { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.targeta { background: var(--panel); border: 2px solid #000; border-radius: 10px; padding: 12px; }
.targeta img { width: 100%; border-radius: 6px; border: 1.5px solid #000; margin-bottom: 8px; }
.targeta p { font-size: 0.92em; margin-bottom: 8px; }
.targeta-meta { font-family: 'Courier New', monospace; font-size: 0.72em; opacity: 0.8; display: flex; flex-direction: column; gap: 2px; }
.targeta-autor { opacity: 0.7; }

/* ---- arbre navegable ---- */
.arbre-search { font-family: 'Courier New', monospace; padding: 8px 12px; border: 2px solid #000; border-radius: 6px; background: rgba(255,255,255,0.35); min-width: 240px; font-size: 0.95em; }
.arbre-results { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.arbre-hit { font-family: 'Courier New', monospace; font-size: 0.82em; background: #000; color: var(--terracotta); border: none; border-radius: 5px; padding: 5px 9px; cursor: pointer; }
.arbre-hit:hover { background: var(--ink-soft); }
.arbre-holder { position: relative; border: 2px solid #000; border-radius: 8px; overflow: hidden; background: var(--terracotta); }
.arbre-svg { display: block; width: 100%; height: 70vh; cursor: grab; touch-action: pan-y; }
.arbre-svg:active { cursor: grabbing; }
.arbre-box { fill: #000; stroke: var(--terracotta); stroke-width: 2; transition: stroke-width 0.12s; }
.arbre-node { cursor: pointer; outline: none; }
.arbre-node:hover .arbre-box, .arbre-node:focus-visible .arbre-box { stroke-width: 4; }
.arbre-node.focus .arbre-box { fill: var(--gold); stroke: #000; }
.arbre-node.viu .arbre-box { stroke-dasharray: 4 3; }
.arbre-nom { fill: var(--terracotta); font-family: 'Georgia', serif; font-size: 12px; font-weight: bold; pointer-events: none; }
.arbre-node.focus .arbre-nom, .arbre-node.focus .arbre-anys { fill: #000; }
.arbre-anys { fill: var(--terracotta); font-family: 'Courier New', monospace; font-size: 10px; opacity: 0.8; pointer-events: none; }
.arbre-edge { fill: none; stroke: #000; stroke-width: 1.6; opacity: 0.4; }
.arbre-spouse { stroke: var(--gold); stroke-width: 3; }
.arbre-ctrl { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.arbre-ctrl button { width: 38px; height: 38px; background: #000; color: var(--terracotta); border: none; border-radius: 6px; font-size: 1.1em; cursor: pointer; font-family: 'Courier New', monospace; }
.arbre-ctrl button:hover { background: var(--ink-soft); }
.arbre-focus-info { position: absolute; left: 10px; top: 10px; background: #000; color: var(--terracotta); padding: 8px 12px; border-radius: 6px; font-size: 0.85em; max-width: 60%; }

.foot { font-family: 'Courier New', monospace; font-size: 0.72em; opacity: 0.6; text-align: center; margin-top: 40px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-width: 780px) { .container { } h1 { font-size: 1.4em; } .tab { font-size: 0.9em; padding: 8px 11px; } }
