/*
============================================================================
PROJECTE: Motor Educatiu Step Quiz (Vanilla JS)
FITXER: css/asimptotes.css
ROL: Estils específics per al joc d'asímptotes i límits laterals.
DEPENDÈNCIES: Autònom (inclou reset, variables i font).
              Carregar ABANS de chromebook.css.
============================================================================
*/

@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700;800&display=swap');

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

:root {
    --bg-color:      #f0f6ff;
    --primary:       #2563eb;
    --primary-light: #dbeafe;
    --primary-dark:  #1d4ed8;
    --primary-hover: #1e40af;
    --text-main:     #1e293b;
    --text-muted:    #64748b;
    --border-light:  #e2e8f0;
    --border-heavy:  #cbd5e1;
    --success:       #10b981;
    --danger:        #ef4444;
    --danger-light:  #fee2e2;
}

html { height: 100%; }
body {
    height: 100%;
    min-height: 100vh; min-height: 100dvh; /* [FIX BUG4] */
    display: flex;
    flex-direction: column;
    font-family: 'Barlow', sans-serif;
    background: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
}

/* ---- CAPÇALERA ---- */
.title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 0 6px;
}
.title-row h1 {
    font-size: clamp(.95rem, 1.8vw, 1.2rem);
    font-weight: 700;
    color: var(--primary-dark);
}
.home-icon-link { display:block; width:58px; height:58px; flex-shrink:0; opacity:.75; transition:opacity .2s ease; }
.home-icon-link:hover { opacity:1; }
.home-icon-link img { width:100%; height:100%; object-fit:contain; }

/* ---- PANELL ---- */
.panel {
    max-width: 98vw;
    width: 98vw;
    margin: 0 auto;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 2px 16px rgba(0,0,0,.08);
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

.header-info {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 6px;
}
.session-text {
    font-size: calc(.82rem * 1.2); /* +20% */
    font-weight: 700;
    color: var(--text-muted);
}
.level-text {
    font-size: calc(.75rem * 1.2); /* +20% */
    font-weight: 600;
    color: var(--text-muted);
}
.session-sep {
    color: var(--border-heavy);
    font-weight: 400;
    font-size: 1rem;
}

/* ---- GAME SCREEN ---- */
#game-screen {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
}

/* ---- LAYOUT DUES COLUMNES ---- */
.game-body {
    display: flex;
    flex: 1 1 0;
    min-height: 0;
}

/* Columna esquerra */
.game-left {
    width: 36%;
    display: flex;
    flex-direction: column;
    padding: 14px 12px 14px 16px;
    border-right: 1px solid var(--border-light);
    overflow-y: auto;
    gap: 0;
}

/* Columna dreta */
.game-right {
    width: 64%;
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    overflow: hidden;
    min-height: 0;
}

/* ---- FUNCTION BOX ---- */
.function-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
}

.function-label {
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0;
}
.function-math {
    font-size: 1em;
    color: #111;
    padding: 12px 16px;
    background: #f0f6ff;
    border-radius: 10px;
    border: 2px solid var(--border-light);
    overflow-x: auto;
}

/* ---- OPCIONS 2×2 ---- */
.options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
}

@keyframes popIn {
    0%   { opacity: 0; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1); }
}

.btn-option {
    padding: 14px 10px;
    font-size: 1em;
    border-radius: 10px;
    border: 2px solid var(--border-heavy);
    background: white;
    color: var(--text-main);
    cursor: pointer;
    transition: background .2s, border-color .2s, transform .2s;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 64px;
    box-shadow: 0 2px 4px rgba(0,0,0,.04);
    opacity: 0;
    animation: popIn .3s cubic-bezier(.175,.885,.32,1.275) forwards;
    overflow: hidden;
    min-width: 0;
}

@media (hover: hover) {
    .btn-option:hover {
        background: var(--primary-light);
        border-color: var(--primary);
        transform: translateY(-2px);
    }
}
.btn-option:active { transform: scale(.97); }
.btn-option:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.btn-option .katex-html {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
.btn-option .katex-html::-webkit-scrollbar { display: none; }

@keyframes shake {
    0%,100% { transform: translateX(0); }
    25%     { transform: translateX(-5px); }
    75%     { transform: translateX(5px); }
}
.btn-option.correct {
    background: var(--success) !important;
    border-color: var(--success) !important;
    color: white !important;
}
.btn-option.wrong {
    background: var(--danger-light) !important;
    border-color: var(--danger) !important;
    color: var(--danger) !important;
    opacity: 1 !important;
    pointer-events: none;
    cursor: not-allowed;
    animation: shake .3s;
}

/* ---- FEEDBACK ---- */
#missatge-feedback {
    font-size: .88rem;
    min-height: 36px;
    transition: opacity .3s;
    margin-top: 10px;
    text-align: center;
}
.feedback-correct { color: var(--success); font-weight: 700; }
.feedback-wrong   { color: var(--text-main); }

.solution-reveal {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    padding: 8px 12px;
    background: #f0fdf4;
    border: 2px solid #bbf7d0;
    border-radius: 8px;
}
.solution-label {
    color: #047857;
    font-size: .82em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
}
.solution-formula { color: #065f46; font-size: 1em; }

/* ---- GRÀFIC SVG ---- */
#graph-canvas {
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
#graph-canvas svg {
    display: block;
    width: 100% !important;
    height: 100% !important;
    border-radius: 6px;
}

.asymptote-toggle-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: #f8fafc;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    margin-bottom: 8px;
    flex-shrink: 0;
}
.asymptote-toggle-label {
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
    
}
.asymptote-toggle-btns {
    display: flex;
    gap: 4px;
}
.btn-asym {
    padding: 3px 14px;
    font-size: .78rem;
    font-family: 'Barlow', sans-serif;
    font-weight: 700;
    border-radius: 6px;
    border: 1.5px solid var(--border-heavy);
    background: white;
    color: var(--text-muted);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.btn-asym.active-on {
    background: var(--primary);
    border-color: var(--primary-dark);
    color: white;
}
.btn-asym.active-off {
    background: #f1f5f9;
    border-color: var(--border-heavy);
    color: var(--text-muted);
}

/* ---- RESUM FINAL ---- */
#session-summary { padding: 24px 20px 28px; overflow-y: auto; }
.summary-score { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 20px; }
.summary-score-label { font-size: .82em; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.summary-score-value { font-size: 2.2em; font-weight: 800; color: var(--primary-dark); }

.summary-stats { display: flex; justify-content: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.summary-stat { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 16px; border-radius: 10px; min-width: 90px; border: 2px solid transparent; }
.summary-stat--ok   { background: #f0fdf4; border-color: #bbf7d0; }
.summary-stat--warn { background: #fffbeb; border-color: #fde68a; }
.summary-stat--err  { background: #fef2f2; border-color: #fecaca; }
.summary-stat-num { font-size: 1.8em; font-weight: 800; line-height: 1; }
.summary-stat--ok   .summary-stat-num { color: #047857; }
.summary-stat--warn .summary-stat-num { color: #b45309; }
.summary-stat--err  .summary-stat-num { color: #b91c1c; }
.summary-stat-desc { font-size: .78em; text-align: center; color: var(--text-muted); line-height: 1.3; }

.summary-errors-title { font-size: .82em; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); font-weight: 700; margin-bottom: 10px; text-align: center; }
.summary-errors-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.summary-error-item { background: #eff6ff; border-left: 4px solid var(--primary); border-radius: 0 8px 8px 0; padding: 10px 14px; }
.summary-error-header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.summary-error-type  { font-weight: 700; font-size: .92em; color: var(--primary-dark); }
.summary-error-count { font-size: .78em; color: var(--primary); background: var(--primary-light); padding: 1px 8px; border-radius: 99px; white-space: nowrap; }
.summary-no-errors { text-align: center; color: #047857; font-weight: 600; background: #f0fdf4; border: 2px solid #bbf7d0; border-radius: 10px; padding: 14px; margin-bottom: 24px; }

.summary-continue-btn {
    display: block; margin: 0 auto; padding: 12px 36px;
    background: var(--primary); color: white; border: none; border-radius: 10px;
    font-family: 'Barlow', sans-serif; font-size: 1em; font-weight: 700; cursor: pointer;
    transition: background .2s, transform .15s;
}
.summary-continue-btn:hover  { background: var(--primary-hover); transform: translateY(-1px); }
.summary-continue-btn:active { transform: scale(.97); }

/* ---- RESPONSIVE ---- */
@media (max-width: 780px) {
    body { overflow: auto; }
    .game-body { flex-direction: column; }
    .game-left  { width: 100%; border-right: none; border-bottom: 1px solid var(--border-light); }
    .game-right { width: 100%; }
    #graph-container svg { height: 40vh; }
}
@media (max-width: 560px) {
    .options-grid { grid-template-columns: 1fr; }
}

/* ---- TOGGLE GRÀFICA ---- */
.btn-toggle-graph {
    display: block;
    width: calc(100% - 0px);
    padding: 10px 16px;
    margin-bottom: 10px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border: 2px dashed var(--primary);
    border-radius: 10px;
    font-family: 'Barlow', sans-serif;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, border-color .2s;
    text-align: center;
}
.btn-toggle-graph:hover:not(:disabled) {
    background: #bfdbfe;
    border-color: var(--primary-dark);
}
.btn-toggle-graph.revealed {
    background: #fef9c3;
    border: 2px solid #f59e0b;
    color: #92400e;
    cursor: default;
}
