/* HEADSPACE — base.css
   Reset, tipografía, layout y componentes compartidos entre todos los mundos.
   Cada mundo sobreescribe las variables --world-* en /assets/css/themes/*.css
*/

@font-face {
    font-family: 'Omori';
    src: url('/assets/fonts/OMORI_GAME.ttf') format('truetype');
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Omori Fancy';
    src: url('/assets/fonts/OMORI_GAME2.ttf') format('truetype');
    font-weight: normal;
    font-display: swap;
}

:root {
    /* Paleta neutra por defecto (se sobreescribe por tema de mundo) */
    --world-bg: #1a1625;
    --world-bg-image: none;
    --world-surface: #2b2440;
    --world-surface-alt: #392f57;
    --world-text: #f4eefc;
    --world-text-muted: #b9aed4;
    --world-accent: #f2a3c1;
    --world-accent-2: #7ee8c7;
    --world-border: #4a3d6b;
    --world-danger: #ff6b6b;
    --world-shadow: rgba(10, 6, 20, 0.45);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;

    --font-display: 'Omori Fancy', 'Omori', system-ui, sans-serif;
    --font-body: 'Omori', system-ui, sans-serif;

    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: var(--font-body);
    background-color: var(--world-bg);
    color: var(--world-text);
    min-height: 100dvh;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
    transition: background-color 0.4s ease;
    position: relative;
}

/* Fondo de mundo: escena de OMORI a baja opacidad, fija detrás del contenido.
   El color sólido --world-bg sigue siendo la base para que el texto sea legible. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: var(--world-bg-image);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    opacity: var(--world-bg-opacity, 0.22);
    z-index: -1;
    pointer-events: none;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: normal;
    margin: 0 0 0.5em;
    letter-spacing: 0.5px;
}

p {
    margin: 0 0 1em;
}

a {
    color: var(--world-accent);
}

button, input, select, textarea {
    font-family: inherit;
    font-size: 1rem;
    color: inherit;
}

img {
    max-width: 100%;
    display: block;
}

/* ---------- Layout raíz ---------- */

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem calc(1rem + env(safe-area-inset-top));
    padding-top: max(1rem, env(safe-area-inset-top));
}

.app-header .title {
    font-family: var(--font-display);
    font-size: 1.4rem;
    color: var(--world-accent);
    text-shadow: 0 2px 0 var(--world-shadow);
}

.icon-btn {
    background: var(--world-surface);
    border: 2px solid var(--world-border);
    border-radius: var(--radius-sm);
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:active {
    transform: scale(0.92);
}

.app-main {
    flex: 1;
    padding: 0.5rem 1.25rem 2rem;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
}

/* ---------- Bottom nav (mobile-first) ---------- */

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--world-surface);
    border-top: 2px solid var(--world-border);
    padding: 0.4rem 0.25rem calc(0.4rem + env(safe-area-inset-bottom));
    z-index: 40;
}

.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    font-size: 0.65rem;
    text-decoration: none;
    color: var(--world-text-muted);
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease, transform 0.15s ease;
}

.bottom-nav a img {
    width: 26px;
    height: 26px;
    image-rendering: pixelated;
    opacity: 0.7;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.bottom-nav a.active {
    color: var(--world-accent);
}

.bottom-nav a.active img {
    opacity: 1;
    transform: translateY(-3px);
}

.bottom-nav a:active {
    transform: scale(0.9);
}

/* ---------- Tarjetas / paneles ---------- */

.card {
    background: var(--world-surface);
    border: 2px solid var(--world-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
    box-shadow: 0 6px 0 var(--world-shadow);
}

.card-title {
    font-family: var(--font-display);
    font-size: 1.05rem;
    color: var(--world-accent);
    margin-bottom: 0.6rem;
}

/* ---------- Botones estilo OMORI (bordes gruesos, sombra dura) ---------- */

.btn-omori {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--world-accent);
    color: var(--world-bg);
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1.5rem;
    font-family: var(--font-display);
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--world-shadow);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-omori:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--world-shadow);
}

.btn-omori:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-omori.secondary {
    background: transparent;
    color: var(--world-accent);
    border: 2px solid var(--world-accent);
    box-shadow: none;
}

.btn-omori.danger {
    background: var(--world-danger);
}

/* ---------- Formularios ---------- */

.field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.field-label {
    font-size: 0.75rem;
    text-transform: lowercase;
    color: var(--world-text-muted);
    letter-spacing: 0.5px;
}

.field input,
.field select,
.field textarea {
    background: var(--world-bg);
    border: 2px solid var(--world-border);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.8rem;
    color: var(--world-text);
    outline: none;
    transition: border-color 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--world-accent);
}

/* ---------- Modal con imagen de fondo ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 6, 20, 0.6);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-panel {
    width: 100%;
    max-width: 480px;
    position: relative;
    background-color: var(--world-surface);
    border: 3px solid var(--world-border);
    border-bottom: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-height: 85dvh;
    overflow-y: auto;
    overflow-x: hidden;
    isolation: isolate;
}

.modal-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--world-modal-bg, none);
    background-size: cover;
    background-position: center;
    opacity: 0.14;
    z-index: -1;
    pointer-events: none;
}

.modal-overlay.open .modal-panel {
    transform: translateY(0);
}

@media (min-width: 640px) {
    .modal-overlay {
        align-items: center;
    }

    .modal-panel {
        border-radius: var(--radius-lg);
        border-bottom: 3px solid var(--world-border);
        transform: translateY(24px) scale(0.96);
        opacity: 0;
    }

    .modal-overlay.open .modal-panel {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* ---------- Mensaje de personaje ---------- */

.character-bubble {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.character-bubble img {
    width: 56px;
    height: 56px;
    image-rendering: pixelated;
    flex-shrink: 0;
    animation: character-bob 2.4s ease-in-out infinite;
}

.character-bubble .bubble {
    background: var(--world-surface);
    border: 2px solid var(--world-border);
    border-radius: var(--radius-md);
    padding: 0.6rem 0.9rem;
    font-size: 0.9rem;
    position: relative;
}

@keyframes character-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* ---------- Utilidades ---------- */

.progress-track {
    background: var(--world-bg);
    border: 2px solid var(--world-border);
    border-radius: 999px;
    height: 14px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--world-accent), var(--world-accent-2));
    border-radius: 999px;
    transition: width 0.6s cubic-bezier(0.65, 0, 0.35, 1);
}

.fade-in {
    animation: fade-in 0.35s ease both;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.empty-state {
    text-align: center;
    color: var(--world-text-muted);
    padding: 2rem 1rem;
    font-size: 0.9rem;
}

.loading-placeholder {
    color: var(--world-text-muted);
    font-size: 0.85rem;
    padding: 0.5rem 0;
}

/* ---------- Listas del dashboard ---------- */

.habit-list, .task-list, .addiction-list, .goal-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.habit-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: opacity 0.2s ease;
}

.habit-row.done {
    opacity: 0.6;
}

.habit-row.done span {
    text-decoration: line-through;
}

.habit-check {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--world-accent);
    background: transparent;
    color: var(--world-bg);
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.15s ease;
}

.habit-row.done .habit-check {
    background: var(--world-accent);
}

.habit-check:active {
    transform: scale(0.85);
}

.task-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding-left: 0.75rem;
    border-left: 3px solid var(--world-border);
}

.task-row.priority-high {
    border-left-color: var(--world-danger);
}

.task-row.priority-medium {
    border-left-color: var(--world-accent);
}

.task-row .due-date {
    font-size: 0.75rem;
    color: var(--world-text-muted);
    flex-shrink: 0;
}

.addiction-row, .goal-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.goal-row {
    flex-direction: column;
    align-items: stretch;
}

.goal-row .progress-track {
    margin-top: 0.35rem;
}

.balance-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    text-align: center;
}

.balance-grid .label {
    display: block;
    font-size: 0.7rem;
    color: var(--world-text-muted);
}

.balance-grid .value {
    display: block;
    font-family: var(--font-display);
    font-size: 1rem;
    margin-top: 0.2rem;
}

.value.income, .value.positive {
    color: var(--world-accent-2);
}

.value.expense, .value.negative {
    color: var(--world-danger);
}

/* ---------- Tarjetas de hábitos (vista dedicada) ---------- */

.habit-card {
    transition: opacity 0.2s ease, transform 0.15s ease;
}

.habit-card.done {
    opacity: 0.65;
}

.habit-card-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.habit-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
}

.habit-info strong {
    font-size: 0.95rem;
}

.habit-card.done .habit-info strong {
    text-decoration: line-through;
}

.habit-streak {
    font-size: 0.75rem;
    color: var(--world-text-muted);
}

.habit-archive {
    background: transparent;
    border: none;
    color: var(--world-text-muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.3rem;
    line-height: 1;
    flex-shrink: 0;
}

.habit-archive:active {
    transform: scale(0.85);
}

/* ---------- Adicciones ---------- */

.addiction-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.days-counter {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.days-number {
    font-family: var(--font-display);
    font-size: 2.4rem;
    color: var(--world-accent);
    line-height: 1;
}

.days-label {
    color: var(--world-text-muted);
    font-size: 0.85rem;
}

.chart-wrap {
    position: relative;
    height: 160px;
    margin-top: 0.5rem;
}

/* ---------- Finanzas ---------- */

.savings-item {
    margin-bottom: 0.9rem;
}

.savings-item:last-child {
    margin-bottom: 0;
}

.savings-item-head {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-bottom: 0.3rem;
}

.tx-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
}

.tx-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.tx-note {
    font-size: 0.75rem;
    color: var(--world-text-muted);
}

.tx-date {
    font-size: 0.7rem;
    color: var(--world-text-muted);
}

.tx-amount {
    font-family: var(--font-display);
    font-size: 0.95rem;
    white-space: nowrap;
}

.tx-amount.income {
    color: var(--world-accent-2);
}

.tx-amount.expense {
    color: var(--world-danger);
}

.tx-delete {
    background: transparent;
    border: none;
    color: var(--world-text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.2rem;
    flex-shrink: 0;
}

/* ---------- Cuidado personal ---------- */

.mood-picker {
    display: flex;
    justify-content: space-between;
    gap: 0.4rem;
    margin-bottom: 1.1rem;
}

.mood-btn {
    flex: 1;
    background: var(--world-bg);
    border: 2px solid var(--world-border);
    border-radius: var(--radius-sm);
    font-size: 1.4rem;
    padding: 0.5rem 0;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.mood-btn.selected {
    border-color: var(--world-accent);
    background: var(--world-surface-alt);
    transform: translateY(-3px);
}

.checkbox-field {
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
}

.checkbox-field input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--world-accent);
}

/* ---------- Objetivos ---------- */

.section-heading {
    font-family: var(--font-display);
    font-size: 0.95rem;
    color: var(--world-text-muted);
    margin: 1.25rem 0 0.6rem;
    text-transform: lowercase;
    letter-spacing: 0.5px;
}

.section-heading:first-child {
    margin-top: 0;
}

.goal-card.completed {
    opacity: 0.7;
}

.subtask-list {
    list-style: none;
    margin: 0 0 0.6rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.subtask-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.85rem;
}

.subtask-row.done span {
    text-decoration: line-through;
    color: var(--world-text-muted);
}

.subtask-check {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    border: 2px solid var(--world-accent);
    background: transparent;
    color: var(--world-bg);
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 0.7rem;
    flex-shrink: 0;
}

.subtask-row.done .subtask-check {
    background: var(--world-accent);
}

.subtask-form {
    display: flex;
    gap: 0.5rem;
}

.subtask-form input {
    flex: 1;
    background: var(--world-bg);
    border: 2px solid var(--world-border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.6rem;
    color: var(--world-text);
    font-size: 0.85rem;
}

/* ---------- Tareas ---------- */

.task-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-left: 4px solid var(--world-border);
}

.task-card.priority-high {
    border-left-color: var(--world-danger);
}

.task-card.priority-medium {
    border-left-color: var(--world-accent);
}

.task-card.done {
    opacity: 0.6;
}

.task-card.done .task-card-info strong {
    text-decoration: line-through;
}

.task-card.overdue .due-date {
    color: var(--world-danger);
}

.task-card-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}
