/* ── Pipe Mania Theme ── */
:root {
    --pm-accent: #14B8A6;
    --pm-accent-light: #2DD4BF;
    --pm-accent-dark: #0D9488;
    --pm-bg: #0F1923;
    --pm-surface: #1A2736;
    --pm-surface-light: #243447;
    --pm-text: #E2E8F0;
    --pm-text-dim: #94A3B8;
    --pm-water: #06B6D4;
    --pm-water-glow: #22D3EE;
    --pm-pipe: #475569;
    --pm-pipe-connected: #14B8A6;
    --pm-danger: #EF4444;
    --pm-success: #22C55E;
}

/* ── Layout ── */
.pm-layout {
    display: flex;
    justify-content: center;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: calc(100vh - 80px);
}

.ad-slot { width: 160px; flex-shrink: 0; }
.ad-slot--left, .ad-slot--right { display: flex; align-items: flex-start; }
.ad-placeholder--vertical {
    width: 160px; height: 600px;
    background: var(--pm-surface);
    border: 1px dashed var(--pm-text-dim);
    display: flex; align-items: center; justify-content: center;
    color: var(--pm-text-dim); font-size: 12px; border-radius: 8px;
}

#pipemania-app {
    flex: 1;
    max-width: 700px;
    min-width: 320px;
}

/* ── Screens ── */
.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ── Header ── */
.pm-header {
    text-align: center;
    padding: 40px 0 30px;
}
.pm-logo { margin-bottom: 16px; }
.pm-logo-icon { width: 80px; height: 80px; }
.pm-header h1 {
    font-family: 'Syne', sans-serif;
    font-size: 3rem;
    font-weight: 800;
    color: var(--pm-accent);
    letter-spacing: 4px;
    margin: 0;
    text-shadow: 0 0 30px rgba(20, 184, 166, 0.3);
}
.subtitle {
    color: var(--pm-text-dim);
    font-size: 1rem;
    margin-top: 8px;
}

/* ── Cards ── */
.card {
    background: var(--pm-surface);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    border: 1px solid var(--pm-surface-light);
}
.card__title {
    font-family: 'Syne', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--pm-accent);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 12px;
}

/* ── Difficulty Grid ── */
.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.diff-btn {
    background: var(--pm-bg);
    border: 2px solid var(--pm-surface-light);
    border-radius: 10px;
    padding: 14px 8px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    color: var(--pm-text);
}
.diff-btn:hover { border-color: var(--pm-accent); background: var(--pm-surface-light); }
.diff-btn.selected { border-color: var(--pm-accent); background: rgba(20, 184, 166, 0.15); }
.diff-icon { display: block; font-size: 1.4rem; font-weight: 800; margin-bottom: 4px; color: var(--pm-accent); }
.diff-btn span:nth-child(2) { display: block; font-weight: 600; font-size: 0.9rem; }
.diff-desc { display: block; font-size: 0.75rem; color: var(--pm-text-dim); margin-top: 2px; }

/* ── Buttons ── */
.menu-actions { text-align: center; margin-top: 24px; }
.btn {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 1px;
}
.btn--primary {
    background: var(--pm-accent);
    color: #fff;
    padding: 14px 40px;
    font-size: 1.1rem;
}
.btn--primary:hover { background: var(--pm-accent-light); transform: translateY(-2px); box-shadow: 0 4px 20px rgba(20, 184, 166, 0.4); }
.btn--lg { font-size: 1.1rem; }
.btn--sm { padding: 8px 16px; font-size: 0.8rem; }
.btn--outline {
    background: transparent;
    color: var(--pm-accent);
    border: 2px solid var(--pm-accent);
    padding: 8px 20px;
}
.btn--outline:hover { background: rgba(20, 184, 166, 0.1); }
.btn--accent {
    background: var(--pm-accent);
    color: #fff;
    padding: 10px 24px;
}
.btn--accent:hover { background: var(--pm-accent-light); }
.btn--ghost {
    background: transparent;
    color: var(--pm-text-dim);
    padding: 10px 20px;
}
.btn--ghost:hover { color: var(--pm-accent); }

/* ── HUD ── */
#game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--pm-surface);
    border-radius: 12px;
    padding: 12px 20px;
    margin-bottom: 16px;
    border: 1px solid var(--pm-surface-light);
}
.hud__cell { text-align: left; }
.hud__cell--center { text-align: center; }
.hud__cell--right { text-align: right; }
.hud__label { display: block; font-size: 0.7rem; color: var(--pm-text-dim); text-transform: uppercase; letter-spacing: 1px; }
.hud__value { font-family: 'JetBrains Mono', monospace; font-size: 1.4rem; font-weight: 700; color: var(--pm-text); }
.hud__timer { color: var(--pm-accent); }
.hud__timer.danger { color: var(--pm-danger); animation: pulse 0.5s ease infinite alternate; }
@keyframes pulse { to { opacity: 0.5; } }

/* ── Pipe Grid ── */
.pm-board-area {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}
.pm-grid {
    display: grid;
    gap: 2px;
    background: var(--pm-bg);
    border: 3px solid var(--pm-surface-light);
    border-radius: 12px;
    padding: 8px;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.3);
}

.pipe-cell {
    width: 100%;
    aspect-ratio: 1;
    background: var(--pm-surface);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.pipe-cell:hover { background: var(--pm-surface-light); }
.pipe-cell.source { background: rgba(20, 184, 166, 0.2); cursor: default; }
.pipe-cell.drain { background: rgba(239, 68, 68, 0.2); cursor: default; }
.pipe-cell.connected .pipe-svg { stroke: var(--pm-water); filter: drop-shadow(0 0 4px var(--pm-water-glow)); }
.pipe-cell.water-flowing .pipe-svg { stroke: var(--pm-water-glow); filter: drop-shadow(0 0 8px var(--pm-water-glow)); }
.pipe-cell.rotating { animation: rotatePipe 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes rotatePipe {
    from { transform: rotate(-90deg); }
    to { transform: rotate(0deg); }
}

.pipe-svg {
    width: 80%;
    height: 80%;
    stroke: var(--pm-pipe);
    stroke-width: 8;
    stroke-linecap: round;
    fill: none;
    transition: stroke 0.4s, filter 0.4s;
}

.pipe-cell.source .pipe-svg,
.pipe-cell.drain .pipe-svg {
    stroke: var(--pm-accent);
}

/* Water flow animation */
.pipe-cell.water-flowing::after {
    content: '';
    position: absolute;
    inset: 20%;
    background: radial-gradient(circle, rgba(6, 182, 212, 0.3), transparent);
    border-radius: 50%;
    animation: waterPulse 1s ease infinite;
}
@keyframes waterPulse {
    0%, 100% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 1; }
}

/* ── Actions ── */
.pm-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* ── Result Card ── */
.result-card, .lb-card {
    background: var(--pm-surface);
    border-radius: 16px;
    padding: 40px 30px;
    text-align: center;
    border: 1px solid var(--pm-surface-light);
    max-width: 420px;
    margin: 60px auto;
}
.result-card h2, .lb-card h2 {
    font-family: 'Syne', sans-serif;
    font-size: 1.8rem;
    color: var(--pm-accent);
    margin: 0 0 20px;
    letter-spacing: 3px;
}
.result-score {
    font-family: 'JetBrains Mono', monospace;
    font-size: 3rem;
    font-weight: 700;
    color: var(--pm-text);
    margin-bottom: 8px;
}
.result-detail {
    color: var(--pm-text-dim);
    font-size: 0.9rem;
    margin-bottom: 20px;
}
#nickname {
    width: 100%;
    max-width: 280px;
    padding: 10px 16px;
    background: var(--pm-bg);
    border: 2px solid var(--pm-surface-light);
    border-radius: 8px;
    color: var(--pm-text);
    font-size: 1rem;
    text-align: center;
    outline: none;
    margin-bottom: 16px;
}
#nickname:focus { border-color: var(--pm-accent); }
.result-actions { display: flex; justify-content: center; gap: 12px; margin-bottom: 12px; }

/* ── Leaderboard ── */
#leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 20px 0;
}
#leaderboard-list li {
    display: flex;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--pm-surface-light);
    color: var(--pm-text);
    font-family: 'JetBrains Mono', monospace;
}
#leaderboard-list li:first-child { color: var(--pm-accent); font-weight: 700; }

/* ── Responsive ── */
@media (max-width: 900px) {
    .ad-slot--left, .ad-slot--right { display: none; }
    .pm-layout { padding: 10px; }
}
@media (max-width: 500px) {
    .pm-header h1 { font-size: 2rem; }
    .difficulty-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .diff-btn { padding: 10px 4px; }
    #game-hud { padding: 8px 12px; }
    .hud__value { font-size: 1.1rem; }
}
