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

:root {
    --blue: #3d5a96; --blue-dk: #2e4575; --blue-lt: #5a7ab8;
    --coral: #e8755c; --pink: #d05a7e; --vino: #691b31;
    --white: #ffffff; --gray: #f4f6fa; --text: #2d3a50; --text-lt: #6b7a92;
    --success: #28a745; --error: #dc3545; --warning: #ffc107;
    --radius: 12px; --header-h: 48px;
}

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

html, body { height: 100%; overflow: hidden; }

body {
    font-family: 'Nunito', 'Segoe UI', Tahoma, sans-serif;
    background: linear-gradient(135deg, #3d5a96 0%, #e8755c 50%, #d05a7e 100%);
    color: var(--text);
    display: flex; flex-direction: column;
}

/* ── HEADER ── */
.quiz-header {
    height: var(--header-h);
    min-height: var(--header-h);
    flex-shrink: 0;
    position: relative;
    z-index: 100;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.30);
    /* Layer 1: Three-color gradient background */
    background: linear-gradient(135deg, #3d5a96 0%, #e8755c 50%, #d05a7e 100%);
}

/* Layer 2: Overlapping rectangles */
.quiz-header::before {
    content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 1;
    background:
        linear-gradient(rgba(61,90,150,0.75), rgba(61,90,150,0.75)) 4%  0 / 3% 100% no-repeat,
        linear-gradient(rgba(232,117,92,0.70), rgba(232,117,92,0.70)) 11% 0 / 5% 65%  no-repeat,
        linear-gradient(rgba(208,90,126,0.75), rgba(208,90,126,0.75)) 18% 0 / 2% 100% no-repeat,
        linear-gradient(rgba(255,255,255,0.50), rgba(255,255,255,0.50)) 24% 0 / 4% 50%  no-repeat,
        linear-gradient(rgba(61,90,150,0.80), rgba(61,90,150,0.80)) 31% 0 / 2% 100% no-repeat,
        linear-gradient(rgba(232,117,92,0.70), rgba(232,117,92,0.70)) 37% 0 / 4% 80%  no-repeat,
        linear-gradient(rgba(208,90,126,0.75), rgba(208,90,126,0.75)) 43% 0 / 3% 55%  no-repeat,
        linear-gradient(rgba(255,255,255,0.45), rgba(255,255,255,0.45)) 49% 0 / 2% 100% no-repeat,
        linear-gradient(rgba(61,90,150,0.80), rgba(61,90,150,0.80)) 55% 0 / 4% 70%  no-repeat,
        linear-gradient(rgba(232,117,92,0.70), rgba(232,117,92,0.70)) 61% 0 / 2% 100% no-repeat,
        linear-gradient(rgba(208,90,126,0.75), rgba(208,90,126,0.75)) 67% 0 / 5% 60%  no-repeat,
        linear-gradient(rgba(255,255,255,0.50), rgba(255,255,255,0.50)) 74% 0 / 3% 100% no-repeat,
        linear-gradient(rgba(61,90,150,0.75), rgba(61,90,150,0.75)) 80% 0 / 2% 75%  no-repeat,
        linear-gradient(rgba(232,117,92,0.70), rgba(232,117,92,0.70)) 86% 0 / 4% 100% no-repeat,
        linear-gradient(rgba(208,90,126,0.75), rgba(208,90,126,0.75)) 92% 0 / 3% 50%  no-repeat,
        linear-gradient(rgba(255,255,255,0.45), rgba(255,255,255,0.45)) 97% 0 / 2% 100% no-repeat;
}

/* Layer 3: Overlapping triangles */
.quiz-header::after {
    content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 2;
    background:
        linear-gradient(135deg, rgba(61,90,150,0.55) 50%, transparent 50%) 7%  0 / 5% 100% no-repeat,
        linear-gradient(225deg, rgba(232,117,92,0.55) 50%, transparent 50%) 15% 0 / 4% 100% no-repeat,
        linear-gradient(135deg, rgba(208,90,126,0.55) 50%, transparent 50%) 22% 0 / 6% 100% no-repeat,
        linear-gradient(225deg, rgba(255,255,255,0.40) 50%, transparent 50%) 29% 0 / 3% 100% no-repeat,
        linear-gradient(135deg, rgba(61,90,150,0.55) 50%, transparent 50%) 35% 0 / 5% 100% no-repeat,
        linear-gradient(225deg, rgba(232,117,92,0.55) 50%, transparent 50%) 42% 0 / 4% 100% no-repeat,
        linear-gradient(135deg, rgba(208,90,126,0.55) 50%, transparent 50%) 49% 0 / 6% 100% no-repeat,
        linear-gradient(225deg, rgba(255,255,255,0.40) 50%, transparent 50%) 56% 0 / 3% 100% no-repeat,
        linear-gradient(135deg, rgba(61,90,150,0.55) 50%, transparent 50%) 62% 0 / 5% 100% no-repeat,
        linear-gradient(225deg, rgba(232,117,92,0.55) 50%, transparent 50%) 69% 0 / 4% 100% no-repeat,
        linear-gradient(135deg, rgba(208,90,126,0.55) 50%, transparent 50%) 76% 0 / 6% 100% no-repeat,
        linear-gradient(225deg, rgba(255,255,255,0.40) 50%, transparent 50%) 83% 0 / 3% 100% no-repeat,
        linear-gradient(135deg, rgba(61,90,150,0.55) 50%, transparent 50%) 89% 0 / 5% 100% no-repeat,
        linear-gradient(225deg, rgba(232,117,92,0.55) 50%, transparent 50%) 95% 0 / 4% 100% no-repeat;
}

.header-brand, .header-right { position: relative; z-index: 3; }
.header-brand { display: flex; align-items: center; gap: 10px; }
.bot-avatar {
    width: 30px; height: 30px; border-radius: 10px;
    background: linear-gradient(135deg, var(--coral), var(--pink));
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(208,90,126,0.4);
}
.header-title strong { font-size: 13px; font-weight: 800; color: var(--white); display: block; line-height: 1.1; }
.header-title span { font-size: 10px; color: rgba(255,255,255,0.65); font-weight: 500; }

.header-right { display: flex; align-items: center; gap: 12px; }
.score-pill {
    display: flex; align-items: center; gap: 4px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 16px; padding: 4px 12px;
    font-size: 13px; font-weight: 700; color: #fff;
}
.score-pill .star { color: var(--warning); font-size: 14px; }

/* ── MAIN LAYOUT ── */
.main-wrap {
    flex: 1; display: flex; gap: 3px; padding: 3px;
    min-height: 0; overflow: hidden;
}

/* ── LEFT: CROSSWORD ── */
.crossword-panel {
    flex: 0 0 50%; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: rgba(255,255,255,0.93);
    border-radius: var(--radius); padding: 6px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.10);
    overflow: hidden;
}
.crossword-title {
    font-size: 11px; font-weight: 700; color: var(--blue);
    margin-bottom: 4px; flex-shrink: 0;
}
.grid-wrap {
    flex: 1; display: flex; align-items: center; justify-content: center;
    width: 100%; min-height: 0;
}
.grid-wrap canvas {
    max-width: 100%; max-height: 100%;
    display: block;
}

/* ── RIGHT: QUESTIONS ── */
.questions-panel {
    flex: 0 0 50%; display: flex; flex-direction: column;
    background: rgba(255,255,255,0.93);
    border-radius: var(--radius); padding: 6px 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.10);
    overflow: hidden;
}
.questions-header {
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0; margin-bottom: 4px;
}
.questions-header h2 {
    font-size: 12px; font-weight: 800; color: var(--blue);
}
.questions-score {
    font-size: 12px; font-weight: 700; color: var(--vino);
    background: rgba(208,90,126,0.08); padding: 2px 10px;
    border-radius: 12px;
}
.questions-scroll {
    flex: 1; overflow-y: auto; min-height: 0;
    padding-right: 4px;
}
.questions-scroll::-webkit-scrollbar { width: 4px; }
.questions-scroll::-webkit-scrollbar-thumb { background: var(--blue); border-radius: 4px; }
.questions-scroll::-webkit-scrollbar-track { background: #e0e0e0; border-radius: 4px; }

.question-item {
    display: flex; align-items: center; gap: 6px;
    padding: 3px 6px; margin-bottom: 2px;
    border-radius: 6px; font-size: 10.5px; line-height: 1.3;
    background: var(--white); border: 1px solid #e8eaef;
    transition: border-color 0.15s, background 0.15s;
}
.question-item.correct {
    background: rgba(40,167,69,0.07);
    border-color: var(--success);
}
.question-item.wrong {
    background: rgba(220,53,69,0.06);
    border-color: var(--error);
    animation: shake 0.3s ease;
}
.question-number {
    width: 18px; height: 18px; min-width: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--blue), var(--blue-lt));
    color: var(--white); display: flex; align-items: center;
    justify-content: center; font-size: 9px; font-weight: 800;
    flex-shrink: 0;
}
.question-item.correct .question-number { background: var(--success); }
.question-text { flex: 1; min-width: 0; color: var(--text); }
.question-input {
    width: 75px; min-width: 60px; flex-shrink: 0;
    padding: 2px 6px; border: 1.5px solid #ccc;
    border-radius: 6px; font-family: inherit; font-size: 10px;
    font-weight: 600; text-transform: uppercase;
    outline: none; transition: border-color 0.15s;
    letter-spacing: 1px;
}
.question-input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(61,90,150,0.15); }
.question-item.correct .question-input {
    border-color: var(--success); background: rgba(40,167,69,0.05);
    color: var(--success); font-weight: 800;
}
.question-item.wrong .question-input {
    border-color: var(--error); background: rgba(220,53,69,0.05);
}
.question-check {
    width: 16px; flex-shrink: 0; text-align: center;
    font-size: 13px; font-weight: 800;
}

/* ── BUTTONS ── */
.btn-bar {
    display: flex; gap: 6px; justify-content: center;
    flex-shrink: 0; padding: 4px 0 0;
}
.btn {
    padding: 6px 18px; border: none; border-radius: 20px;
    font-family: inherit; font-size: 11px; font-weight: 700;
    cursor: pointer; transition: transform 0.12s, box-shadow 0.12s;
}
.btn:hover { transform: scale(1.04); }
.btn:active { transform: scale(0.96); }
.btn-primary {
    background: linear-gradient(135deg, var(--pink), var(--coral));
    color: var(--white); box-shadow: 0 3px 10px rgba(208,90,126,0.35);
}
.btn-secondary {
    background: var(--white); color: var(--blue);
    border: 2px solid var(--blue);
}
.btn-secondary:hover { background: var(--blue); color: var(--white); }

/* ── WELCOME ── */
.welcome-card {
    max-width: 500px; width: 100%; background: rgba(255,255,255,0.95);
    border-radius: var(--radius); padding: 20px; text-align: center;
    box-shadow: 0 6px 24px rgba(0,0,0,0.16);
    margin: auto; animation: fadeUp 0.35s ease;
}
.welcome-icon { font-size: 36px; margin-bottom: 4px; display: block; }
.welcome-card h1 { color: var(--blue); font-size: 18px; font-weight: 800; margin-bottom: 2px; }
.welcome-card .subtitle { color: var(--vino); font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.welcome-card p { color: var(--text-lt); font-size: 12px; line-height: 1.5; margin-bottom: 6px; }
.welcome-card .rules { text-align: left; background: var(--gray); border-radius: 10px; padding: 8px 14px; margin: 6px 0 10px; }
.welcome-card .rules li { list-style: none; padding: 3px 0; font-size: 11.5px; color: var(--text); display: flex; align-items: center; gap: 6px; }
.welcome-card .rules li::before { content: ''; width: 5px; height: 5px; flex-shrink: 0; border-radius: 50%; background: var(--coral); }

/* ── RESULTS ── */
.results-card {
    max-width: 480px; width: 100%; background: rgba(255,255,255,0.97);
    border-radius: var(--radius); padding: 20px; text-align: center;
    box-shadow: 0 6px 24px rgba(0,0,0,0.16);
    margin: auto; animation: fadeUp 0.35s ease;
}
.results-card .big-icon { font-size: 42px; display: block; margin-bottom: 4px; }
.results-card h2 { color: var(--blue); font-size: 20px; font-weight: 800; margin-bottom: 2px; }
.results-card .results-sub { color: var(--vino); font-size: 12px; font-weight: 600; margin-bottom: 10px; }
.score-display { display: flex; justify-content: center; gap: 16px; margin: 6px 0 8px; }
.score-item { text-align: center; }
.score-item .num { font-size: 24px; font-weight: 800; display: block; }
.score-item .num.green { color: var(--success); }
.score-item .num.red { color: var(--error); }
.score-item .num.blue { color: var(--blue); }
.score-item .label { font-size: 10px; color: var(--text-lt); font-weight: 600; }
.stars-row { font-size: 20px; margin: 4px 0 8px; letter-spacing: 2px; }
.stars-row .star-filled { color: var(--warning); }
.stars-row .star-empty { color: #ddd; }
.results-message { background: var(--gray); border-radius: 10px; padding: 10px 14px; margin: 6px 0 10px; font-size: 12px; line-height: 1.5; color: var(--text); }
.results-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shake {
    0%,100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}
