/* ===== CSS Variables & Reset ===== */
:root {
    --red: #DA251D;
    --red-dark: #a81b15;
    --gold: #FFCD00;
    --gold-light: #ffe566;
    --gold-dim: #b8941a;
    --bg-dark: #0d0f1a;
    --bg-card: rgba(255,255,255,0.04);
    --bg-card-hover: rgba(255,255,255,0.08);
    --text: #f0e6d3;
    --text-dim: #a09888;
    --cell-bg: rgba(255,205,0,0.08);
    --cell-border: rgba(255,205,0,0.25);
    --cell-key-bg: rgba(218,37,29,0.15);
    --cell-key-border: rgba(218,37,29,0.6);
    --cell-filled: rgba(255,205,0,0.18);
    --cell-correct: #2ecc71;
    --cell-wrong: #e74c3c;
    --font: 'Be Vietnam Pro', sans-serif;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.3s cubic-bezier(0.4,0,0.2,1);
    --glow-gold: 0 0 20px rgba(255,205,0,0.15);
    --glow-red: 0 0 20px rgba(218,37,29,0.2);
}

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

body {
    font-family: var(--font);
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(218,37,29,0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(255,205,0,0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 50% 50%, rgba(218,37,29,0.03) 0%, transparent 80%);
    pointer-events: none;
    z-index: 0;
}

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

/* ===== Decorative Stars ===== */
.star-decoration {
    position: fixed;
    color: var(--gold);
    opacity: 0.06;
    font-size: 120px;
    pointer-events: none;
    z-index: 0;
    animation: starFloat 8s ease-in-out infinite;
}
.star-1 { top: 10%; left: 5%; animation-delay: 0s; }
.star-2 { top: 60%; right: 3%; font-size: 80px; animation-delay: 2s; }
.star-3 { bottom: 10%; left: 15%; font-size: 60px; animation-delay: 4s; }

@keyframes starFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-15px) rotate(10deg); }
}

/* ===== Header ===== */
header {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 48px 24px 32px;
    background: linear-gradient(180deg, rgba(218,37,29,0.1) 0%, transparent 100%);
    border-bottom: 1px solid rgba(255,205,0,0.08);
}

.header-badge {
    display: inline-block;
    padding: 6px 20px;
    background: rgba(255,205,0,0.1);
    border: 1px solid rgba(255,205,0,0.2);
    border-radius: 50px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gold);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 16px;
}

h1 {
    font-size: clamp(28px, 5vw, 48px);
    font-weight: 900;
    line-height: 1.2;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--text) 0%, var(--gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

h1 .highlight {
    background: linear-gradient(135deg, var(--gold) 0%, var(--red) 100%);
    -webkit-background-clip: text;
    background-clip: text;
}

.subtitle {
    font-size: clamp(14px, 2vw, 17px);
    color: var(--text-dim);
    max-width: 600px;
    margin: 0 auto 24px;
    line-height: 1.6;
}

/* ===== Progress Bar ===== */
.progress-bar-container {
    position: relative;
    max-width: 400px;
    margin: 0 auto;
    height: 8px;
    background: rgba(255,255,255,0.06);
    border-radius: 50px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--red), var(--gold));
    border-radius: 50px;
    transition: width 0.6s cubic-bezier(0.34,1.56,0.64,1);
}

.progress-text {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 500;
}

/* ===== Main Layout ===== */
main {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.section-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--gold);
}

/* ===== Crossword Grid ===== */
.grid-section {
    display: flex;
    justify-content: center;
}

.crossword-wrapper {
    overflow-x: auto;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid rgba(255,205,0,0.08);
    border-radius: var(--radius);
    backdrop-filter: blur(10px);
    box-shadow: var(--glow-gold);
}

.crossword-grid {
    display: grid;
    gap: 4px;
    width: fit-content;
    margin: 0 auto;
}

.grid-row {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 48px;
}

.row-label {
    width: 32px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--gold);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    flex-shrink: 0;
}

.row-label:hover {
    background: rgba(255,205,0,0.1);
    transform: scale(1.1);
}

.row-label.active {
    background: rgba(255,205,0,0.2);
    color: var(--gold-light);
    box-shadow: 0 0 12px rgba(255,205,0,0.2);
}

.cell {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    text-transform: uppercase;
    user-select: none;
}

.cell-empty {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.cell-normal {
    background: var(--cell-bg);
    border: 2px solid var(--cell-border);
    color: var(--text);
}

.cell-key {
    background: var(--cell-key-bg);
    border: 2px solid var(--cell-key-border);
    color: var(--gold);
    box-shadow: var(--glow-red);
}

.cell-filled {
    background: var(--cell-filled);
    border-color: var(--gold-dim);
    animation: cellFill 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

.cell-key.cell-filled {
    background: rgba(218,37,29,0.25);
    border-color: var(--red);
    color: var(--gold-light);
    box-shadow: 0 0 15px rgba(218,37,29,0.3);
}

.cell-highlight {
    border-color: var(--gold-light) !important;
    box-shadow: 0 0 12px rgba(255,205,0,0.3);
    transform: scale(1.02);
}

@keyframes cellFill {
    0% { transform: scale(0.5) rotateY(90deg); opacity: 0; }
    50% { transform: scale(1.15) rotateY(0deg); }
    100% { transform: scale(1) rotateY(0deg); opacity: 1; }
}

@keyframes cellCorrect {
    0% { background: var(--cell-correct); transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes cellWrong {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); background: var(--cell-wrong); }
    40%, 80% { transform: translateX(6px); background: var(--cell-wrong); }
}

/* ===== Row Label Solved ===== */
.row-label.solved {
    background: rgba(46,204,113,0.2);
    color: var(--cell-correct);
    cursor: default;
    font-size: 16px;
}

.row-label.solved:hover {
    transform: none;
    background: rgba(46,204,113,0.2);
}

/* ===== Answer Panel Question Display ===== */
.q-badge {
    display: inline-block;
    padding: 4px 14px;
    background: linear-gradient(135deg, var(--red), var(--red-dark));
    color: white;
    border-radius: 50px;
    font-size: 13px;
    font-weight: 700;
    margin-right: 8px;
}

.q-length {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(255,205,0,0.12);
    color: var(--gold);
    border-radius: 50px;
    font-size: 12px;
    font-weight: 600;
}

.q-content {
    display: inline-block;
    margin-top: 8px;
    font-size: 16px;
    line-height: 1.7;
    color: var(--text);
}

@keyframes fadeSlideIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.panel-active {
    border-color: rgba(255,205,0,0.3) !important;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.4), 0 0 20px rgba(255,205,0,0.08);
}

/* ===== Answer Section ===== */
.answer-section {
    position: sticky;
    bottom: 20px;
    z-index: 10;
}

.answer-panel {
    background: rgba(13,15,26,0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,205,0,0.15);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.4);
}

.selected-question {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.selected-question .hint-icon {
    margin-right: 8px;
}

.input-group {
    display: flex;
    gap: 10px;
}

#answer-input {
    flex: 1;
    padding: 14px 18px;
    background: rgba(255,255,255,0.06);
    border: 2px solid rgba(255,205,0,0.2);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    outline: none;
    transition: var(--transition);
}

#answer-input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 20px rgba(255,205,0,0.15);
}

#answer-input::placeholder {
    color: var(--text-dim);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}

.btn-check {
    padding: 14px 28px;
    background: linear-gradient(135deg, var(--red), var(--red-dark));
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-check:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(218,37,29,0.4);
}

.btn-check:active {
    transform: translateY(0);
}

.feedback {
    margin-top: 10px;
    font-size: 14px;
    font-weight: 600;
    min-height: 24px;
    transition: var(--transition);
}

.feedback.correct { color: var(--cell-correct); }
.feedback.wrong { color: var(--cell-wrong); }
.feedback.hint-feedback { color: var(--gold); }

/* ===== Hint Buttons ===== */
.hint-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.btn-hint-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: rgba(255,205,0,0.08);
    border: 1px solid rgba(255,205,0,0.25);
    color: var(--gold);
    border-radius: 50px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-hint-row:hover {
    background: rgba(255,205,0,0.15);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255,205,0,0.15);
}

.btn-hint-text {
    background: rgba(218,37,29,0.08);
    border-color: rgba(218,37,29,0.3);
    color: #ff9b8e;
}

.btn-hint-text:hover {
    background: rgba(218,37,29,0.15);
    box-shadow: 0 4px 15px rgba(218,37,29,0.15);
}

.hint-pulse {
    animation: hintPulse 1s ease-in-out 3;
}

@keyframes hintPulse {
    0%, 100% { transform: scale(1); box-shadow: none; }
    50% { transform: scale(1.05); box-shadow: 0 0 18px rgba(255,205,0,0.3); }
}

/* ===== Hint Text Display ===== */
.hint-text-display {
    margin-top: 10px;
    padding: 12px 16px;
    background: rgba(255,205,0,0.06);
    border-left: 3px solid var(--gold);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 14px;
    line-height: 1.6;
    color: var(--gold-light);
    font-style: italic;
}

/* ===== Hint Revealed Cells ===== */
.cell-hint-revealed {
    background: rgba(255,205,0,0.12) !important;
    border-color: rgba(255,205,0,0.4) !important;
    color: var(--gold-light) !important;
    font-size: 18px;
}

@keyframes hintReveal {
    0% { transform: scale(0.6); opacity: 0.3; }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== Keyword Section ===== */
.keyword-section {
    position: relative;
    z-index: 1;
    text-align: center;
    max-width: 600px;
    margin: 0 auto 40px;
    padding: 32px 20px;
    background: var(--bg-card);
    border: 1px solid rgba(255,205,0,0.1);
    border-radius: var(--radius);
    backdrop-filter: blur(10px);
}

.keyword-cells {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.kw-cell {
    width: 48px;
    height: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--cell-key-bg);
    border: 2px solid var(--cell-key-border);
    border-radius: var(--radius-sm);
    font-size: 24px;
    font-weight: 800;
    color: var(--gold);
    transition: var(--transition);
}

.kw-cell.revealed {
    background: rgba(218,37,29,0.25);
    border-color: var(--red);
    box-shadow: 0 0 15px rgba(218,37,29,0.3);
    animation: cellFill 0.5s cubic-bezier(0.34,1.56,0.64,1);
}

.kw-cell-index {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 500;
}

.keyword-hint {
    color: var(--text-dim);
    font-size: 14px;
    font-style: italic;
}

.btn-hint {
    margin-top: 12px;
    padding: 10px 24px;
    background: rgba(255,205,0,0.1);
    border: 1px solid rgba(255,205,0,0.25);
    color: var(--gold);
    border-radius: 50px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-hint:hover {
    background: rgba(255,205,0,0.2);
    transform: translateY(-2px);
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: linear-gradient(135deg, #1a1020 0%, #0d0f1a 100%);
    border: 2px solid var(--gold);
    border-radius: 20px;
    padding: 48px 40px;
    max-width: 520px;
    width: 90%;
    text-align: center;
    transform: scale(0.8);
    transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1);
    box-shadow: 0 0 60px rgba(255,205,0,0.2);
}

.modal-overlay.show .modal-content {
    transform: scale(1);
}

.modal-star {
    font-size: 60px;
    margin-bottom: 12px;
    animation: starPulse 1.5s ease-in-out infinite;
}

@keyframes starPulse {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.2) rotate(10deg); }
}

.modal-content h2 {
    font-size: 32px;
    color: var(--gold);
    margin-bottom: 12px;
}

.modal-content p {
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 16px;
}

.keyword-reveal {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 24px 0;
    flex-wrap: wrap;
}

.keyword-reveal .kw-letter {
    width: 48px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--red), var(--red-dark));
    border: 2px solid var(--gold);
    border-radius: var(--radius-sm);
    font-size: 26px;
    font-weight: 900;
    color: var(--gold);
    animation: letterBounce 0.5s cubic-bezier(0.34,1.56,0.64,1) backwards;
}

@keyframes letterBounce {
    0% { transform: scale(0) rotateY(180deg); opacity: 0; }
    100% { transform: scale(1) rotateY(0deg); opacity: 1; }
}

.keyword-meaning {
    font-style: italic;
    color: var(--text) !important;
    font-size: 15px !important;
}

.btn-close-modal {
    margin-top: 20px;
    padding: 12px 36px;
    background: linear-gradient(135deg, var(--gold), var(--gold-dim));
    color: #0d0f1a;
    border: none;
    border-radius: 50px;
    font-family: var(--font);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}

.btn-close-modal:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(255,205,0,0.4);
}

/* ===== Footer ===== */
footer {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 32px 20px;
    border-top: 1px solid rgba(255,255,255,0.05);
    color: var(--text-dim);
    font-size: 13px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    header { padding: 32px 16px 24px; }
    main { padding: 24px 12px; gap: 24px; }
    .cell, .cell-empty { width: 38px; height: 38px; font-size: 16px; }
    .row-label { width: 28px; height: 38px; font-size: 12px; }
    .kw-cell { width: 38px; height: 46px; font-size: 20px; }
    .crossword-wrapper { padding: 12px; }
    .answer-panel { padding: 16px; }
    .input-group { flex-direction: column; }
    .btn-check { justify-content: center; }
    .modal-content { padding: 32px 24px; }
}

@media (max-width: 480px) {
    .cell, .cell-empty { width: 32px; height: 32px; font-size: 14px; }
    .row-label { width: 24px; height: 32px; font-size: 11px; }
    .grid-row { gap: 2px; }
    .crossword-grid { gap: 2px; }
}
