/* ==========================================================================
   Block Puzzle — Premium Dark-Navy Theme & Responsive Styles
   ========================================================================== */

:root {
    --bg-primary: #101827;
    --bg-secondary: #182438;
    --bg-board: #223149;
    --bg-cell: #162235;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);

    --accent-blue: #37B2F6;
    --accent-purple: #9475FF;
    --accent-yellow: #FFD166;
    --accent-green: #42D6A4;
    --accent-danger: #FF6B8B;

    --text-primary: #FFFFFF;
    --text-secondary: #A8B5C7;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;

    --board-size: min(92vw, 440px, 52dvh);
    --tray-cell-size: clamp(14px, 3.6vw, 22px);

    --shadow-card: 0 12px 32px rgba(0, 0, 0, 0.35);
    --shadow-block: inset 0 2px 3px rgba(255, 255, 255, 0.35),
                    inset 0 -3px 4px rgba(0, 0, 0, 0.28),
                    0 3px 8px rgba(0, 0, 0, 0.3);
}

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

html,
body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    line-height: 1.5;
}

body {
    background-image:
        radial-gradient(circle at 18% 10%, rgba(55, 178, 246, 0.12), transparent 45%),
        radial-gradient(circle at 85% 25%, rgba(148, 117, 255, 0.12), transparent 45%);
}

button {
    font-family: inherit;
    color: inherit;
    cursor: pointer;
    border: none;
    background: none;
    -webkit-tap-highlight-color: transparent;
}

[hidden] {
    display: none !important;
}

/* ==========================================================================
   App Layout
   ========================================================================== */

.app-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.game-shell {
    width: 100%;
    max-width: 520px;
    min-height: 100dvh;
    padding: max(10px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
}

/* ==========================================================================
   Header & HUD
   ========================================================================== */

.game-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.header-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    display: grid;
    grid-template-columns: repeat(2, 10px);
    grid-template-rows: repeat(2, 10px);
    gap: 3px;
}

.brand-icon span {
    border-radius: 3px;
    display: block;
}

.brand-icon span:nth-child(1) { background: var(--accent-blue); }
.brand-icon span:nth-child(2) { background: var(--accent-purple); }
.brand-icon span:nth-child(3) { background: var(--accent-green); }
.brand-icon span:nth-child(4) { background: var(--accent-yellow); }

.brand-title {
    font-size: clamp(1.05rem, 4vw, 1.35rem);
    font-weight: 800;
    letter-spacing: 0.06em;
    background: linear-gradient(135deg, #FFFFFF 20%, #A8B5C7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
    background: var(--bg-board);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.icon-btn:active {
    transform: scale(0.94);
}

.icon-btn svg {
    width: 19px;
    height: 19px;
}

.icon-btn .icon-sound-off {
    display: none;
}

.icon-btn.is-muted .icon-sound-on {
    display: none;
}

.icon-btn.is-muted .icon-sound-off {
    display: block;
    color: var(--accent-danger);
}

.hud-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.score-cards {
    display: flex;
    gap: 8px;
    flex: 1;
}

.score-card {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 7px 12px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.score-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.score-value {
    font-size: clamp(1.1rem, 4.2vw, 1.4rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.score-card--current .score-value {
    color: var(--accent-blue);
}

.score-card--best .score-value {
    color: var(--accent-yellow);
}

.mode-switcher {
    display: flex;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 3px;
    gap: 3px;
}

.mode-btn {
    padding: 7px 11px;
    border-radius: 9px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-secondary);
    transition: background-color 0.18s ease, color 0.18s ease;
}

.mode-btn--active {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: var(--text-primary);
    box-shadow: 0 2px 10px rgba(55, 178, 246, 0.3);
}

/* Daily Challenge Bar */
.daily-bar {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 7px 12px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.daily-bar-top {
    display: flex;
    justify-content: space-between;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.daily-progress-track {
    height: 6px;
    background: var(--bg-cell);
    border-radius: 999px;
    overflow: hidden;
}

.daily-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-blue));
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* ==========================================================================
   Main Game Area & 10x10 Board
   ========================================================================== */

.game-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex: 1;
}

.board-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.combo-pill {
    position: absolute;
    top: -12px;
    z-index: 5;
    background: linear-gradient(135deg, var(--accent-yellow), #FF9F43);
    color: #101827;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    padding: 3px 12px;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(255, 209, 102, 0.45);
    animation: popIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.board-frame {
    position: relative;
    width: var(--board-size);
    height: var(--board-size);
    padding: 8px;
    border-radius: var(--radius-lg);
    background: linear-gradient(160deg, #273854, var(--bg-board));
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-card);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.game-board {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 3px;
}

.board-cell {
    background: var(--bg-cell);
    border-radius: var(--radius-sm);
    position: relative;
    transition: background-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.board-cell--filled {
    background: var(--block-color, var(--accent-blue));
    box-shadow: var(--shadow-block);
}

.board-cell--just-placed {
    animation: cellPlaceBounce 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

.board-cell--clearing {
    animation: cellClearPop 0.3s ease-out forwards;
}

.board-cell--preview-valid {
    background: var(--preview-color, var(--accent-blue));
    opacity: 0.55;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
}

.board-cell--preview-invalid {
    background: rgba(255, 107, 139, 0.35);
    box-shadow: inset 0 0 0 2px rgba(255, 107, 139, 0.85);
}

.board-cell--preview-clear {
    box-shadow: inset 0 0 0 2px var(--accent-yellow), 0 0 12px rgba(255, 209, 102, 0.5);
    filter: brightness(1.22);
}

.effects-canvas {
    position: absolute;
    inset: 8px;
    width: calc(100% - 16px);
    height: calc(100% - 16px);
    pointer-events: none;
    z-index: 3;
}

.popup-layer {
    position: absolute;
    inset: 8px;
    pointer-events: none;
    z-index: 4;
    overflow: visible;
}

/* ==========================================================================
   Bottom Block Tray & Drag Ghost
   ========================================================================== */

.tray-section {
    width: 100%;
    max-width: 440px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.tray-slot {
    height: clamp(86px, 14dvh, 114px);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
    transition: transform 0.18s ease, border-color 0.18s ease, opacity 0.18s ease, background-color 0.18s ease;
}

.tray-slot:hover:not(.tray-slot--empty) {
    border-color: rgba(55, 178, 246, 0.45);
    background: #1d2b42;
    transform: translateY(-2px);
}

.tray-slot--empty {
    cursor: default;
    opacity: 0.45;
}

.tray-slot--dragging {
    opacity: 0.25;
    transform: scale(0.92);
}

.tray-slot--unplaceable {
    opacity: 0.42;
    filter: grayscale(0.45);
}

.tray-piece {
    display: grid;
    gap: 2px;
    pointer-events: none;
}

.tray-cell {
    background: var(--block-color, var(--accent-blue));
    border-radius: 4px;
    box-shadow: var(--shadow-block);
}

.tray-cell--empty {
    background: transparent;
}

/* Floating Drag Ghost */
.drag-ghost {
    position: fixed;
    top: 0;
    left: 0;
    display: grid;
    gap: 3px;
    pointer-events: none;
    z-index: 1000;
    will-change: transform;
    filter: drop-shadow(0 12px 22px rgba(0, 0, 0, 0.55));
}

.drag-ghost-cell {
    background: var(--block-color, var(--accent-blue));
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-block);
}

.drag-ghost-empty {
    background: transparent;
}

/* ==========================================================================
   Popups & Animations
   ========================================================================== */

.score-popup {
    position: absolute;
    transform: translate(-50%, -50%);
    font-size: 1.05rem;
    font-weight: 800;
    color: #FFFFFF;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
    white-space: nowrap;
    animation: floatUpFade 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.score-popup--big {
    font-size: 1.4rem;
    color: var(--accent-yellow);
}

.combo-banner {
    position: absolute;
    left: 50%;
    top: 46%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    color: #FFFFFF;
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    padding: 7px 18px;
    border-radius: 999px;
    box-shadow: 0 8px 26px rgba(55, 178, 246, 0.45);
    white-space: nowrap;
    animation: bannerPop 1.05s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes cellPlaceBounce {
    0% { transform: scale(0.8); }
    60% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

@keyframes cellClearPop {
    0% { transform: scale(1); background: #FFFFFF; opacity: 1; }
    40% { transform: scale(1.12); background: var(--accent-yellow); opacity: 0.9; }
    100% { transform: scale(0.2); opacity: 0; }
}

@keyframes floatUpFade {
    0% { opacity: 0; transform: translate(-50%, -30%) scale(0.75); }
    20% { opacity: 1; transform: translate(-50%, -55%) scale(1.08); }
    100% { opacity: 0; transform: translate(-50%, -140%) scale(0.95); }
}

@keyframes bannerPop {
    0% { opacity: 0; transform: translate(-50%, -40%) scale(0.65); }
    18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
    75% { opacity: 1; transform: translate(-50%, -58%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -80%) scale(0.92); }
}

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.75); }
    100% { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   Footer
   ========================================================================== */

.game-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.footer-actions {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 440px;
}

.footer-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.footer-btn:hover {
    background: var(--bg-board);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.footer-btn:active {
    transform: scale(0.96);
}

.footer-btn svg {
    width: 15px;
    height: 15px;
}

.footer-tip {
    font-size: 0.74rem;
    color: var(--text-secondary);
    text-align: center;
}

/* ==========================================================================
   Modals & Controls
   ========================================================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 13, 22, 0.78);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 2000;
    animation: fadeIn 0.18s ease;
}

.modal {
    width: 100%;
    max-width: 380px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 24px 22px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: popIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-badge {
    align-self: center;
    background: linear-gradient(135deg, var(--accent-yellow), #FF9F43);
    color: #101827;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    padding: 4px 12px;
    border-radius: 999px;
}

.modal-title {
    font-size: 1.35rem;
    font-weight: 800;
    text-align: center;
}

.modal-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: -8px;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-actions--row {
    flex-direction: row;
}

.modal-actions--row .btn {
    flex: 1;
}

.btn {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 700;
    transition: transform 0.15s ease, filter 0.15s ease, background-color 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
}

.btn:active {
    transform: scale(0.97);
}

.btn--primary {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: #FFFFFF;
    box-shadow: 0 6px 18px rgba(55, 178, 246, 0.32);
}

.btn--secondary {
    background: var(--bg-board);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.btn--danger {
    background: var(--accent-danger);
    color: #FFFFFF;
}

.btn--danger-outline {
    background: transparent;
    color: var(--accent-danger);
    border: 1px solid rgba(255, 107, 139, 0.45);
}

/* Settings Toggle */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-board);
    padding: 12px 14px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
}

.toggle-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch {
    position: relative;
    width: 46px;
    height: 26px;
    background: #334663;
    border-radius: 999px;
    transition: background-color 0.2s ease;
}

.toggle-switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #FFFFFF;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.toggle-input:checked + .toggle-switch {
    background: var(--accent-green);
}

.toggle-input:checked + .toggle-switch::after {
    transform: translateX(20px);
}

/* Game Over & Stats */
.gameover-scores {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.go-score-box {
    background: var(--bg-board);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.go-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.go-value {
    font-size: 1.55rem;
    font-weight: 800;
    color: var(--accent-blue);
}

.go-value--accent {
    color: var(--accent-yellow);
}

.gameover-mini-stats {
    display: flex;
    justify-content: space-around;
    font-size: 0.84rem;
    color: var(--text-secondary);
}

.gameover-mini-stats strong {
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-item {
    background: var(--bg-board);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.stat-item--wide {
    grid-column: span 2;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.stat-val {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--accent-blue);
}

/* Tutorial Steps */
.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tutorial-step {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: var(--bg-board);
    padding: 11px 12px;
    border-radius: var(--radius-md);
}

.step-num {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 800;
    flex-shrink: 0;
}

.tutorial-step strong {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.tutorial-step p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==========================================================================
   SEO / Portal Info Section Below Game
   ========================================================================== */

.info-section {
    width: 100%;
    max-width: 760px;
    padding: 28px 16px 48px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.info-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
}

.info-card h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.info-card p {
    font-size: 0.92rem;
    color: var(--text-secondary);
}

.guide-list {
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.92rem;
    color: var(--text-secondary);
}

.guide-list strong {
    color: var(--text-primary);
}

.faq-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.faq-item {
    background: var(--bg-board);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}

.faq-item summary {
    font-weight: 600;
    font-size: 0.93rem;
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.faq-item summary::after {
    content: "+";
    font-size: 1.1rem;
    color: var(--accent-blue);
    font-weight: 700;
}

.faq-item[open] summary::after {
    content: "−";
}

.faq-item p {
    margin-top: 8px;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

/* ==========================================================================
   Landscape Mobile Adaptation
   ========================================================================== */

@media (max-height: 580px) and (orientation: landscape) {
    :root {
        --board-size: min(70dvh, 46vw, 340px);
        --tray-cell-size: clamp(11px, 2.4dvh, 16px);
    }

    .game-shell {
        max-width: 780px;
        gap: 6px;
    }

    .game-main {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 18px;
    }

    .tray-section {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(3, 1fr);
        width: 150px;
    }

    .tray-slot {
        height: clamp(64px, 21dvh, 88px);
    }

    .footer-tip {
        display: none;
    }
}

