:root {
    --bg: #020617;
    --panel: rgba(15, 23, 42, .72);
    --border: rgba(255,255,255,.08);
    --text: #f8fafc;
    --muted: #94a3b8;
    --accent: #f59e0b;
    --cell-gap: 2px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    color: var(--text);
}

body {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    overflow: hidden;
    overscroll-behavior: none;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button {
    font: inherit;
    border: 0;
    cursor: pointer;
}

button:active { transform: scale(.97); }

.app-shell {
    width: 100vw;
    height: 100vh;
    min-height: 100dvh;
    background:
        radial-gradient(circle at 15% 10%, rgba(59,130,246,.10), transparent 28%),
        radial-gradient(circle at 85% 85%, rgba(139,92,246,.09), transparent 28%),
        #020617;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

.app-container {
    width: min(100%, 520px);
    height: 100%;
    margin: 0 auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.glass-panel {
    background: var(--panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    box-shadow: 0 12px 35px rgba(0,0,0,.20);
}

.topbar {
    border-radius: 18px;
    padding: 14px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.title-area { min-width: 0; }

.title-row {
    display: flex;
    align-items: center;
    gap: 9px;
}

.title-row h1 {
    margin: 0;
    font-size: 21px;
    font-weight: 900;
    letter-spacing: -.5px;
}

#level-num { color: #fbbf24; }

.title-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: rgba(245,158,11,.14);
    border: 1px solid rgba(245,158,11,.25);
    color: #fbbf24;
    font-size: 24px;
    font-weight: 900;
}

#category-title {
    margin: 5px 0 0 43px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hint-badge {
    min-width: 88px;
    padding: 7px 9px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    gap: 7px;
    color: white;
    background: linear-gradient(135deg, rgba(49,46,129,.85), rgba(30,41,59,.9));
    border: 1px solid rgba(99,102,241,.4);
}

.hint-icon {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: rgba(99,102,241,.15);
    font-size: 17px;
}

.hint-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1;
}

.hint-info span {
    color: #a5b4fc;
    font-size: 8px;
    font-weight: 900;
    letter-spacing: 1px;
}

.hint-info strong {
    margin-top: 4px;
    font-size: 16px;
}

.hint-badge > b {
    margin-left: 2px;
    padding: 2px 5px;
    border-radius: 999px;
    background: #f59e0b;
    color: #111827;
    font-size: 10px;
}

.words-panel {
    border-radius: 18px;
    padding: 11px;
    margin-bottom: 10px;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.words-heading {
    display: flex;
    justify-content: space-between;
    align-items: end;
    padding: 0 3px 8px;
}

.words-heading h2 {
    margin: 0;
    color: var(--muted);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

#progress-text {
    color: #34d399;
    background: rgba(6,78,59,.3);
    border-radius: 6px;
    padding: 3px 7px;
    font-size: 11px;
    font-weight: 900;
}

.words-scroll {
    overflow-x: auto;
    scrollbar-width: none;
}

.words-scroll::-webkit-scrollbar { display: none; }

.word-list {
    min-height: 42px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
    padding-bottom: 2px;
}

.word-badge {
    padding: 7px 10px;
    border-radius: 10px;
    background: #1e293b;
    color: #cbd5e1;
    border: 1px solid #334155;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 1px;
    transition: all .25s ease;
}

.word-badge.found {
    opacity: .65;
    text-decoration: line-through;
    transform: scale(.95);
}

.game-area {
    flex: 1;
    min-height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
}

.game-footer {
    flex-shrink: 0;
    margin: 8px 10px 4px;
    position: relative;
    z-index: 20;
}

.primary-btn, .success-btn {
    width: 100%;
    padding: 14px 16px;
    border-radius: 16px;
    color: white;
    font-weight: 900;
    font-size: 14px;
}

.primary-btn {
    background: linear-gradient(90deg, #2563eb, #4f46e5);
    border: 1px solid rgba(96,165,250,.3);
    box-shadow: 0 0 18px rgba(79,70,229,.3);
}

.success-btn {
    background: linear-gradient(90deg, #10b981, #14b8a6);
    box-shadow: 0 0 20px rgba(16,185,129,.25);
}

.toast {
    position: fixed;
    top: calc(var(--safe-top) + 28px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100vw - 30px);
    padding: 11px 16px;
    border-radius: 15px;
    background: rgba(30,41,59,.96);
    border: 1px solid #475569;
    box-shadow: 0 16px 35px rgba(0,0,0,.4);
    color: white;
    font-size: 13px;
    font-weight: 800;
    transition: opacity .25s, transform .25s;
}

.toast.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -12px);
}

.toast:not(.hidden) {
    opacity: 1;
    transform: translate(-50%, 0);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(2,6,23,.90);
    backdrop-filter: blur(10px);
    transition: opacity .3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.win-card {
    width: min(100%, 330px);
    padding: 30px 24px;
    text-align: center;
    border-radius: 30px;
    background: linear-gradient(#1e293b, #0f172a);
    border: 1px solid #334155;
    box-shadow: 0 25px 70px rgba(0,0,0,.55);
    transform: scale(.92);
    transition: transform .35s cubic-bezier(.34,1.56,.64,1);
}

.modal:not(.hidden) .win-card { transform: scale(1); }

.trophy {
    font-size: 66px;
    margin-bottom: 8px;
    animation: bounce 1s infinite;
}

.win-card h2 {
    margin: 0 0 12px;
    font-size: 28px;
    font-weight: 950;
}

.category-pill {
    display: inline-block;
    padding: 6px 11px;
    margin-bottom: 12px;
    border-radius: 9px;
    color: #fbbf24;
    background: rgba(245,158,11,.13);
    border: 1px solid rgba(245,158,11,.25);
    font-size: 12px;
    font-weight: 900;
}

.win-message {
    margin: 0 0 20px;
    color: #94a3b8;
    font-size: 13px;
    line-height: 1.5;
}

#confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 900;
}

@media (max-height: 680px) {
    .app-container { padding: 9px; }
    .topbar { padding: 10px; margin-bottom: 8px; }
    .words-panel { padding: 8px; margin-bottom: 6px; }
    .game-footer { margin-top: 5px; }
    .primary-btn { padding: 11px; }
}
