* { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
    height: 100%;
}
body {
    margin: 0;
    height: 100vh;
    height: 100dvh;
    background: #eef1f6;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: #1b1b18;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.tetrum-topbar-wrap {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    flex-shrink: 0;
}

.tetrum-game-wrap {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.tetrum-screen {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tetrum-screen-game {
    width: 100%;
    height: 100%;
    position: relative;
}

.tetrum-level-complete {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10;
    background: #fff;
    border-radius: 20px;
    padding: 32px 48px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.tetrum-level-complete.is-visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}

.tetrum-level-complete-text {
    font-size: 28px;
    font-weight: 700;
    color: #1b1b18;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    white-space: nowrap;
}

.tetrum-objective-tooltip {
    position: absolute;
    max-width: 220px;
    background: #1b1b18;
    color: #fff;
    font-size: 13px;
    line-height: 1.4;
    padding: 10px 12px;
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    z-index: 20;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.tetrum-objective-tooltip.is-visible {
    opacity: 1;
}

.tetrum-loader {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tetrum-loader-spinner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 5px solid #d8dce3;
    border-top-color: #0066cc;
    animation: tetrum-spin 0.8s linear infinite;
}

@keyframes tetrum-spin {
    to { transform: rotate(360deg); }
}

.tetrum-game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.tetrum-screen-start {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.tetrum-start-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.tetrum-start-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    background: #fff;
    border-radius: 20px;
    padding: 32px 48px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.tetrum-progress-hint {
    font-size: 14px;
    font-weight: 600;
    color: #6b7280;
}

.tetrum-how-to-play-btn {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: #0066cc;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
}

.tetrum-how-to-play-btn:hover {
    text-decoration: underline;
}

.tetrum-play-btn {
    font-family: inherit;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    background: #0066cc;
    border: none;
    border-radius: 12px;
    padding: 18px 56px;
    cursor: pointer;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18), inset 0 2px 0 rgba(255, 255, 255, 0.25);
    transition: filter 0.15s ease;
}

.tetrum-play-btn:hover {
    filter: brightness(1.15);
}

.tetrum-play-btn:active {
    filter: brightness(0.95);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35);
    transform: translateY(2px);
}

.tetrum-ad-bonus-btn {
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #ff9f43, #ee5253);
    border: none;
    border-radius: 10px;
    padding: 12px 22px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.25);
    transition: filter 0.15s ease;
}

.tetrum-ad-bonus-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.tetrum-ad-bonus-btn:hover {
    filter: brightness(1.1);
}

.tetrum-ad-bonus-btn:active {
    filter: brightness(0.95);
    transform: translateY(1px);
}

.tetrum-topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    background: #fff;
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.tetrum-topbar h1 {
    grid-column: 2;
    justify-self: center;
    margin: 0;
}

.tetrum-logo {
    display: flex;
    gap: 3px;
    cursor: default;
}

.tetrum-logo-tile {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18), inset 0 2px 0 rgba(255, 255, 255, 0.25);
    cursor: default;
    transition: transform 0.25s ease;
}

.tetrum-logo-tile:hover {
    transform: rotate(20deg);
}

@media (max-width: 500px) {
    .tetrum-logo {
        display: none;
    }
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: #f3f5f9;
    border-radius: 8px;
    cursor: pointer;
    color: #1b1b18;
    padding: 0;
}

.icon-btn:hover {
    background: #e9ecf2;
}

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

.tetrum-topbar-left {
    grid-column: 1;
    justify-self: start;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tetrum-vk-user {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px 4px 4px;
    background: #f3f5f9;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: #1b1b18;
    white-space: nowrap;
    overflow: hidden;
}

.tetrum-vk-user img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: block;
    object-fit: cover;
    flex-shrink: 0;
}

@media (max-width: 420px) {
    .tetrum-vk-user span {
        display: none;
    }

    .tetrum-vk-user {
        padding: 4px;
    }
}

#menu-toggle {
    grid-column: 3;
    justify-self: end;
}

.tetrum-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.tetrum-menu-overlay.is-open {
    display: block;
}

.tetrum-menu-panel {
    position: fixed;
    background: #fff;
    border-radius: 10px;
    min-height: 100px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    padding: 8px;
}

.tetrum-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    color: #1b1b18;
    background: none;
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    white-space: nowrap;
}

.tetrum-menu-item:hover {
    background: #f3f5f9;
}

.tetrum-levels-overlay {
    display: none;
    position: fixed;
    inset: 0;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1100;
}

.tetrum-levels-overlay.is-open {
    display: flex;
}

.tetrum-levels-modal {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
    width: min(480px, 92vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tetrum-levels-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid #eef1f6;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
}

.tetrum-levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 10px;
    padding: 18px;
    overflow-y: auto;
}

.tetrum-level-item {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    background: #0066cc;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18), inset 0 2px 0 rgba(255, 255, 255, 0.25);
    transition: filter 0.15s ease;
}

.tetrum-level-item:hover {
    filter: brightness(1.15);
}

.tetrum-level-item:active {
    filter: brightness(0.95);
    transform: translateY(1px);
}

.tetrum-level-item.is-completed {
    background: #22c55e;
}

.tetrum-level-item.is-locked {
    background: #d8dce3;
    color: #97a0ad;
    cursor: not-allowed;
    box-shadow: none;
    text-shadow: none;
}

.tetrum-level-item.is-playing {
    animation: tetrum-level-playing-pulse 1.2s ease-in-out infinite;
}

@keyframes tetrum-level-playing-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    pointer-events: none;
}

.tutorial-highlight {
    position: absolute;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    transition: left 0.3s ease, top 0.3s ease, width 0.3s ease, height 0.3s ease;
    pointer-events: none;
}

.tutorial-bubble {
    position: absolute;
    width: 280px;
    max-width: calc(100vw - 24px);
    background: #fff;
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    transition: left 0.3s ease, top 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.tutorial-bubble-title {
    font-size: 15px;
    font-weight: 700;
    color: #1b1b18;
    margin-bottom: 6px;
}

.tutorial-bubble-text {
    font-size: 13px;
    line-height: 1.4;
    color: #4b5563;
    margin-bottom: 12px;
}

.tutorial-bubble-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.tutorial-skip-btn {
    font-family: inherit;
    font-size: 12px;
    color: #97a0ad;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 4px;
}

.tutorial-skip-btn:hover {
    color: #6b7280;
}

.tutorial-next-btn {
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    background: #0066cc;
    border: none;
    border-radius: 8px;
    padding: 9px 18px;
    cursor: pointer;
}

.tutorial-next-btn:hover {
    filter: brightness(1.1);
}

.tutorial-bubble.is-waiting .tutorial-next-btn {
    display: none;
}
