/* ─── Variables (ACTotal Theme) ─── */
:root {
    --bg: #050506;
    --surface: #111827;
    --surface-light: #1f2937;
    --surface-hover: #374151;
    --accent: #00A7E1;
    --accent-glow: rgba(0, 167, 225, 0.35);
    --accent-soft: rgba(0, 167, 225, 0.12);
    --accent-medium: rgba(0, 167, 225, 0.25);
    --text: #ffffff;
    --text-dim: #9ca3af;
    --radius: 20px;
    --radius-sm: 12px;

    --success: #10b981;
    --danger: #ef4444;
    --purple: #8B5CF6;
    --purple-glow: rgba(139, 92, 246, 0.35);
}

/* ─── Base Reset ─── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

/* ─── Layout ─── */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding: 1.5rem;
    max-width: 600px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--purple), #6D28D9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.btn-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, .08);
    background: var(--surface);
    color: var(--text-dim);
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all .2s;
}

.btn-icon:hover {
    background: var(--surface-light);
    color: var(--text);
}

/* ─── Main Content ─── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding-top: 1rem;
}

/* ─── Result Panel ─── */
.result-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius);
    padding: 1.2rem 2rem;
    width: 100%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.result-panel.has-result {
    border-color: var(--purple);
    box-shadow: 0 4px 25px var(--purple-glow);
}

.result-factor,
.result-answer {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--text-dim);
    transition: all 0.3s;
    min-width: 2ch;
    text-align: center;
}

.result-factor.active {
    color: var(--accent);
}

.result-answer.active {
    color: var(--purple);
    text-shadow: 0 0 20px var(--purple-glow);
    transform: scale(1.1);
}

.result-operator,
.result-equals {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-dim);
}

/* ─── Hint Text ─── */
.hint-text {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-align: center;
    min-height: 1.2em;
    transition: opacity 0.3s;
}

/* ─── Table Wrapper ─── */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* ─── Pythagorean Table ─── */
.pyth-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    user-select: none;
}

/* Corner cell */
.corner-cell {
    background: linear-gradient(135deg, var(--purple), #6D28D9);
    color: #fff;
    font-size: 1.2rem;
    font-weight: 800;
    text-align: center;
    padding: 0.5rem;
    position: sticky;
    left: 0;
    z-index: 3;
}

/* Column headers (top row) */
.col-header {
    background: var(--surface-light);
    color: var(--text-dim);
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
    padding: 0.6rem 0.3rem;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid rgba(255, 255, 255, 0.06);
    position: relative;
}

.col-header:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.col-header.selected {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 15px var(--accent-glow);
}

/* Row headers (left column) */
.row-header {
    background: var(--surface-light);
    color: var(--text-dim);
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
    padding: 0.6rem 0.3rem;
    cursor: pointer;
    transition: all 0.2s;
    border-right: 2px solid rgba(255, 255, 255, 0.06);
    position: sticky;
    left: 0;
    z-index: 2;
}

.row-header:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.row-header.selected {
    background: var(--accent);
    color: #fff;
    box-shadow: 4px 0 15px var(--accent-glow);
}

/* Data cells */
.data-cell {
    text-align: center;
    padding: 0.5rem 0.3rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-dim);
    border: 1px solid rgba(255, 255, 255, 0.03);
    transition: all 0.25s;
}

/* Highlighted column */
.data-cell.highlight-col {
    background: var(--accent-soft);
    color: var(--text);
}

/* Highlighted row */
.data-cell.highlight-row {
    background: var(--accent-soft);
    color: var(--text);
}

/* When both row and col are highlighted (non-intersection cells get slightly stronger) */
.data-cell.highlight-col.highlight-row {
    background: var(--accent-medium);
}

/* ★ Intersection cell — the star of the show */
.data-cell.highlight-intersection {
    background: var(--purple);
    color: #fff;
    font-size: 1.15rem;
    font-weight: 800;
    border-radius: 6px;
    box-shadow: 0 0 20px var(--purple-glow), inset 0 0 10px rgba(255, 255, 255, 0.15);
    transform: scale(1.15);
    position: relative;
    z-index: 1;
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% {
        transform: scale(0.7);
        opacity: 0.5;
    }

    100% {
        transform: scale(1.15);
        opacity: 1;
    }
}

/* ─── Responsive ─── */
@media (max-width: 420px) {
    .app-container {
        padding: 1rem;
    }

    .result-factor,
    .result-answer {
        font-size: 1.8rem;
    }

    .result-operator,
    .result-equals {
        font-size: 1.3rem;
    }

    .col-header,
    .row-header {
        font-size: 0.8rem;
        padding: 0.4rem 0.2rem;
    }

    .data-cell {
        font-size: 0.75rem;
        padding: 0.35rem 0.15rem;
    }

    .corner-cell {
        font-size: 1rem;
        padding: 0.4rem;
    }

    .data-cell.highlight-intersection {
        font-size: 0.95rem;
    }
}

/* ─── Footer ─── */
.app-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: auto;
    padding-top: 2rem;
}