/* =============================================
   AMAZEING - Main Styles
   ============================================= */

/* CSS Custom Properties */
:root {
    /* Base colors (overridden by themes) */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;

    /* Grid */
    --grid-gap: 2px;
    --cell-size: 48px;
    --cell-bg: rgba(255, 255, 255, 0.1);
    --cell-border: rgba(255, 255, 255, 0.2);

    /* Interactive states */
    --hover-bg: rgba(255, 255, 255, 0.2);
    --active-bg: rgba(255, 255, 255, 0.3);
    --error-bg: rgba(255, 100, 100, 0.4);
    --hint-bg: rgba(255, 255, 0, 0.3);

    /* Points */
    --point-size: 32px;
    --point-bg: #ffffff;
    --point-color: #1a1a2e;
    --point-connected-bg: #4CAF50;

    /* Buttons */
    --btn-bg: rgba(255, 255, 255, 0.15);
    --btn-hover: rgba(255, 255, 255, 0.25);
    --btn-radius: 12px;

    /* Shadows and effects */
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px currentColor;
}

/* Reset and base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Background layer */
.background {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-size: cover;
    background-position: center;
    transition: background 0.5s ease, opacity 0.5s ease;
}

/* App container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
    padding: 12px 16px;
    position: relative;
    z-index: 1;
}

/* =============================================
   HEADER
   ============================================= */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    flex-shrink: 0;
}

.header-left,
.header-right {
    flex: 0 0 60px;
}

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

.timer {
    font-size: 1.25rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.level-name {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
}

.theme-indicator {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    opacity: 0.8;
    margin-top: 2px;
}

.theme-emoji {
    font-size: 1rem;
}

.icon-btn {
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--btn-bg);
    border: none;
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

.icon-btn:hover {
    background: var(--btn-hover);
}

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

/* =============================================
   GAME MAIN AREA
   ============================================= */
.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px 0;
}

/* Pattern Preview */
.pattern-preview {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    opacity: 0.9;
}

.pattern-preview canvas {
    width: 48px;
    height: 48px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    image-rendering: pixelated;
}

.preview-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
}

/* Grid Wrapper */
.grid-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Grid Container */
.grid-container {
    display: grid;
    gap: var(--grid-gap);
    background: rgba(0, 0, 0, 0.4);
    padding: var(--grid-gap);
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
}

/* Dynamic grid sizes */
.grid-container[data-size="6"] {
    grid-template-columns: repeat(6, var(--cell-size));
    grid-template-rows: repeat(6, var(--cell-size));
}

.grid-container[data-size="8"] {
    grid-template-columns: repeat(8, var(--cell-size));
    grid-template-rows: repeat(8, var(--cell-size));
}

.grid-container[data-size="10"] {
    grid-template-columns: repeat(10, var(--cell-size));
    grid-template-rows: repeat(10, var(--cell-size));
}

.grid-container[data-size="12"] {
    grid-template-columns: repeat(12, var(--cell-size));
    grid-template-rows: repeat(12, var(--cell-size));
}

/* Grid Cells */
.cell {
    background: var(--cell-bg);
    border: 1px solid var(--cell-border);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
    cursor: pointer;
}

.cell:hover {
    background: var(--hover-bg);
}

.cell.occupied {
    /* Path passes through this cell */
}

.cell.invalid {
    background: var(--error-bg) !important;
    animation: shake 0.3s ease;
}

.cell.hint {
    background: var(--hint-bg) !important;
    animation: pulse-hint 1s ease infinite;
}

.cell.highlight {
    background: var(--hover-bg);
}

/* Obstacle cells */
.cell.obstacle {
    background: rgba(40, 40, 40, 0.9);
    border-color: rgba(60, 60, 60, 0.8);
    cursor: not-allowed;
}

.cell.obstacle:hover {
    background: rgba(40, 40, 40, 0.9);
}

/* Path Canvas Overlay */
.path-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 5;
}

/* Points Overlay */
.points-overlay {
    position: absolute;
    top: 0;
    left: 0;
    display: grid;
    pointer-events: none;
    padding: var(--grid-gap);
    gap: var(--grid-gap);
}

.points-overlay[data-size="6"] {
    grid-template-columns: repeat(6, var(--cell-size));
    grid-template-rows: repeat(6, var(--cell-size));
}

.points-overlay[data-size="8"] {
    grid-template-columns: repeat(8, var(--cell-size));
    grid-template-rows: repeat(8, var(--cell-size));
}

.points-overlay[data-size="10"] {
    grid-template-columns: repeat(10, var(--cell-size));
    grid-template-rows: repeat(10, var(--cell-size));
}

.points-overlay[data-size="12"] {
    grid-template-columns: repeat(12, var(--cell-size));
    grid-template-rows: repeat(12, var(--cell-size));
}

/* Numbered Points */
.point {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 700;
    background: var(--point-bg);
    color: var(--point-color);
    border-radius: 50%;
    width: var(--point-size);
    height: var(--point-size);
    margin: auto;
    box-shadow: var(--shadow-soft);
    z-index: 10;
    transition: background 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
}

.point.connected {
    background: var(--point-connected-bg);
    color: #fff;
}

.point.active {
    animation: pulse-point 1.5s ease infinite;
    box-shadow: var(--shadow-soft), 0 0 15px var(--point-bg);
}

.point.current {
    transform: scale(1.1);
    box-shadow: var(--shadow-soft), 0 0 20px var(--point-bg);
}

/* =============================================
   CONTROLS
   ============================================= */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 16px 0 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 20px;
    background: var(--btn-bg);
    border: none;
    border-radius: var(--btn-radius);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    min-width: 70px;
}

.control-btn:hover {
    background: var(--btn-hover);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-label {
    font-size: 0.75rem;
    opacity: 0.9;
}

/* =============================================
   MODALS
   ============================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 20px;
}

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

.modal {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 24px;
    max-width: 90%;
    width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-soft);
    animation: modal-appear 0.3s ease;
}

.modal.hidden {
    display: none;
}

.modal h2 {
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.5rem;
}

.modal-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Win Modal */
.final-artwork {
    display: grid;
    gap: 0;
    justify-content: center;
    margin: 16px 0;
    font-size: 1.25rem;
    line-height: 1;
}

.win-stats {
    text-align: center;
    font-size: 1rem;
    opacity: 0.8;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.primary-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.primary-btn:hover {
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.primary-btn:active {
    transform: scale(0.98);
}

.secondary-btn {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Menu Modal */
.menu-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.menu-btn {
    width: 100%;
    padding: 14px;
    background: var(--btn-bg);
    border: none;
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.menu-btn:hover {
    background: var(--btn-hover);
}

/* Level Select */
.pack-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.pack-tab {
    flex: 1;
    min-width: 80px;
    padding: 10px 8px;
    background: var(--btn-bg);
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pack-tab:hover {
    background: var(--btn-hover);
}

.pack-tab.active {
    background: var(--btn-hover);
    border-color: var(--point-bg);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
}

.level-btn {
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--btn-bg);
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.level-btn:hover {
    background: var(--btn-hover);
}

.level-btn.completed {
    background: rgba(76, 175, 80, 0.3);
    border-color: #4CAF50;
}

.level-btn.current {
    border-color: var(--point-bg);
}

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

/* Theme Select */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.theme-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px;
    background: var(--btn-bg);
    border: 2px solid transparent;
    border-radius: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-btn:hover {
    background: var(--btn-hover);
}

.theme-btn.active {
    border-color: var(--point-bg);
    background: var(--btn-hover);
}

.theme-preview {
    font-size: 2rem;
}

/* =============================================
   DIFFICULTY OPTIONS
   ============================================= */
.difficulty-options {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 8px 0 12px;
    flex-wrap: wrap;
}

.difficulty-btn {
    padding: 8px 16px;
    background: var(--btn-bg);
    border: 2px solid transparent;
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.difficulty-btn:hover {
    background: var(--btn-hover);
}

.difficulty-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
    color: white;
}

.new-random-btn {
    padding: 8px 20px;
    background: linear-gradient(135deg, #4CAF50 0%, #2E7D32 100%);
    border: none;
    border-radius: 20px;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.new-random-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.new-random-btn:active {
    transform: scale(0.98);
}
