:root {
    --bg-body: #f8fafc;
    --primary: #0ea5e9;
    --primary-hover: #0284c7;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
}

/* Dark Mode Theme overrides */
body.dark, .dark-mode, body.theme-dark {
    --bg-body: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    /* Primary usually stays same or slightly brighter */
}

body {
    background-color: var(--bg-body);
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
    margin: 0;
    padding-bottom: 80px;
}

.tool-container {
    max-width: 1100px;
    margin: 40px auto;
    padding: 0 20px;
}

.tool-header { text-align: center; margin-bottom: 30px; }
.tool-header h1 { font-size: 2rem; font-weight: 800; margin-bottom: 10px; }

/* ZONA DE CARGA */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 16px;
    background: var(--bg-card, white); /* fallback */
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}
body.dark .upload-zone { background: #1e293b; }
body.theme-dark .upload-zone { background: #1e293b; }

.upload-zone:hover { border-color: var(--primary); background: rgba(14, 165, 233, 0.08); }
body.dark .upload-zone:hover { background: rgba(14, 165, 233, 0.15); }
body.theme-dark .upload-zone:hover { background: rgba(14, 165, 233, 0.15); }


/* BARRA DE HERRAMIENTAS GLOBAL (Rotar Todo) */
.global-controls {
    display: none; /* Oculto inicio */
    justify-content: center;
    gap: 15px;
    margin-bottom: 30px;
    background: var(--bg-card, white);
    padding: 15px;
    border-radius: 50px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 10px rgba(0,0,0,0.03);
    width: fit-content;
    margin-left: auto; margin-right: auto;
}
body.dark .global-controls { background: #1e293b; }
body.theme-dark .global-controls { background: #1e293b; }

.ctrl-btn {
    background: transparent; border: 1px solid var(--border);
    padding: 8px 16px; border-radius: 20px;
    font-size: 0.9rem; color: var(--text-main); cursor: pointer;
    display: flex; align-items: center; gap: 8px;
    transition: 0.2s;
}
.ctrl-btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
body.dark .ctrl-btn:hover { background: #334155; border-color: #475569; }
body.theme-dark .ctrl-btn:hover { background: #334155; border-color: #475569; }

.ctrl-btn.reset { color: #ef4444; border-color: transparent; }
.ctrl-btn.reset:hover { background: #fee2e2; }
body.dark .ctrl-btn.reset:hover { background: #7f1d1d; }
body.theme-dark .ctrl-btn.reset:hover { background: #7f1d1d; }


/* GRID DE PÁGINAS */
.pages-grid {
    display: none; /* Oculto inicio */
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 25px;
}

/* TARJETA DE PÁGINA */
.page-card {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}

/* El marco que contiene la hoja */
.card-frame {
    width: 100%;
    aspect-ratio: 1/1; /* Cuadrado para permitir rotación sin solapamiento */
    background: transparent;
    display: flex; align-items: center; justify-content: center;
    position: relative;
}

/* La hoja visual que rota */
.page-preview {
    width: 120px; aspect-ratio: 1/1.4;
    background: white; /* Always white paper */
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border-radius: 4px;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); /* Efecto rebote suave */
    display: flex; align-items: center; justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Decoración interna de la hoja (texto falso) */
.dummy-content {
    width: 80%; height: 80%;
    display: flex; flex-direction: column; gap: 6px; opacity: 0.3;
}
.line { height: 4px; background: #cbd5e1; border-radius: 2px; }
.line.title { height: 8px; width: 60%; background: #94a3b8; margin-bottom: 5px; }
.img-placeholder { height: 40px; background: #e2e8f0; margin-bottom: 5px; border-radius: 4px; }


/* BOTONES SOBRE LA TARJETA (Overlay) */
.card-actions {
    position: absolute;
    bottom: -10px;
    display: flex; gap: 10px;
    opacity: 0; transform: translateY(10px);
    transition: 0.2s;
    z-index: 10;
}
.card-frame:hover .card-actions, .card-frame:focus-within .card-actions { opacity: 1; transform: translateY(0); }

/* Force visible on touch devices if needed or keep hover logic */

.rotate-mini-btn {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--text-main); color: var(--bg-body); /* Inverted for contrast */
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: 0.2s;
}
.rotate-mini-btn:hover { background: var(--primary); color: white; transform: scale(1.1); }

.page-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }


/* BARRA DE ACCIÓN */
.action-bar {
    position: fixed; bottom: 0; left: 0; width: 100%;
    background: var(--bg-card, white); padding: 15px 40px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    transform: translateY(100%); transition: transform 0.3s;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
    z-index: 100;
}
body.dark .action-bar { background: #1e293b; }
body.theme-dark .action-bar { background: #1e293b; }
.action-bar.visible { transform: translateY(0); }

.download-btn {
    background: var(--primary); color: white;
    padding: 12px 30px; border-radius: 10px; border: none;
    font-size: 1rem; font-weight: 600; cursor: pointer;
}
.download-btn:hover { background: var(--primary-hover); }
.download-btn:disabled { background: var(--text-muted); cursor: not-allowed; opacity: 0.7; }

canvas {
    width: 100%; height: 100%; object-fit: contain;
}
