:root {
    --bg-primary: #f5e6d0;
    --bg-secondary: #e8d5b8;
    --bg-board: #d4b896;
    --bg-dark: #c4a882;
    --border-box: #b8956a;
    --border-light: #d4b896;
    --shadow-box: 0 4px 12px rgba(139, 90, 43, 0.3);
    --shadow-hover: 0 6px 16px rgba(139, 90, 43, 0.4);
    --shadow-picked: 0 8px 24px rgba(139, 90, 43, 0.5);
    --radius-box: 12px;
    --radius-cell: 6px;
    --radius-button: 10px;

    --color-red: #e74c3c;
    --color-blue: #3498db;
    --color-green: #2ecc71;
    --color-yellow: #f1c40f;
    --color-purple: #9b59b6;
    --color-orange: #e67e22;

    --color-red-dark: #c0392b;
    --color-blue-dark: #2980b9;
    --color-green-dark: #27ae60;
    --color-yellow-dark: #d4a30e;
    --color-purple-dark: #8e44ad;
    --color-orange-dark: #d35400;

    --cell-size: 48px; /* default fallback, overridden dynamically on .board */
    --cell-gap: 3px;
    --column-gap: 10px;
    --box-extra: 17px;

    --text-primary: #5d4037;
    --text-secondary: #8d6e63;
    --text-light: #f5e6d0;
}

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

body {
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-dark) 100%);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    font-size: 1.5rem;
    color: var(--text-secondary);
}

/* ===== Main Menu ===== */
.main-menu {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.menu-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 36px;
}

/* Logo */
.logo-area {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.logo-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 340px;
    height: 200px;
    background: radial-gradient(ellipse, rgba(228, 180, 100, 0.35) 0%, rgba(228, 180, 100, 0.1) 40%, transparent 70%);
    filter: blur(30px);
    pointer-events: none;
    animation: glow-breathe 4s ease-in-out infinite;
}

.game-title {
    font-size: 4.2rem;
    font-weight: 900;
    color: var(--text-primary);
    letter-spacing: -1px;
    text-shadow:
        0 2px 0 #c4a070,
        0 4px 0 #b8956a,
        0 6px 12px rgba(93, 64, 55, 0.25),
        0 0 40px rgba(228, 180, 100, 0.15);
    line-height: 1;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 3px;
    text-transform: uppercase;
}

/* Play Button */
.play-btn {
    display: inline-block;
    padding: 20px 84px;
    background: linear-gradient(135deg, var(--color-green), var(--color-green-dark));
    color: white;
    font-size: 1.6rem;
    font-weight: 800;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 4px;
    border-radius: 16px;
    box-shadow:
        0 4px 0 var(--color-green-dark),
        0 6px 20px rgba(46, 204, 113, 0.4);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    animation: pulse 2.5s ease-in-out infinite;
}

.play-btn:hover {
    transform: translateY(-3px);
    box-shadow:
        0 7px 0 var(--color-green-dark),
        0 10px 30px rgba(46, 204, 113, 0.5);
    animation-play-state: paused;
}

.play-btn:active {
    transform: translateY(2px);
    box-shadow:
        0 2px 0 var(--color-green-dark),
        0 3px 10px rgba(46, 204, 113, 0.3);
    animation-play-state: paused;
}

/* Secondary Buttons */
.menu-actions {
    display: flex;
    gap: 12px;
}

.menu-action-btn {
    padding: 10px 24px;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    border: 2px solid var(--border-box);
    border-radius: var(--radius-button);
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.menu-action-btn:hover {
    background: rgba(184, 149, 106, 0.25);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(139, 90, 43, 0.15);
}

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

/* External Links Panel */
.external-links {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    display: flex;
    gap: 12px;
}

.ext-link-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    border: 1.5px solid var(--border-light);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s, color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.ext-link-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(139, 90, 43, 0.15);
}

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

.ext-link-btn svg {
    flex-shrink: 0;
}

/* Decorative Floating Blocks */
.decor-blocks {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.decor-block {
    position: absolute;
    display: grid;
    gap: 3px;
    opacity: 0.22;
    animation: float var(--float-duration, 7s) ease-in-out infinite;
    animation-delay: var(--float-delay, 0s);
}

.decor-t { grid-template-columns: repeat(3, 24px); grid-template-rows: repeat(2, 24px); }
.decor-l { grid-template-columns: repeat(2, 24px); grid-template-rows: repeat(3, 24px); }
.decor-o { grid-template-columns: repeat(2, 28px); grid-template-rows: repeat(2, 28px); }
.decor-s { grid-template-columns: repeat(3, 22px); grid-template-rows: repeat(2, 22px); }
.decor-i { grid-template-columns: repeat(1, 22px); grid-template-rows: repeat(4, 22px); }
.decor-z { grid-template-columns: repeat(3, 22px); grid-template-rows: repeat(2, 22px); }

.dc {
    background: var(--dc-color, var(--color-red));
    border-radius: 5px;
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}

/* Menu Animations */
@keyframes float {
    0%, 100% { transform: translateY(0) rotate(var(--rot-start, 0deg)); }
    50% { transform: translateY(var(--float-y, -15px)) rotate(var(--rot-end, 0deg)); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

@keyframes glow-breathe {
    0%, 100% { opacity: 0.7; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

/* Play Page */
.play-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 8px;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.game-header {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 600px;
    flex-wrap: wrap;
    position: relative;
    z-index: 10;
    background: var(--bg-dark);
    padding: 8px 12px;
    border-radius: var(--radius-box);
}

.level-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-btn {
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-box);
    border-radius: var(--radius-button);
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s;
}

.nav-btn:hover:not(:disabled) { background: var(--bg-dark); }
.nav-btn:disabled { opacity: 0.4; cursor: default; }

.level-goto {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.15);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-button);
}

.level-goto input {
    width: 44px;
    padding: 3px 6px;
    border: 1.5px solid var(--border-box);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.8rem;
    text-align: center;
}

.goto-btn {
    padding: 3px 10px;
    border: 1.5px solid var(--border-box);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.goto-btn:hover { background: var(--bg-dark); }

/* Hide number input spinners */
.level-goto input::-webkit-inner-spin-button,
.level-goto input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.level-goto input[type=number] {
    -moz-appearance: textfield;
}

.back-button {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-box);
    border-radius: var(--radius-button);
    color: var(--text-primary);
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease;
}

.back-button:hover {
    background: var(--bg-dark);
}

.level-label {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Error UI */
#blazor-error-ui {
    background: #fff3cd;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Drag ghost — floating block following cursor */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.8;
    transform: scale(1.1);
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.4));
    animation: ghost-appear 0.15s ease-out;
}

.drag-ghost-grid {
    display: inline-grid;
    gap: var(--cell-gap);
}

@keyframes ghost-appear {
    from { opacity: 0; transform: scale(0.7); }
    to { opacity: 0.8; transform: scale(1.1); }
}

/* ===== Mobile Responsive ===== */
@media (max-width: 480px) {
    :root {
        --cell-size: 32px;
        --cell-size-queue: 14px;
        --cell-gap: 2px;
        --radius-box: 8px;
        --radius-cell: 4px;
        --column-gap: 6px;
        --box-extra: 12px;
    }
    .game-title { font-size: 2.8rem; }
    .subtitle { font-size: 0.85rem; letter-spacing: 2px; }
    .play-btn { padding: 16px 56px; font-size: 1.3rem; letter-spacing: 3px; }
    .menu-content { gap: 28px; }
    .menu-action-btn { display: none; }
    .decor-block { opacity: 0.15; }
    .decor-t, .decor-l, .decor-s, .decor-z { grid-template-columns: repeat(3, 18px); grid-template-rows: repeat(2, 18px); }
    .decor-l { grid-template-columns: repeat(2, 18px); grid-template-rows: repeat(3, 18px); }
    .decor-o { grid-template-columns: repeat(2, 20px); grid-template-rows: repeat(2, 20px); }
    .decor-i { grid-template-columns: repeat(1, 18px); grid-template-rows: repeat(4, 18px); }
    .main-menu { flex-direction: column; overflow: auto; padding: 20px 0; }
    .external-links { position: static; transform: none; margin-top: 16px; gap: 8px; flex-wrap: wrap; justify-content: center; }
    .ext-link-btn { padding: 6px 12px; font-size: 0.75rem; }
    .ext-link-btn svg { width: 18px; height: 18px; }
    .play-page { gap: 6px; padding: 4px; }
    .game-header { gap: 8px; }
    .back-button { padding: 6px 10px; font-size: 0.85rem; }
    .level-label { font-size: 1rem; }
    .game-over-card { padding: 24px 32px; }
    .game-over-title { font-size: 1.5rem; }
    .game-over-button { padding: 10px 28px; font-size: 1rem; }
}

@media (max-width: 380px) {
    :root {
        --cell-size: 26px;
        --cell-size-queue: 12px;
        --cell-gap: 2px;
        --column-gap: 4px;
        --box-extra: 10px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    :root {
        --cell-size: 40px;
        --cell-size-queue: 16px;
        --cell-gap: 2px;
    }
    .play-page { gap: 14px; padding: 12px; }
}
