:root {
    --indigo: #6366f1;
    --indigo-dark: #4f46e5;
    --violet: #8b5cf6;
    --pink: #ec4899;
    --rose: #f43f5e;
    --emerald: #10b981;
    --emerald-dark: #059669;
    --amber: #f59e0b;

    --bg: #fafafa;
    --bg-card: #ffffff;
    --bg-soft: #f4f4f5;
    --bg-soft-2: #e4e4e7;

    --text: #18181b;
    --text-muted: #71717a;
    --text-soft: #a1a1aa;

    --border: #e4e4e7;
    --border-strong: #d4d4d8;

    --header-h: 72px;
    --footer-h: 100px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 4px 16px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.10), 0 4px 12px rgba(0,0,0,0.06);
    --shadow-glow: 0 8px 32px rgba(99,102,241,0.18);

    --radius: 12px;
    --radius-lg: 18px;
    --radius-pill: 999px;

    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    --gradient-soft: linear-gradient(135deg, #eef2ff 0%, #faf5ff 50%, #fdf2f8 100%);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    padding-top: var(--header-h);
    padding-bottom: var(--footer-h);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

.bg-aura {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(ellipse 60% 50% at 20% 0%, rgba(99,102,241,0.10), transparent 60%),
        radial-gradient(ellipse 50% 40% at 80% 10%, rgba(236,72,153,0.08), transparent 60%),
        radial-gradient(ellipse 80% 60% at 50% 100%, rgba(139,92,246,0.06), transparent 60%);
    pointer-events: none;
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

/* ===== Header ===== */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: rgba(255,255,255,0.75);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid rgba(228,228,231,0.6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--gradient-primary);
    color: white;
    font-size: 14px;
    font-weight: 700;
    box-shadow: var(--shadow-glow);
}
.app-title {
    margin: 0;
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}
.app-title .bang {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-left: 2px;
}

.status {
    display: flex;
    align-items: center;
    gap: 12px;
}
.best-score, .score-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}
.best-score {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-color: #fcd34d;
    color: #92400e;
}
.best-score-icon { color: var(--amber); font-size: 14px; }
.best-score strong, .score-pill strong {
    color: var(--text);
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.best-score strong { color: #92400e; }
.score-pill {
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    border-color: #c7d2fe;
}
.score-pill strong { color: var(--indigo-dark); }

.lives {
    display: inline-flex;
    gap: 4px;
    font-size: 22px;
    line-height: 1;
}
.lives .heart {
    display: inline-block;
    transition: transform 0.2s ease, opacity 0.3s ease;
}
.lives .heart.lost {
    opacity: 0.25;
    transform: scale(0.85);
    filter: grayscale(1);
}
.lives .heart.lose-anim {
    animation: heart-break 0.5s ease forwards;
}
@keyframes heart-break {
    0% { transform: scale(1); }
    30% { transform: scale(1.4); }
    60% { transform: scale(0.7); opacity: 0.3; }
    100% { transform: scale(0.85); opacity: 0.25; filter: grayscale(1); }
}

/* ===== Theme bar ===== */
.theme-bar {
    max-width: 720px;
    margin: 32px auto 0;
    padding: 0 20px;
}
#theme-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    background: var(--bg-card);
    padding: 8px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
#theme-input {
    flex: 1;
    min-width: 200px;
    padding: 14px 18px;
    font-family: inherit;
    font-size: 16px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
}
#theme-input::placeholder { color: var(--text-soft); }
#theme-input:focus { outline: none; }

button {
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease;
    border: none;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

#play-btn, #submit-btn, #continue-btn, #replay-btn, .btn-primary-large {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 24px;
    font-size: 15px;
    background: var(--gradient-primary);
    color: white;
    border-radius: var(--radius);
    box-shadow: 0 4px 14px rgba(99,102,241,0.35);
}
#play-btn:hover:not(:disabled),
#submit-btn:hover:not(:disabled),
#continue-btn:hover:not(:disabled),
#replay-btn:hover:not(:disabled),
.btn-primary-large:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 8px 24px rgba(99,102,241,0.5);
}
#play-btn:active:not(:disabled),
#submit-btn:active:not(:disabled) { transform: translateY(0); }

#change-theme-btn {
    padding: 14px 18px;
    font-size: 14px;
    background: var(--bg-soft);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
#change-theme-btn:hover { background: var(--bg-soft-2); }

.theme-status {
    margin: 12px 4px 0;
    font-size: 13px;
    color: var(--text-muted);
    min-height: 1.4em;
}
.theme-status.error { color: var(--rose); }

/* ===== Welcome / hero ===== */
.main-wrap { padding: 0 20px; }
.welcome {
    max-width: 1000px;
    margin: 40px auto 0;
    animation: fade-up 0.6s ease both;
}
@keyframes fade-up {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.hero {
    text-align: center;
    padding: 32px 16px 8px;
}
.hero-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(36px, 6vw, 56px);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.05;
    margin: 0 0 16px;
    color: var(--text);
}
.hero-accent {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.hero-subtitle {
    font-size: 18px;
    color: var(--text-muted);
    max-width: 580px;
    margin: 0 auto;
    line-height: 1.6;
}

.rules {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin: 40px 0 32px;
}
.rule-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.rule-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}
.rule-icon {
    font-size: 32px;
    margin-bottom: 12px;
    line-height: 1;
}
.rule-card h3 {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}
.rule-card p {
    margin: 0;
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.5;
}

.suggestions {
    text-align: center;
    margin-bottom: 40px;
}
.suggestions-label {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-soft);
    font-weight: 600;
    margin: 0 0 14px;
}
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.chip {
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 500;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    transition: all 0.15s ease;
}
.chip:hover {
    border-color: var(--indigo);
    color: var(--indigo-dark);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(99,102,241,0.15);
}

/* ===== Loading ===== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 720px;
    margin: 60px auto;
    color: var(--text-muted);
}
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--bg-soft-2);
    border-top-color: var(--indigo);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Article ===== */
.article {
    max-width: 760px;
    margin: 28px auto;
    padding: 40px 48px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    font-family: 'Lora', Georgia, serif;
    font-size: 17px;
    line-height: 1.75;
    color: #2a2a2e;
    animation: fade-up 0.4s ease both;
}
.article h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 34px;
    font-weight: 600;
    letter-spacing: -0.02em;
    border-bottom: 2px solid var(--bg-soft-2);
    padding-bottom: 12px;
    margin: 0 0 20px;
    color: var(--text);
}
.article h2 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 22px;
    font-weight: 600;
    margin: 28px 0 12px;
    color: var(--text);
}
.article h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 18px;
    font-weight: 600;
    margin: 22px 0 10px;
    color: var(--text);
}
.article p { margin: 0 0 16px; }
.article ul, .article ol { margin: 0 0 16px; padding-left: 28px; }
.article li { margin: 4px 0; }
.article a {
    color: var(--indigo-dark);
    text-decoration: none;
    border-bottom: 1px solid rgba(99,102,241,0.25);
    transition: border-color 0.15s;
}
.article a:hover { border-bottom-color: var(--indigo); }
.article a.new { color: var(--rose); }
.article img { max-width: 100%; height: auto; border-radius: 8px; }
.article figure {
    margin: 16px 0;
    padding: 8px;
    background: var(--bg-soft);
    border-radius: 10px;
    text-align: center;
    max-width: 320px;
    float: right;
    clear: right;
    margin-left: 20px;
}
.article figcaption {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 6px;
    line-height: 1.5;
}
.article blockquote {
    border-left: 4px solid var(--indigo);
    padding: 4px 0 4px 16px;
    margin: 16px 0;
    color: var(--text-muted);
    font-style: italic;
}
.article table {
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 14px;
    width: 100%;
}
.article th, .article td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.article th { background: var(--bg-soft); font-weight: 600; }

/* ===== Masked word ===== */
.masked-word {
    display: inline-block;
    padding: 0 6px;
    margin: 0 1px;
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    border: 1.5px solid var(--indigo);
    border-radius: 6px;
    font-family: 'Space Grotesk', monospace;
    letter-spacing: 3px;
    color: transparent;
    user-select: none;
    vertical-align: baseline;
    box-shadow: 0 1px 3px rgba(99,102,241,0.15);
    animation: pulse-mask 2.5s ease-in-out infinite;
}
@keyframes pulse-mask {
    0%, 100% { box-shadow: 0 1px 3px rgba(99,102,241,0.15); }
    50%      { box-shadow: 0 2px 12px rgba(99,102,241,0.35); }
}
.masked-word::before {
    content: attr(data-mask);
    color: var(--indigo);
    opacity: 0.6;
}
.masked-word.revealed-wrong {
    background: linear-gradient(135deg, #fee2e2, #fecaca);
    border-color: var(--rose);
    color: #991b1b;
    font-family: inherit;
    letter-spacing: normal;
    font-weight: 700;
    animation: shake 0.4s ease;
    box-shadow: 0 2px 8px rgba(244,63,94,0.25);
}
.masked-word.revealed-wrong::before { content: ""; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}
.masked-word.revealed-right {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    border-color: var(--emerald);
    color: #064e3b;
    font-family: inherit;
    letter-spacing: normal;
    font-weight: 700;
    animation: pop 0.4s ease;
    box-shadow: 0 2px 8px rgba(16,185,129,0.25);
}
.masked-word.revealed-right::before { content: ""; }
@keyframes pop {
    0%   { transform: scale(0.9); }
    50%  { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ===== Answer bar ===== */
.answer-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(255,255,255,0.85);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid rgba(228,228,231,0.6);
    padding: 16px 20px 20px;
    z-index: 10;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.04);
}
#answer-form {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.hint {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    border: 1px solid #c7d2fe;
    color: var(--indigo-dark);
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-pill);
    white-space: nowrap;
}
#answer-input {
    flex: 1;
    min-width: 180px;
    padding: 14px 18px;
    font-family: inherit;
    font-size: 16px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
#answer-input:focus {
    outline: none;
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
#answer-input:disabled {
    background: var(--bg-soft);
    color: var(--text-muted);
}
.feedback {
    max-width: 760px;
    margin: 8px auto 0;
    font-size: 14px;
    font-weight: 500;
    min-height: 1.2em;
    text-align: center;
}
.feedback.success { color: var(--emerald-dark); }
.feedback.error { color: var(--rose); }

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(24,24,27,0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    animation: fade-in 0.25s ease both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
    background: var(--bg-card);
    padding: 40px 48px;
    border-radius: var(--radius-lg);
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 440px;
    width: calc(100% - 32px);
    animation: modal-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes modal-pop {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}
.modal-icon {
    font-size: 56px;
    margin-bottom: 12px;
    line-height: 1;
    animation: wobble 0.8s ease;
}
@keyframes wobble {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-8deg); }
    75% { transform: rotate(8deg); }
}
.modal-content h2 {
    margin: 0 0 16px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 32px;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.modal-score {
    font-size: 16px;
    color: var(--text-muted);
    margin: 8px 0 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.modal-score strong {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 64px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.modal-best {
    margin: 12px 0 24px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-radius: var(--radius-pill);
    font-size: 14px;
    color: #92400e;
    font-weight: 600;
    display: inline-block;
}
.modal-best.new-record {
    animation: glow 1.5s ease infinite;
}
@keyframes glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.4); }
    50%      { box-shadow: 0 0 0 12px rgba(245,158,11,0); }
}
.btn-primary-large {
    margin-top: 8px;
    padding: 14px 32px;
    font-size: 16px;
}

/* ===== Mobile ===== */
@media (max-width: 720px) {
    .app-header { padding: 0 16px; }
    .app-title { font-size: 16px; }
    .brand-mark { width: 32px; height: 32px; font-size: 12px; }
    .status { gap: 8px; }
    .best-score, .score-pill { padding: 5px 10px; font-size: 12px; }
    .best-score-label, .score-label { display: none; }
    .lives { font-size: 18px; }

    .article { padding: 28px 22px; }
    .article figure {
        float: none;
        margin: 16px auto;
        max-width: 100%;
    }

    .rules {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .hint { display: none; }
    .modal-content { padding: 32px 24px; }
    .modal-score strong { font-size: 48px; }
}
