:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #273549;
    --border: #334155;
    --text: #f8fafc;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --accent-hover: #0ea5e9;
    --radius: 12px;
}

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

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 1.25rem;
}

/* Navbar */
.navbar {
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.navbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 64px;
    flex-wrap: wrap;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1.15rem;
}

.brand-cube {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: conic-gradient(#ef4444 0 90deg, #3b82f6 90deg 180deg, #22c55e 180deg 270deg, #facc15 270deg);
    display: inline-block;
}

.nav-links {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.nav-links a {
    color: var(--muted);
    text-decoration: none;
    padding: 0.45rem 0.85rem;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: background 0.15s, color 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
    background: var(--surface);
    color: var(--text);
}

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

/* Main */
.main-content {
    flex: 1;
    padding-top: 2.5rem;
    padding-bottom: 3rem;
}

/* Hero */
.hero {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 2.5rem;
    align-items: center;
    margin-bottom: 3.5rem;
}

.badge {
    display: inline-block;
    background: rgba(56, 189, 248, 0.15);
    color: var(--accent);
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.hero h1 {
    font-size: 2.4rem;
    line-height: 1.15;
    margin-bottom: 1rem;
}

.hero p {
    color: var(--muted);
    font-size: 1.05rem;
    margin-bottom: 1.5rem;
}

.hero-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.hero-viewer,
.puzzle-stage {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    height: 360px;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

rubikaz-viewer {
    display: block;
    width: 100%;
    height: 100%;
}

.rv-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
}

.rv-stage {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    /* Banda sutil detrás de la barra inferior de twisty-player para que los botones deshabilitados se distingan mejor */
    background: linear-gradient(
        to top,
        rgba(203, 213, 225, 0.35) 0%,
        rgba(203, 213, 225, 0.35) 54px,
        transparent 54px
    );
}

.rv-reset-camera {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 2;
    background: rgba(15, 23, 42, 0.85);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.rv-reset-camera:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--surface);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 1.2rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #082f49;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
}

/* Catalog */
.catalog h2 {
    font-size: 1.4rem;
    margin-bottom: 1.25rem;
}

.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: transform 0.15s, border-color 0.15s;
}

.card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.card h3 {
    font-size: 1.1rem;
}

.card p {
    color: var(--muted);
    font-size: 0.92rem;
    flex: 1;
}

.card-link {
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 600;
}

.pill {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--surface-hover);
    color: var(--muted);
    border: 1px solid var(--border);
    white-space: nowrap;
}

/* Puzzle detail */
.puzzle-page {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.5rem;
    align-items: start;
}

.puzzle-info h1 {
    font-size: 2rem;
    margin: 0.75rem 0;
}

.lead {
    color: var(--muted);
    font-size: 1.05rem;
    margin-bottom: 1.5rem;
}

.alg-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.alg-label {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.alg-box code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--accent);
    font-size: 1rem;
}

.htmx-demo {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.85rem;
}

.fact-box {
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem;
    font-size: 0.95rem;
}

.not-found {
    text-align: center;
    padding: 4rem 1rem;
}

.not-found h1 {
    font-size: 4rem;
    color: var(--accent);
}

.not-found p {
    color: var(--muted);
    margin: 0.75rem 0 1.5rem;
}

/* CTA & Ortega trainer */
.cta-banner {
    margin-bottom: 1.5rem;
}

.ortega-header {
    margin-bottom: 1.75rem;
}

.ortega-header h1 {
    font-size: 2.1rem;
    margin-bottom: 0.5rem;
}

.ortega-controls {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 1rem 1.25rem;
    margin-bottom: 1.75rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.control-group label {
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 600;
}

.control-group input[type="text"],
.control-group select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    font-size: 0.95rem;
}

.control-group input[type="text"] {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.control-check {
    justify-content: center;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    color: var(--text) !important;
    font-weight: 500 !important;
}

.control-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.ortega-summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.summary-label {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.scramble-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--accent);
    font-size: 1.05rem;
    font-weight: 600;
}

.summary-stats {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.steps-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.step-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    gap: 1.5rem;
    align-items: center;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}

.step-num {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.step-info h2 {
    font-size: 1.3rem;
    margin-bottom: 0.85rem;
}

.step-explanation {
    color: var(--muted);
    font-size: 0.95rem;
    margin-bottom: 0.9rem;
}

.vision-box {
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.28);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
}

.step-viewer {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    height: 260px;
    padding: 0.5rem;
}

/* Algorithm catalog & detail */
.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
}

.alg-table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

.alg-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.alg-table th,
.alg-table td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.alg-table th {
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.alg-table tbody tr:last-child td {
    border-bottom: none;
}

.alg-table-action {
    text-align: right;
}

.alg-detail-layout {
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    gap: 1.5rem;
    align-items: start;
}

.alg-rows {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.alg-row-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
}

.alg-row-btn:hover,
.alg-row-btn.active {
    border-color: var(--accent);
    background: var(--surface-hover);
}

.alg-row-btn code {
    flex: 1;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--accent);
    font-size: 0.95rem;
}

.alg-preview-sticky {
    position: sticky;
    top: 84px;
}

.alg-preview-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.alg-preview-card code {
    display: block;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--accent);
    margin-bottom: 0.75rem;
}

.alg-preview-stage {
    height: 300px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.5rem;
}

.htmx-indicator {
    display: none;
    color: var(--accent);
    font-size: 0.85rem;
}

.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request {
    display: inline;
}

/* Footer */
.footer {
    border-top: 1px solid var(--border);
    padding: 1.25rem 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.footer .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.footer a {
    color: var(--accent);
    text-decoration: none;
}

@media (max-width: 800px) {
    .hero,
    .puzzle-page,
    .ortega-controls,
    .step-card {
        grid-template-columns: 1fr;
    }
}
