/* ============================================
   RESONANCE - Geometric Puzzle Game
   Fully Responsive Mobile-First Styles
   ============================================ */

/* CSS Variables */
:root {
    --bg-cream: #FFF8F0;
    --bg-light: #FFFFFF;
    --bg-dark: #F5EDE5;
    --coral: #FF8A80;
    --coral-light: #FFCCBC;
    --coral-dark: #FF5252;
    --mint: #A5D6A7;
    --mint-light: #C8E6C9;
    --sky: #81D4FA;
    --sky-light: #B3E5FC;
    --lavender: #CE93D8;
    --lavender-light: #E1BEE7;
    --text-dark: #424242;
    --text-medium: #757575;
    --text-light: #9E9E9E;
    --shadow-soft: rgba(0, 0, 0, 0.08);
    --shadow-medium: rgba(0, 0, 0, 0.12);
    --danger: #EF5350;

    /* Safe areas */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    font-size: 16px;
    height: 100%;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-cream);
    color: var(--text-dark);
    min-height: 100%;
    width: 100%;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    position: relative;
    overflow: hidden;
}

/* ============================================
   SCREENS - Base
   ============================================ */

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-cream);
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    overflow: hidden;
}

.screen.hidden {
    display: none !important;
}

/* Screen Header */
.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-light);
    border-bottom: 1px solid var(--bg-dark);
    flex-shrink: 0;
    min-height: 56px;
}

.screen-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-dark);
    text-align: center;
    flex: 1;
}

.header-spacer {
    width: 40px;
    flex-shrink: 0;
}

/* ============================================
   LOADING SCREEN
   ============================================ */

.loading-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-cream) 0%, var(--bg-light) 100%);
}

.loading-content {
    text-align: center;
    padding: 20px;
    width: 100%;
    max-width: 300px;
}

.loading-logo {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
}

.loading-shape {
    width: 32px;
    height: 32px;
    animation: loadingBounce 1.2s ease-in-out infinite;
}

.loading-shape.circle {
    background: var(--coral);
    border-radius: 50%;
    animation-delay: 0s;
}

.loading-shape.triangle {
    width: 0;
    height: 0;
    background: transparent;
    border-left: 16px solid transparent;
    border-right: 16px solid transparent;
    border-bottom: 28px solid var(--mint);
    animation-delay: 0.2s;
}

.loading-shape.square {
    background: var(--sky);
    border-radius: 4px;
    animation-delay: 0.4s;
}

@keyframes loadingBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-16px); }
}

.loading-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 4px;
    background: linear-gradient(135deg, var(--coral), var(--lavender));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 24px;
}

.loading-bar {
    width: 100%;
    max-width: 180px;
    height: 4px;
    background: var(--bg-dark);
    border-radius: 2px;
    margin: 0 auto;
    overflow: hidden;
}

.loading-progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--coral), var(--lavender));
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* ============================================
   START SCREEN
   ============================================ */

.start-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(180deg, var(--bg-cream) 0%, var(--bg-light) 100%);
    padding: 16px;
}

.start-content {
    text-align: center;
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.start-logo {
    margin-bottom: 16px;
}

.logo-svg {
    width: min(35vw, 130px);
    height: min(35vw, 130px);
}

.start-title {
    font-size: clamp(1.75rem, 8vw, 2.5rem);
    font-weight: 800;
    letter-spacing: 0.3em;
    background: linear-gradient(135deg, var(--coral), var(--sky), var(--lavender));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.start-subtitle {
    font-size: 0.875rem;
    color: var(--text-medium);
    margin-bottom: 32px;
    letter-spacing: 2px;
}

.start-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    margin-bottom: 32px;
}

.start-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    font-size: 0.9rem;
    color: var(--text-medium);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ============================================
   LEVEL SELECT SCREEN
   ============================================ */

.level-select-screen {
    background: var(--bg-light);
}

.level-grid-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 400px;
    margin: 0 auto;
}

.level-item {
    aspect-ratio: 1;
    background: var(--bg-cream);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    border: 2px solid transparent;
    position: relative;
    min-height: 60px;
}

.level-item:active {
    transform: scale(0.95);
}

.level-item.unlocked {
    background: var(--bg-light);
    border-color: var(--bg-dark);
}

.level-item.current {
    border-color: var(--coral);
    background: var(--coral-light);
}

.level-item.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.level-number {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-dark);
}

.level-item.locked .level-number {
    color: var(--text-light);
}

.level-item.locked::after {
    content: '🔒';
    position: absolute;
    font-size: 0.625rem;
    top: 4px;
    right: 4px;
}

.level-stars {
    font-size: 0.5rem;
    margin-top: 2px;
    letter-spacing: 0;
}

/* ============================================
   SETTINGS SCREEN
   ============================================ */

.settings-screen {
    background: var(--bg-light);
}

.settings-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
}

.setting-label {
    font-size: 0.9375rem;
    color: var(--text-dark);
}

.setting-divider {
    height: 1px;
    background: var(--bg-dark);
    margin: 8px 0;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-dark);
    border-radius: 26px;
    transition: 0.3s;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 2px 4px var(--shadow-medium);
}

.toggle input:checked + .toggle-slider {
    background: var(--coral);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.about-section {
    margin-top: 24px;
    text-align: center;
}

.about-text {
    font-size: 0.8125rem;
    color: var(--text-light);
    margin-bottom: 4px;
}

/* ============================================
   GAME SCREEN
   ============================================ */

.game-screen {
    background: var(--bg-cream);
}

.game-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 0 12px;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    flex-shrink: 0;
}

.header-center {
    flex: 1;
    text-align: center;
}

.level-display {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
}

.level-display span {
    color: var(--coral);
}

.score-display {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-medium);
    min-width: 50px;
    text-align: right;
}

.score-display span {
    color: var(--lavender);
}

/* Level Info */
.level-info {
    text-align: center;
    padding: 8px 12px;
    background: var(--bg-light);
    border-radius: 10px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.level-info p {
    color: var(--text-medium);
    font-size: 0.8125rem;
    line-height: 1.3;
}

/* Game Area */
.game-area {
    position: relative;
    background: var(--bg-light);
    border-radius: 12px;
    margin-bottom: 10px;
    overflow: hidden;
    flex: 1;
    min-height: 0;
    box-shadow: 0 2px 8px var(--shadow-soft);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    touch-action: none;
}

/* Resonance Overlay */
.resonance-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 248, 240, 0.95);
    pointer-events: none;
}

.resonance-overlay.hidden {
    display: none;
}

.resonance-text {
    font-size: clamp(1.5rem, 8vw, 2.25rem);
    font-weight: 800;
    letter-spacing: 4px;
    background: linear-gradient(135deg, var(--coral), var(--sky), var(--mint), var(--lavender));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: resonancePulse 0.6s ease-out;
}

@keyframes resonancePulse {
    0% { opacity: 0; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.05); }
    100% { opacity: 1; transform: scale(1); }
}

/* Shape Palette */
.shape-palette {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-light);
    border-radius: 12px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.palette-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-medium);
    white-space: nowrap;
}

.shapes-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}

.shape-item {
    width: 44px;
    height: 44px;
    background: var(--bg-cream);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: grab;
    box-shadow: 0 2px 6px var(--shadow-soft);
    transition: transform 0.15s ease;
    position: relative;
    touch-action: none;
}

.shape-item:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.shape-item.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.shape-item svg {
    width: 26px;
    height: 26px;
    pointer-events: none;
}

.shape-count {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--coral);
    color: white;
    font-size: 0.625rem;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Game Controls */
.game-controls {
    display: flex;
    gap: 10px;
    padding-bottom: 12px;
    flex-shrink: 0;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    outline: none;
    width: 100%;
}

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

.btn-icon {
    font-size: 1rem;
}

.btn-large {
    padding: 14px 24px;
    font-size: 1rem;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.8125rem;
    width: auto;
}

.btn-primary {
    background: linear-gradient(135deg, var(--coral), var(--coral-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(255, 138, 128, 0.35);
}

.btn-secondary {
    background: var(--bg-light);
    color: var(--text-dark);
    border: 2px solid var(--bg-dark);
}

.btn-reset, .btn-hint {
    background: var(--bg-light);
    color: var(--text-medium);
    flex: 1;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-back {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-cream);
    border-radius: 10px;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dark);
    flex-shrink: 0;
}

.btn-back:active {
    transform: scale(0.95);
    background: var(--bg-dark);
}

/* ============================================
   MODALS
   ============================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 16px;
}

.modal.hidden {
    display: none !important;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--bg-light);
    padding: 24px 20px;
    border-radius: 20px;
    text-align: center;
    width: 100%;
    max-width: 300px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-small {
    max-width: 280px;
    padding: 20px 16px;
}

.modal-content h2 {
    font-size: 1.25rem;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.modal-content p {
    color: var(--text-medium);
    margin-bottom: 8px;
    font-size: 0.875rem;
}

.modal-subtitle {
    margin-bottom: 16px !important;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-buttons .btn {
    flex: 1;
}

.modal-stars {
    font-size: 2rem;
    margin-bottom: 12px;
    display: flex;
    justify-content: center;
    gap: 6px;
}

.modal-stars .star {
    display: inline-block;
    animation: starPop 0.4s ease-out backwards;
}

.modal-stars .star:nth-child(1) { animation-delay: 0.1s; }
.modal-stars .star:nth-child(2) { animation-delay: 0.2s; }
.modal-stars .star:nth-child(3) { animation-delay: 0.3s; }

.modal-stars .star.empty {
    opacity: 0.3;
    filter: grayscale(1);
}

@keyframes starPop {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

.completion-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.final-score {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--lavender) !important;
    margin-top: 12px !important;
}

/* ============================================
   DRAG GHOST
   ============================================ */

.drag-ghost {
    position: fixed;
    pointer-events: none;
    opacity: 0.9;
    z-index: 1000;
    transform: translate(-50%, -50%) scale(1.2);
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.2));
}

/* ============================================
   RESPONSIVE - Small Phones (320px - 360px)
   ============================================ */

@media (max-width: 360px) {
    .loading-title {
        font-size: 1.5rem;
        letter-spacing: 3px;
    }

    .start-title {
        font-size: 1.5rem;
        letter-spacing: 0.2em;
    }

    .logo-svg {
        width: 100px;
        height: 100px;
    }

    .start-subtitle {
        font-size: 0.75rem;
        margin-bottom: 24px;
    }

    .start-buttons {
        gap: 8px;
        margin-bottom: 24px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.875rem;
    }

    .btn-large {
        padding: 12px 20px;
    }

    .level-grid {
        gap: 8px;
    }

    .level-item {
        border-radius: 10px;
        min-height: 55px;
    }

    .level-number {
        font-size: 1.125rem;
    }

    .level-stars {
        font-size: 0.4375rem;
    }

    .game-container {
        padding: 0 8px;
    }

    .shape-item {
        width: 40px;
        height: 40px;
    }

    .shape-item svg {
        width: 22px;
        height: 22px;
    }

    .level-info p {
        font-size: 0.75rem;
    }

    .resonance-text {
        font-size: 1.25rem;
        letter-spacing: 2px;
    }
}

/* ============================================
   RESPONSIVE - Medium Phones (361px - 400px)
   ============================================ */

@media (min-width: 361px) and (max-width: 400px) {
    .logo-svg {
        width: 120px;
        height: 120px;
    }

    .start-title {
        font-size: 1.875rem;
    }
}

/* ============================================
   RESPONSIVE - Large Phones (401px - 480px)
   ============================================ */

@media (min-width: 401px) {
    .level-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 12px;
    }

    .shape-item {
        width: 48px;
        height: 48px;
    }

    .shape-item svg {
        width: 28px;
        height: 28px;
    }
}

/* ============================================
   RESPONSIVE - Short Screens (height < 600px)
   ============================================ */

@media (max-height: 600px) {
    .start-content {
        transform: scale(0.9);
    }

    .logo-svg {
        width: 80px;
        height: 80px;
    }

    .start-subtitle {
        margin-bottom: 20px;
    }

    .start-buttons {
        margin-bottom: 20px;
    }

    .level-info {
        padding: 6px 10px;
        margin-bottom: 8px;
    }

    .level-info p {
        font-size: 0.75rem;
    }

    .shape-palette {
        padding: 8px 10px;
        margin-bottom: 8px;
    }

    .shape-item {
        width: 38px;
        height: 38px;
    }

    .shape-item svg {
        width: 22px;
        height: 22px;
    }

    .game-controls {
        padding-bottom: 8px;
    }

    .btn-reset, .btn-hint {
        padding: 10px 16px;
        font-size: 0.8125rem;
    }
}

/* ============================================
   RESPONSIVE - Very Short Screens (height < 500px)
   ============================================ */

@media (max-height: 500px) {
    .level-info {
        display: none;
    }

    .game-header {
        padding: 6px 0;
    }

    .shape-palette {
        padding: 6px 8px;
    }

    .shapes-container {
        gap: 6px;
    }

    .shape-item {
        width: 36px;
        height: 36px;
    }

    .shape-item svg {
        width: 20px;
        height: 20px;
    }
}

/* ============================================
   RESPONSIVE - Tablets (min-width: 600px)
   ============================================ */

@media (min-width: 600px) {
    .start-content {
        max-width: 400px;
    }

    .logo-svg {
        width: 160px;
        height: 160px;
    }

    .start-title {
        font-size: 2.5rem;
    }

    .start-subtitle {
        font-size: 1rem;
    }

    .btn {
        padding: 14px 24px;
        font-size: 1rem;
    }

    .btn-large {
        padding: 16px 32px;
        font-size: 1.125rem;
    }

    .level-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 16px;
        max-width: 500px;
    }

    .level-item {
        border-radius: 16px;
    }

    .level-number {
        font-size: 1.5rem;
    }

    .game-container {
        max-width: 550px;
        padding: 0 20px;
    }

    .shape-item {
        width: 52px;
        height: 52px;
    }

    .shape-item svg {
        width: 30px;
        height: 30px;
    }

    .modal-content {
        max-width: 360px;
        padding: 32px 28px;
    }

    .modal-content h2 {
        font-size: 1.5rem;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
