/* =============================================================
   Mattemagi – Style
   Trollkarls-tema: mörkblå/lila med guldaccenter
   Skolplus AB
   ============================================================= */

/* ---------- Reset & variabler ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-deep:      #0a0a2e;
    --bg-mid:       #12123e;
    --bg-card:      #1a1a4e;
    --purple:       #6a2fdb;
    --purple-light: #9a5ffe;
    --gold:         #f5c518;
    --gold-dark:    #c9980c;
    --teal:         #00d4aa;
    --red:          #ff4d6d;
    --white:        #ffffff;
    --gray:         #a0a0c8;
    --text:         #e8e8ff;

    --shadow:       0 4px 20px rgba(106,47,219,.4);
    --glow-gold:    0 0 20px rgba(245,197,24,.6);
    --glow-purple:  0 0 20px rgba(154,95,254,.5);

    --radius:       16px;
    --radius-sm:    8px;
    --transition:   .25s ease;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-deep); }
::-webkit-scrollbar-thumb { background: var(--purple); border-radius: 3px; }

/* ---------- Bakgrund ---------- */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-deep);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

#stars-canvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

/* ---------- Layout ---------- */
#game-wrapper {
    position: relative;
    z-index: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 20px 16px 60px;
}

/* ---------- Header ---------- */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: rgba(26,26,78,.8);
    border: 1px solid rgba(154,95,254,.3);
    border-radius: var(--radius);
    margin-bottom: 20px;
    backdrop-filter: blur(10px);
    flex-wrap: wrap;
    gap: 10px;
}

.game-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gold);
    text-shadow: var(--glow-gold);
}

.header-stats {
    display: flex;
    gap: 18px;
    align-items: center;
}

.stat-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(106,47,219,.25);
    border: 1px solid rgba(154,95,254,.4);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: .85rem;
    font-weight: 600;
}
.stat-pill .icon { font-size: 1rem; }
.stat-pill .value { color: var(--gold); }

/* ---------- Trollkarls-karaktär ---------- */
.wizard-container {
    text-align: center;
    margin: 10px 0 20px;
    position: relative;
}

#wizard-svg {
    width: 120px;
    height: 120px;
    filter: drop-shadow(0 0 16px rgba(154,95,254,.8));
    animation: wizard-float 3s ease-in-out infinite;
}

@keyframes wizard-float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-10px); }
}

.wizard-speech {
    display: inline-block;
    background: rgba(26,26,78,.9);
    border: 1.5px solid var(--purple-light);
    border-radius: 12px;
    padding: 10px 20px;
    font-size: .95rem;
    color: var(--text);
    margin-top: 8px;
    max-width: 380px;
    line-height: 1.4;
    position: relative;
}
.wizard-speech::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: var(--purple-light);
}

/* ---------- Kristall-progress ---------- */
.crystal-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.crystal-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: transform var(--transition);
}
.crystal-item.earned { transform: scale(1.15); }
.crystal-item svg { width: 36px; height: 36px; }
.crystal-item span {
    font-size: .65rem;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: .5px;
}
.crystal-item.earned span { color: var(--gold); }

/* ---------- Operation-väljare ---------- */
.op-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

@media (min-width: 540px) {
    .op-selector { grid-template-columns: repeat(4, 1fr); }
}

.op-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 10px;
    background: var(--bg-card);
    border: 2px solid rgba(154,95,254,.3);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text);
    font-size: .9rem;
    font-weight: 600;
}
.op-btn .symbol {
    font-size: 2rem;
    line-height: 1;
}
.op-btn .level-badge {
    font-size: .7rem;
    background: rgba(106,47,219,.4);
    border-radius: 10px;
    padding: 2px 8px;
    color: var(--purple-light);
}
.op-btn:hover,
.op-btn.active {
    border-color: var(--gold);
    background: rgba(245,197,24,.1);
    box-shadow: var(--glow-gold);
    transform: translateY(-3px);
}

/* ---------- Spel-arena ---------- */
#game-arena { display: none; }
#game-arena.visible { display: block; }

/* Progress-bar för fråga */
.question-progress {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: .85rem;
    color: var(--gray);
}
.q-progress-bar {
    flex: 1;
    height: 6px;
    background: rgba(154,95,254,.2);
    border-radius: 3px;
    margin: 0 12px;
    overflow: hidden;
}
.q-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--purple), var(--gold));
    border-radius: 3px;
    transition: width .4s ease;
}

/* Fråge-kort */
.question-card {
    background: rgba(26,26,78,.85);
    border: 1.5px solid rgba(154,95,254,.4);
    border-radius: var(--radius);
    padding: 28px 24px;
    text-align: center;
    margin-bottom: 16px;
    backdrop-filter: blur(6px);
    position: relative;
    overflow: hidden;
}
.question-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at top, rgba(154,95,254,.08), transparent 70%);
    pointer-events: none;
}

.question-text {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--white);
    margin-bottom: 8px;
    line-height: 1.3;
}
.question-sub {
    font-size: .8rem;
    color: var(--gray);
    margin-bottom: 12px;
}

/* Timer-ring */
.timer-ring-wrap {
    display: flex;
    justify-content: center;
    margin: 12px 0;
}
#timer-ring { transition: stroke-dashoffset .9s linear; }
.timer-text {
    font-size: 1rem;
    font-weight: 700;
    fill: var(--white);
}

/* Svarsalternativ */
.answer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 16px;
}

.answer-btn {
    padding: 18px 10px;
    font-size: 1.3rem;
    font-weight: 700;
    background: var(--bg-card);
    border: 2px solid rgba(154,95,254,.4);
    border-radius: var(--radius);
    color: var(--white);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}
.answer-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,.04), transparent);
}
.answer-btn:hover:not(:disabled) {
    border-color: var(--gold);
    background: rgba(245,197,24,.08);
    transform: translateY(-2px);
    box-shadow: var(--glow-gold);
}
.answer-btn.correct {
    border-color: var(--teal);
    background: rgba(0,212,170,.15);
    box-shadow: 0 0 20px rgba(0,212,170,.5);
    animation: pulse-correct .5s ease;
}
.answer-btn.wrong {
    border-color: var(--red);
    background: rgba(255,77,109,.15);
    box-shadow: 0 0 20px rgba(255,77,109,.4);
    animation: shake .4s ease;
}
.answer-btn:disabled { cursor: default; }

@keyframes pulse-correct {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.05); }
    100% { transform: scale(1); }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

/* ---------- Feedback-rad ---------- */
.feedback-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-radius: var(--radius);
    margin-top: 14px;
    font-weight: 600;
    opacity: 0;
    transition: opacity .3s ease;
    min-height: 52px;
}
.feedback-bar.visible { opacity: 1; }
.feedback-bar.correct {
    background: rgba(0,212,170,.12);
    border: 1.5px solid var(--teal);
    color: var(--teal);
}
.feedback-bar.wrong {
    background: rgba(255,77,109,.12);
    border: 1.5px solid var(--red);
    color: var(--red);
}
.feedback-bar .fb-text { flex: 1; }
.feedback-bar .fb-score {
    font-size: 1.1rem;
    color: var(--gold);
    text-shadow: var(--glow-gold);
    margin-left: 16px;
}

/* ---------- Streak-display ---------- */
.streak-display {
    text-align: center;
    font-size: .9rem;
    font-weight: 700;
    color: var(--gold);
    min-height: 28px;
    transition: all var(--transition);
}
.streak-display.fire { animation: streak-pop .4s ease; }
@keyframes streak-pop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.4); }
    100% { transform: scale(1); }
}

/* ---------- Hint-knapp ---------- */
.hint-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid rgba(154,95,254,.4);
    border-radius: 20px;
    padding: 4px 14px;
    color: var(--purple-light);
    font-size: .8rem;
    cursor: pointer;
    transition: all var(--transition);
    margin-top: 10px;
}
.hint-btn:hover { border-color: var(--purple-light); background: rgba(154,95,254,.1); }

.hint-box {
    display: none;
    background: rgba(106,47,219,.15);
    border: 1px dashed var(--purple-light);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: .85rem;
    color: var(--gray);
    margin-top: 8px;
    text-align: left;
}
.hint-box.visible { display: block; }

/* ---------- Score-display ---------- */
.score-display {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin: 10px 0;
    flex-wrap: wrap;
}
.score-item {
    text-align: center;
}
.score-item .label {
    font-size: .7rem;
    color: var(--gray);
    text-transform: uppercase;
    letter-spacing: .5px;
}
.score-item .val {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--gold);
    display: block;
    text-shadow: var(--glow-gold);
}

/* ---------- Modal bas ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5,5,20,.88);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(6px);
    animation: fadeIn .3s ease;
}
.modal-overlay.hidden { display: none; }

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal {
    background: var(--bg-card);
    border: 2px solid rgba(154,95,254,.5);
    border-radius: var(--radius);
    padding: 36px 28px;
    max-width: 520px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.6), var(--glow-purple);
    animation: slideUp .35s ease;
    max-height: 90vh;
    overflow-y: auto;
}
@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.modal h1 { font-size: 2rem; color: var(--gold); margin-bottom: 8px; }
.modal h2 { font-size: 1.5rem; color: var(--gold); margin-bottom: 8px; text-shadow: var(--glow-gold); }
.modal p  { color: var(--gray); font-size: .95rem; line-height: 1.5; margin-bottom: 14px; }

/* ---------- Start-modal ---------- */
.features-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 18px 0;
    text-align: left;
}
.feature-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(106,47,219,.15);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: .85rem;
}
.feature-item .fi-icon { font-size: 1.2rem; }

/* ---------- Resultat-modal ---------- */
.result-score-big {
    font-size: 3.5rem;
    font-weight: 900;
    color: var(--gold);
    text-shadow: var(--glow-gold);
    line-height: 1;
    margin: 10px 0;
}
.result-meta {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin: 14px 0;
}
.result-meta-item { text-align: center; }
.result-meta-item .rmi-val {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--purple-light);
    display: block;
}
.result-meta-item .rmi-label {
    font-size: .7rem;
    color: var(--gray);
    text-transform: uppercase;
}

/* Weakspot-sektion */
.weakspot-section {
    background: rgba(255,77,109,.08);
    border: 1px solid rgba(255,77,109,.3);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin: 14px 0;
    text-align: left;
}
.weakspot-section h3 {
    font-size: .9rem;
    color: var(--red);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.weakspot-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: .85rem;
}
.weakspot-item .ws-cat { flex: 1; color: var(--text); }
.weakspot-item .ws-bar-wrap {
    width: 90px;
    height: 8px;
    background: rgba(255,255,255,.1);
    border-radius: 4px;
    overflow: hidden;
}
.weakspot-item .ws-bar {
    height: 100%;
    background: var(--red);
    border-radius: 4px;
    transition: width .6s ease;
}
.weakspot-item .ws-pct {
    width: 36px;
    text-align: right;
    color: var(--red);
    font-weight: 600;
}

/* ---------- Knappar ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 32px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.btn-primary {
    background: linear-gradient(135deg, var(--purple), var(--purple-light));
    color: var(--white);
    box-shadow: var(--shadow);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow), var(--glow-purple);
}
.btn-gold {
    background: linear-gradient(135deg, var(--gold-dark), var(--gold));
    color: #1a1a00;
}
.btn-gold:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow-gold);
}
.btn-ghost {
    background: transparent;
    border: 1.5px solid rgba(154,95,254,.4);
    color: var(--purple-light);
}
.btn-ghost:hover { border-color: var(--purple-light); background: rgba(154,95,254,.1); }
.btn-sm { padding: 8px 18px; font-size: .85rem; }

.btn-group {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 18px;
}

/* ---------- Level-indikator ---------- */
.level-indicator {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 8px 0;
}
.level-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(154,95,254,.25);
    border: 1.5px solid rgba(154,95,254,.4);
    transition: all var(--transition);
}
.level-dot.active {
    background: var(--gold);
    border-color: var(--gold);
    box-shadow: var(--glow-gold);
}

/* ---------- Kombostjärna ---------- */
.combo-badge {
    display: inline-block;
    background: linear-gradient(135deg, #ff8c00, #ff4500);
    color: white;
    font-weight: 900;
    font-size: .8rem;
    border-radius: 6px;
    padding: 2px 8px;
    margin-left: 6px;
    animation: combo-pulse 1s infinite;
}
@keyframes combo-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .7; }
}

/* ---------- Partiklar (kristaller) ---------- */
.particle {
    position: fixed;
    pointer-events: none;
    z-index: 200;
    font-size: 1.5rem;
    animation: particle-fly 1.2s ease-out forwards;
}
@keyframes particle-fly {
    0%   { transform: translateY(0) scale(1);    opacity: 1; }
    100% { transform: translateY(-120px) scale(0); opacity: 0; }
}

/* ---------- Adaptiv nivå-toast ---------- */
.level-toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-80px);
    background: linear-gradient(135deg, var(--purple), var(--purple-light));
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 700;
    font-size: .95rem;
    z-index: 300;
    transition: transform .4s cubic-bezier(.34,1.56,.64,1);
    box-shadow: var(--shadow);
    white-space: nowrap;
}
.level-toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- Utilities ---------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

/* ---------- Responsivt ---------- */
@media (max-width: 480px) {
    .question-text { font-size: 1.4rem; }
    .answer-btn { padding: 14px 8px; font-size: 1.1rem; }
    .modal { padding: 24px 18px; }
    .modal h1 { font-size: 1.6rem; }
    .result-score-big { font-size: 2.8rem; }
    .features-grid { grid-template-columns: 1fr; }
    .game-header { flex-direction: column; align-items: flex-start; }
}
