/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --text-primary: #e8e8f0;
    --text-secondary: #a0a0b8;
    --accent-primary: #4facfe;
    --accent-secondary: #00f2fe;
    --accent-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --danger: #ff6b6b;
    --success: #51cf66;
    --warning: #ffd43b;
    --border-radius: 12px;
    --border-radius-lg: 20px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* ===== SCREENS ===== */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.screen.active {
    display: flex;
}

.screen.overlay {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 100;
}

/* ===== START SCREEN ===== */
.start-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(79, 172, 254, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(0, 242, 254, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(255, 107, 107, 0.1) 0%, transparent 50%),
        var(--bg-primary);
    animation: bgShift 8s ease-in-out infinite alternate;
}

@keyframes bgShift {
    0% { opacity: 1; }
    50% { opacity: 0.8; }
    100% { opacity: 1; }
}

.start-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
    padding: 20px;
}

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

#logo-canvas {
    width: 140px;
    height: 140px;
    filter: drop-shadow(0 0 20px rgba(79, 172, 254, 0.3));
}

.game-title {
    font-size: 52px;
    font-weight: 900;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -2px;
    line-height: 1.1;
}

.game-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 300;
    letter-spacing: 4px;
}

.start-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 240px;
}

.start-bottom-row {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
}

.highscore-display {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ===== BUTTONS ===== */
.btn {
    border: none;
    outline: none;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: 16px;
    font-weight: 500;
    border-radius: var(--border-radius);
    padding: 14px 28px;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

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

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
}

.btn-primary:active {
    box-shadow: 0 2px 8px rgba(79, 172, 254, 0.2);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.1);
}

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

.btn-icon, .btn-icon-sm {
    background: rgba(255,255,255,0.08);
    color: var(--text-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon {
    width: 48px;
    height: 48px;
    padding: 0;
}

.btn-icon-sm {
    width: 40px;
    height: 40px;
    padding: 0;
}

/* ===== GAME SCREEN ===== */
#screen-game {
    justify-content: flex-start;
    background: var(--bg-primary);
}

.game-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    padding-top: calc(8px + var(--safe-top));
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    z-index: 10;
}

.header-left, .header-right {
    width: 80px;
    display: flex;
}

.header-right {
    justify-content: flex-end;
}

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

.level-badge {
    background: var(--accent-gradient);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
}

.score-display {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.game-info-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
    background: rgba(26, 26, 46, 0.8);
    font-size: 13px;
    color: var(--text-secondary);
}

.target-display {
    display: flex;
    align-items: center;
    gap: 6px;
}

.combo-display {
    font-weight: 700;
    color: var(--warning);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.combo-display.visible {
    opacity: 1;
}

.game-canvas-wrapper {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 8px;
    overflow: hidden;
}

#game-canvas {
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-md);
    touch-action: none;
}

.next-marble-container {
    position: absolute;
    top: 12px;
    right: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: rgba(22, 33, 62, 0.9);
    padding: 8px;
    border-radius: var(--border-radius);
    border: 1px solid rgba(255,255,255,0.05);
}

.next-label {
    font-size: 11px;
    color: var(--text-secondary);
}

#next-canvas {
    width: 40px;
    height: 40px;
}

.game-progress {
    width: 100%;
    height: 4px;
    background: var(--bg-secondary);
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    transition: width 0.5s ease;
    border-radius: 0 2px 2px 0;
}

/* ===== MODAL ===== */
.modal {
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    padding: 32px 28px;
    width: min(90vw, 340px);
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255,255,255,0.05);
    text-align: center;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 24px;
}

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

/* ===== GAME OVER ===== */
.gameover-modal {
    overflow: hidden;
}

.gameover-title {
    font-size: 28px;
    color: var(--danger);
}

.gameover-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 24px 0;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.new-record {
    font-size: 18px;
    font-weight: 700;
    color: var(--warning);
    animation: recordPulse 0.6s ease infinite alternate;
    margin-bottom: 8px;
}

@keyframes recordPulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

/* ===== SETTINGS ===== */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 4px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 15px;
}

.setting-item:last-child {
    border-bottom: none;
}

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

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.15);
    border-radius: 28px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s;
}

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

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

/* ===== TUTORIAL ===== */
.tutorial-container {
    width: min(90vw, 340px);
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    padding: 32px 28px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255,255,255,0.05);
    animation: modalIn 0.3s ease;
}

.tutorial-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.tutorial-image {
    width: 200px;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tutorial-image canvas {
    max-width: 100%;
    max-height: 100%;
}

.tutorial-text {
    font-size: 15px;
    line-height: 1.6;
    text-align: center;
    color: var(--text-primary);
}

.tutorial-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
}

.tutorial-dots {
    display: flex;
    gap: 8px;
}

.tutorial-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    transition: all 0.3s ease;
}

.tutorial-dot.active {
    background: var(--accent-primary);
    width: 20px;
    border-radius: 4px;
}

#btn-tutorial-next {
    width: 100%;
}

/* ===== LEVEL UP NOTIFICATION ===== */
.levelup-notification {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    z-index: 200;
    pointer-events: none;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.levelup-notification.show {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

.levelup-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: rgba(15, 15, 35, 0.95);
    padding: 32px 48px;
    border-radius: var(--border-radius-lg);
    border: 2px solid var(--accent-primary);
    box-shadow: 0 0 40px rgba(79, 172, 254, 0.3);
}

.levelup-text {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--accent-secondary);
}

.levelup-level {
    font-size: 40px;
    font-weight: 900;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.levelup-unlock {
    font-size: 13px;
    color: var(--warning);
    margin-top: 4px;
}

/* ===== COMBO NOTIFICATION ===== */
.combo-notification {
    position: fixed;
    top: 30%;
    left: 50%;
    transform: translateX(-50%) scale(0);
    z-index: 150;
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-size: 32px;
    font-weight: 900;
    color: var(--warning);
    text-shadow: 0 0 20px rgba(255, 212, 59, 0.5);
}

.combo-notification.show {
    transform: translateX(-50%) scale(1);
    opacity: 1;
}

/* ===== PRIVACY ===== */
.privacy-modal {
    max-height: 80vh;
    overflow-y: auto;
}

.privacy-content {
    text-align: left;
    font-size: 13px;
    line-height: 1.8;
    color: var(--text-secondary);
    max-height: 50vh;
    overflow-y: auto;
    padding: 16px 0;
}

.privacy-content h3 {
    font-size: 15px;
    color: var(--text-primary);
    margin-top: 16px;
    margin-bottom: 8px;
}

.privacy-content p {
    margin-bottom: 8px;
}

/* ===== MIX GUIDE ===== */
.mixguide-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(79, 172, 254, 0.15);
    border: 1px solid rgba(79, 172, 254, 0.3);
    color: var(--accent-primary);
    font-family: var(--font-family);
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.mixguide-btn:active {
    transform: scale(0.95);
    background: rgba(79, 172, 254, 0.25);
}

.mixguide-modal {
    max-height: 85vh;
    overflow-y: auto;
}

.mixguide-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 16px 0;
}

.mixguide-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 14px;
}

.mix-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-block;
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), 0 1px 3px rgba(0,0,0,0.3);
}

.mix-plus, .mix-eq {
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 16px;
}

.mixguide-specials {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.mixguide-specials h3 {
    font-size: 14px;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.special-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 6px 0;
}

.special-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.rainbow-icon {
    background: conic-gradient(#ff4757, #ffd32a, #2ed573, #3742fa, #a55eea, #ff4757);
}

.bomb-icon {
    background: radial-gradient(circle at 40% 40%, #555, #222);
    box-shadow: 0 0 4px rgba(255, 100, 50, 0.5);
}

.star-icon {
    background: radial-gradient(circle at 40% 40%, #fff6a0, #f9ca24, #e0a500);
    box-shadow: 0 0 6px rgba(249, 202, 36, 0.5);
}

.stone-icon {
    background: radial-gradient(circle at 40% 40%, #999, #666, #444);
}

/* ===== MIX PREVIEW TOAST ===== */
.mix-preview-toast {
    position: fixed;
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: rgba(15, 15, 35, 0.92);
    border: 1px solid rgba(79, 172, 254, 0.3);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    font-family: var(--font-family);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    z-index: 50;
    white-space: nowrap;
}

.mix-preview-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.mix-preview-toast .mix-circle {
    width: 16px;
    height: 16px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 360px) {
    .game-title { font-size: 42px; }
    .score-display { font-size: 24px; }
    .modal { padding: 24px 20px; }
}

@media (min-width: 768px) {
    .game-canvas-wrapper {
        max-width: 420px;
        margin: 0 auto;
    }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes ripple {
    0% { transform: scale(0); opacity: 0.6; }
    100% { transform: scale(2.5); opacity: 0; }
}

.btn::after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%);
    transform: scale(0);
    opacity: 0;
    border-radius: inherit;
}

.btn:active::after {
    animation: ripple 0.5s ease;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 4px;
}
