:root {
    /* Core Palette */
    --color-blue: #4285F4;
    --color-red: #EA4335;
    --color-yellow: #FFD93D;
    --color-green: #34A853;

    /* Neutrals */
    --color-bg: #FFFFFF;
    --color-text: #000000;
    --color-text-dim: #999999;
    --color-platform: #e5e7eb;
    --color-tray: #f3f4f6;

    /* Typography */
    --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Spacing & Sizing (Responsive) */
    --block-size: clamp(16px, 3.5vh, 64px);
    --block-radius: calc(var(--block-size) * 0.18);
    --block-gap: clamp(0px, 0.2vh, 4px);
    --container-max-width: 450px;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--color-bg);
    color: var(--color-text);
    overflow: hidden;
    touch-action: manipulation;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#game-container {
    width: 100%;
    max-width: var(--container-max-width);
    height: 100vh;
    /* Fallback */
    height: 100svh;
    /* Small viewport height - accounts for mobile browser chrome */
    margin: 0 auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

#app {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: clamp(10px, 2vh, 20px);
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideUpModal {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* --- Layout & Screens --- */
.home-screen,
.memorize-screen,
.result-screen,
.review-screen,
.tutorial-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.4s ease-out;
}

.build-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* --- Common Components --- */
.hidden {
    display: none !important;
}

/* --- Blocks --- */
.block,
.tray-block {
    width: var(--block-size);
    height: var(--block-size);
    border-radius: var(--block-radius);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    border: none;
    cursor: pointer;
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tray-block {
    width: 56px;
    height: 56px;
}

.block.placeholder {
    background-color: #f3f4f6;
    box-shadow: none;
    border: 2px dashed #d1d5db;
}

.block.highlight {
    outline: 4px solid #f97316;
    outline-offset: 4px;
}

/* Colors */
.blue {
    background-color: var(--color-blue) !important;
}

.red {
    background-color: var(--color-red) !important;
}

.yellow {
    background-color: var(--color-yellow) !important;
}

.green {
    background-color: var(--color-green) !important;
}

/* --- Game UI --- */
.hero-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0;
}

.logo-stack {
    display: flex;
    flex-direction: column-reverse;
    gap: 4px;
    margin-bottom: clamp(12px, 3vh, 24px);
}

.logo-text {
    font-size: clamp(2.5rem, 8vh, 4rem);
    font-weight: 800;
    letter-spacing: -2px;
}

.tagline {
    font-size: 1.25rem;
    color: var(--color-text-dim);
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: clamp(20px, 4vh, 40px);
}

/* --- Buttons --- */
.btn-main,
.btn-secondary,
.btn-tertiary {
    width: 100%;
    padding: 16px 24px;
    border-radius: 16px;
    border: none;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: transform 0.2s;
}

.btn-main {
    background-color: var(--color-blue);
    color: white;
    box-shadow: 0 4px 0 #2563eb;
}

.btn-secondary {
    background-color: var(--color-tray);
    color: var(--color-text);
    box-shadow: 0 4px 0 #d1d5db;
}

.btn-tertiary {
    background-color: transparent;
    color: var(--color-text-dim);
    justify-content: center;
}

.btn-main:active,
.btn-secondary:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.btn-main.locked {
    background-color: #f3f4f6;
    color: #9ca3af;
    box-shadow: none;
    cursor: not-allowed;
}

.btn-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
}

.btn-title {
    font-size: 1.25rem;
}

.btn-subtitle {
    font-size: 0.875rem;
    font-weight: 400;
    opacity: 0.8;
}

/* --- Game Screen UI --- */
.game-header {
    text-align: center;
    padding: clamp(4px, 0.5vh, 12px) 0;
}

.level-indicator {
    color: var(--color-text-dim);
    font-weight: 600;
    letter-spacing: 1px;
}

.column-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    /* Allow shrinking */
}

.column {
    display: flex;
    flex-direction: column-reverse;
    gap: var(--block-gap);
    padding-bottom: 4px;
}

.platform {
    width: 100px;
    height: 12px;
    background-color: var(--color-platform);
    border-radius: 6px;
    margin: 0 auto;
    position: relative;
}

.platform::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 5%;
    width: 90%;
    height: 4px;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 0 0 10px 10px;
}

/* --- Build Controls --- */
.build-controls {
    padding: 1vh 0;
    flex-shrink: 0;
}

.undo-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: clamp(4px, 1vh, 12px);
}

.progress-text {
    font-weight: 600;
    color: var(--color-text-dim);
}

.undo-btn {
    background: none;
    border: none;
    color: var(--color-blue);
    font-weight: 700;
    cursor: pointer;
}

.undo-btn:disabled {
    color: #d1d5db;
    cursor: not-allowed;
}

.tray {
    background-color: var(--color-tray);
    padding: clamp(6px, 1.5vh, 16px);
    border-radius: 20px;
    margin-bottom: clamp(4px, 1vh, 10px);
}

.tray-hint {
    font-size: 0.75rem;
    color: var(--color-text-dim);
    margin-bottom: 8px;
    text-align: center;
}

.color-options {
    display: flex;
    justify-content: center;
    gap: clamp(8px, 2vw, 16px);
}

.btn-done {
    width: 100%;
    padding: clamp(12px, 2.5vh, 20px);
    background-color: var(--color-green);
    color: white;
    border: none;
    border-radius: 16px;
    font-weight: 800;
    font-size: 1.25rem;
    box-shadow: 0 4px 0 #166534;
    cursor: pointer;
}

.btn-done:disabled {
    background-color: #d1d5db;
    box-shadow: none;
    cursor: not-allowed;
}

/* --- Result Screen --- */
.result-header {
    text-align: center;
    padding: 40px 0;
}

.result-header h1 {
    font-size: 3rem;
    font-weight: 800;
}

.result-header h1.success {
    color: var(--color-green);
}

.result-header h1.failure {
    color: var(--color-red);
}

.level-status-pills {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 40px;
}

.pill {
    width: 60px;
    height: 40px;
    background-color: #f3f4f6;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #9ca3af;
}

.pill.pass {
    background-color: var(--color-green);
    color: white;
}

.pill.fail {
    background-color: var(--color-red);
    color: white;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* --- Review Screen --- */
.review-columns {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    margin: 20px 0;
    flex: 1;
}

.review-col {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.review-col h3 {
    font-size: 0.875rem;
    color: var(--color-text-dim);
    margin-bottom: 12px;
}

#modal-container {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

.modal {
    width: 100%;
    max-width: var(--container-max-width);
    background-color: white;
    border-radius: 32px 32px 0 0;
    padding: 24px;
    height: 90vh;
    height: 90svh;
    /* Modern mobile-friendly height */
    overflow-y: auto;
    position: relative;
    animation: slideUpModal 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-content {
    position: relative;
    padding-top: 10px;
}

.close-btn {
    position: sticky;
    top: -10px;
    /* Offset the modal padding slightly */
    float: right;
    background: #f3f4f6;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 18px;
    cursor: pointer;
    font-size: 24px;
    font-weight: 300;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    margin-bottom: -36px;
    /* Don't push down the header */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stats-summary {
    display: flex;
    gap: 20px;
    margin: 24px 0;
}

.stat-item {
    flex: 1;
    background-color: #f3f4f6;
    padding: 16px;
    border-radius: 16px;
    text-align: center;
}

.stat-val {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--color-text-dim);
    text-transform: uppercase;
}

.reach-chart {
    margin-bottom: 32px;
}

.chart-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.chart-row span {
    width: 20px;
    font-weight: 700;
}

.bar-container {
    flex: 1;
    height: 12px;
    background-color: #f3f4f6;
    border-radius: 6px;
    overflow: hidden;
}

.bar {
    height: 100%;
    background-color: var(--color-blue);
    border-radius: 6px;
}

.history-list {
    margin-bottom: 32px;
}

.history-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f3f4f6;
}

.history-date {
    font-weight: 600;
}

.history-pills {
    display: flex;
    gap: 4px;
}

.mini-pill {
    width: 24px;
    height: 16px;
    border-radius: 8px;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    background-color: #f3f4f6;
    color: #9ca3af;
}

.mini-pill.pass {
    background-color: var(--color-green);
    color: white;
}

.mini-pill.fail {
    background-color: var(--color-red);
    color: white;
}

/* --- Tutorial --- */
.tutorial-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
    justify-content: center;
}

.tutorial-step p {
    font-size: 1.5rem;
    font-weight: 800;
}

.tutorial-step .sub {
    font-size: 1rem;
    font-weight: 400;
    color: var(--color-text-dim);
}

.promo-link,
.promo-link-stats {
    color: var(--color-blue);
    font-weight: 600;
    text-decoration: none;
    text-align: center;
    display: block;
}

.header-actions {
    display: flex;
    justify-content: flex-end;
    padding-bottom: 20px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

/* --- Practice Setup --- */
.practice-setup-screen {
    padding-top: 20px;
}

.setup-title {
    font-size: 1.5rem;
    font-weight: 800;
}

.setup-group {
    margin-bottom: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.setup-label {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--color-text-dim);
    margin-bottom: 16px;
    letter-spacing: 1px;
}

.segmented-control {
    display: flex;
    background-color: #f3f4f6;
    padding: 4px;
    border-radius: 20px;
    width: 100%;
}

.segment {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 16px;
    background: none;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s;
}

.segment.active {
    background-color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.stepper {
    display: flex;
    align-items: center;
    gap: 32px;
}

.stepper-btn {
    width: 48px;
    height: 48px;
    border-radius: 24px;
    border: none;
    background-color: var(--color-blue);
    color: white;
    font-size: 1.5rem;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(66, 133, 244, 0.2);
}

.stepper-val {
    font-size: 4rem;
    font-weight: 800;
}

.preview-column {
    display: flex;
    flex-direction: column-reverse;
    gap: 4px;
}

.preview-column .block {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    box-shadow: none;
}

/* --- Share Section --- */
.share-section {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#share-text {
    width: 100%;
    height: 100px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--color-text);
    resize: none;
    outline: none;
    padding: 0;
}

.share-section .btn-main {
    box-shadow: none;
    justify-content: center;
}