* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

button, input, select, textarea {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(180deg, #f0f4ff 0%, #dce6f9 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.screen {
    width: 100%;
    max-width: 500px;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   SHARED
   ============================================================ */
.coin-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd54f, #ffb300);
    color: #7b5800;
    font-size: 0.7em;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.4);
    flex-shrink: 0;
}

.coins-value {
    font-weight: 700;
    color: #ffc107;
}

/* ============================================================
   HOME SCREEN
   ============================================================ */
#home-screen {
    position: relative;
    align-items: center;
}

.home-inner {
    position: relative;
    z-index: 1;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    padding: 20px 30px 40px;
}

.home-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    width: 100%;
}

.home-coins {
    background: rgba(0,0,0,0.06);
    color: #5a4a30;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 1em;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.home-coins .coins-value {
    color: #b8860b;
}

.home-settings {
    background: rgba(0,0,0,0.06);
    border: none;
    color: #6b7b8d;
    font-size: 1.4em;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.home-settings:hover { background: rgba(0,0,0,0.1); }

.home-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: auto;
    padding-bottom: 20px;
}

.lives-icon { color: #ef5350; }
.lives-value { font-weight: 700; }

/* Logo banner */
.home-logo {
    margin: auto 0;
    padding: 30px 0;
}

.logo-icon {
    font-size: 4em;
    line-height: 1;
    margin-bottom: 12px;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));
}

.logo-banner {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    background: white;
    padding: 16px 40px 20px;
    border-radius: 18px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06);
}

.logo-word {
    font-size: 2.6em;
    font-weight: 800;
    color: #3a3a3a;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.logo-sort {
    font-size: 1.3em;
    font-weight: 700;
    color: #5c6bc0;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-top: 2px;
}

.btn-play {
    -webkit-appearance: none;
    appearance: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 auto;
    background: linear-gradient(180deg, #7c4dff 0%, #651fff 100%);
    color: white;
    border: none;
    border-bottom: 5px solid #4a148c;
    padding: 16px 60px;
    border-radius: 18px;
    font-size: 1.5em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 6px 20px rgba(101,31,255,0.35);
}
.btn-play-label {
    display: block;
    line-height: 1.2;
}
.btn-play-level {
    display: block;
    font-size: 0.5em;
    font-weight: 600;
    opacity: 0.85;
    margin-top: 2px;
}

.btn-play:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(101,31,255,0.5);
}

.btn-play:active {
    transform: translateY(2px);
    border-bottom-width: 2px;
    box-shadow: 0 2px 8px rgba(101,31,255,0.3);
}

.btn-shop {
    margin-top: 14px;
    background: transparent;
    border: 2px solid rgba(0,0,0,0.12);
    color: #7a6a50;
    padding: 10px 28px;
    border-radius: 12px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-shop:active { background: rgba(0,0,0,0.04); }

.home-dev-levels {
    margin-top: 16px;
    background: transparent;
    border: 1px solid rgba(0,0,0,0.1);
    color: rgba(0,0,0,0.35);
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 0.85em;
    cursor: pointer;
}
.home-dev-levels:active {
    background: rgba(0,0,0,0.04);
}

/* ============================================================
   LEVEL MAP
   ============================================================ */
#level-map {
    background: linear-gradient(180deg, #5c6bc0 0%, #7986cb 50%, #c5cae9 100%);
}

.map-header {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    gap: 12px;
    background: rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 10;
}

.map-back-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 1.3em;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.map-back-btn:hover { background: rgba(255,255,255,0.3); }

.map-title {
    flex: 1;
    color: white;
    font-size: 1.3em;
    font-weight: 700;
}

.map-coins {
    background: rgba(0,0,0,0.2);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.map-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0 40px;
    -webkit-overflow-scrolling: touch;
}

.level-path {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 0 20px;
    position: relative;
}

.level-path::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    background: rgba(255,255,255,0.2);
    transform: translateX(-50%);
    z-index: 0;
}

.tier-label {
    color: rgba(255,255,255,0.9);
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    padding: 10px 20px;
    margin: 8px 0;
    background: rgba(0,0,0,0.15);
    border-radius: 20px;
    position: relative;
    z-index: 1;
}

.map-node {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    max-width: 320px;
    padding: 6px 0;
    position: relative;
    z-index: 1;
}

.map-node.left { flex-direction: row; align-self: flex-start; margin-left: 10%; }
.map-node.right { flex-direction: row-reverse; align-self: flex-end; margin-right: 10%; text-align: right; }

.map-circle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: white;
    border: 3px solid rgba(255,255,255,0.6);
    color: #5c6bc0;
    font-size: 1.3em;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.map-node.completed .map-circle {
    background: #66bb6a;
    color: white;
    border-color: #43a047;
}

.map-node.locked .map-circle {
    background: rgba(255,255,255,0.3);
    color: rgba(255,255,255,0.6);
    cursor: not-allowed;
    border-color: rgba(255,255,255,0.2);
    box-shadow: none;
}

.map-node.current .map-circle {
    animation: currentPulse 2s ease-in-out infinite;
    border-color: #ffc107;
    box-shadow: 0 0 20px rgba(255,193,7,0.4);
}

@keyframes currentPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 20px rgba(255,193,7,0.4); }
    50% { transform: scale(1.08); box-shadow: 0 0 30px rgba(255,193,7,0.6); }
}

.map-circle:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 6px 18px rgba(0,0,0,0.2);
}

.map-info { flex: 1; }

.map-name {
    display: block;
    color: white;
    font-weight: 600;
    font-size: 0.95em;
    text-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.map-node.locked .map-name { color: rgba(255,255,255,0.5); }

.map-done-check {
    display: inline-block;
    color: rgba(255,255,255,0.85);
    font-size: 1em;
    font-weight: 700;
    margin-top: 2px;
}

/* ============================================================
   GAME CONTAINER
   ============================================================ */
.game-container {
    position: relative;
}

.game-header {
    text-align: center;
    padding: 10px 14px 0;
}

.header-compact {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    position: relative;
}

.btn-icon {
    background: rgba(0,0,0,0.04);
    border: 2px solid #c5cae9;
    border-radius: 10px;
    width: 40px;
    height: 40px;
    font-size: 1.2em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover { border-color: #5c6bc0; }

.level-indicator {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.9em;
    font-weight: 700;
    color: #333;
    text-align: center;
    pointer-events: none;
}

.header-lives {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    background: #ffebee;
    padding: 5px 10px;
    border-radius: 16px;
    font-size: 0.85em;
    font-weight: 700;
    color: #c62828;
    flex-shrink: 0;
}

/* Sort Status Bar */
.sort-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: rgba(255,255,255,0.6);
    border-radius: 12px;
    margin: 6px 0;
}

.status-moves {
    font-size: 0.9em;
    font-weight: 700;
    color: #555;
}

.status-moves.warning {
    color: #e53935;
}

.status-sorted {
    font-size: 0.9em;
    font-weight: 700;
    color: #5c6bc0;
}

/* ============================================================
   STACKS AREA
   ============================================================ */
.stacks-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 10px;
    flex: 1;
    position: relative;
    overflow: visible;
}

.stacks-row {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 10px;
    padding-top: 24px;
}

.stacks-row-offset {
    /* No horizontal offset needed — the fewer items naturally center with gaps */
}

.stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255,255,255,0.5);
    border: 2px solid #d0d4e6;
    border-radius: 14px;
    padding: 6px 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    width: 86px;
}

.stack:hover {
    border-color: #7986cb;
    box-shadow: 0 2px 12px rgba(92,107,192,0.2);
}

.stack.shake {
    animation: stackShake 0.4s ease;
}

@keyframes stackShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
}

/* Completed stack */
.stack.complete {
    cursor: default;
    border-width: 3px;
}

.stack.complete.animals  { border-color: #8bc34a; background: rgba(139,195,74,0.15); }
.stack.complete.food     { border-color: #e91e63; background: rgba(233,30,99,0.15); }
.stack.complete.vehicles { border-color: #ff9800; background: rgba(255,152,0,0.15); }
.stack.complete.weather  { border-color: #42a5f5; background: rgba(66,165,245,0.15); }
.stack.complete.colors   { border-color: #ab47bc; background: rgba(171,71,188,0.15); }
.stack.complete.body     { border-color: #ef5350; background: rgba(239,83,80,0.15); }
.stack.complete.home     { border-color: #26a69a; background: rgba(38,166,154,0.15); }
.stack.complete.nature   { border-color: #8d6e63; background: rgba(141,110,99,0.15); }
.stack.complete.sports   { border-color: #5c6bc0; background: rgba(92,107,192,0.15); }
.stack.complete.clothes  { border-color: #ff7043; background: rgba(255,112,67,0.15); }
.stack.complete.tools    { border-color: #78909c; background: rgba(120,144,156,0.15); }
.stack.complete.jobs     { border-color: #7e57c2; background: rgba(126,87,194,0.15); }
.stack.complete.rooms    { border-color: #a1887f; background: rgba(161,136,127,0.15); }
.stack.complete.travel   { border-color: #29b6f6; background: rgba(41,182,246,0.15); }
.stack.complete.school   { border-color: #fdd835; background: rgba(253,216,53,0.15); }
.stack.complete.kitchen  { border-color: #ec407a; background: rgba(236,64,122,0.15); }
.stack.complete.ocean    { border-color: #0097a7; background: rgba(0,151,167,0.15); }
.stack.complete.music    { border-color: #d81b60; background: rgba(216,27,96,0.15); }
.stack.complete.flags    { border-color: #43a047; background: rgba(67,160,71,0.15); }
.stack.complete.space    { border-color: #5e35b1; background: rgba(94,53,177,0.15); }

/* Stack label for completed stacks — positioned outside the stack so it doesn't affect height */
.stack-label {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 3px 10px;
    border-radius: 6px;
    color: white;
    text-align: center;
    white-space: nowrap;
    z-index: 5;
}

.stack-label.label-animate {
    animation: labelAppear 0.3s ease-out;
}

@keyframes labelAppear {
    0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
    60% { opacity: 1; transform: translateX(-50%) scale(1.1); }
    100% { opacity: 1; transform: translateX(-50%) scale(1); }
}

.stack-label.animals  { background: #8bc34a; }
.stack-label.food     { background: #e91e63; }
.stack-label.vehicles { background: #ff9800; }
.stack-label.weather  { background: #42a5f5; }
.stack-label.colors   { background: #ab47bc; }
.stack-label.body     { background: #ef5350; }
.stack-label.home     { background: #26a69a; }
.stack-label.nature   { background: #8d6e63; }
.stack-label.sports   { background: #5c6bc0; }
.stack-label.clothes  { background: #ff7043; }
.stack-label.tools    { background: #78909c; }
.stack-label.jobs     { background: #7e57c2; }
.stack-label.rooms    { background: #a1887f; }
.stack-label.travel   { background: #29b6f6; }
.stack-label.school   { background: #fdd835; color: #5d4037; }
.stack-label.kitchen  { background: #ec407a; }
.stack-label.ocean    { background: #0097a7; }
.stack-label.music    { background: #d81b60; }
.stack-label.flags    { background: #43a047; }
.stack-label.space    { background: #5e35b1; }

/* Stack tiles area */
.stack-tiles {
    display: flex;
    flex-direction: column-reverse;
    gap: 4px;
    width: 100%;
}

/* Tile slot (placeholder even when empty) */
.tile-slot {
    min-height: 48px;
    border-radius: 8px;
    position: relative;
}

.tile-slot:empty {
    background: rgba(0,0,0,0.03);
    border: 1.5px dashed rgba(0,0,0,0.1);
    border-radius: 8px;
}

/* ============================================================
   TILES
   ============================================================ */
.tile {
    background: #fffcf7;
    border: 2px solid #e0d6c8;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    min-height: 46px;
    padding: 6px 2px;
    transition: all 0.15s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* Category left-border indicator (hidden by default — revealed by power-up) */
.tile::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 5px;
    border-radius: 6px 0 0 6px;
    transition: all 0.2s ease;
    display: none;
}

.tile.reveal-category::before {
    display: block;
}

.tile.animals::before  { background: #8bc34a; }
.tile.food::before     { background: #e91e63; }
.tile.vehicles::before { background: #ff9800; }
.tile.weather::before  { background: #42a5f5; }
.tile.colors::before   { background: #ab47bc; }
.tile.body::before     { background: #ef5350; }
.tile.home::before     { background: #26a69a; }
.tile.nature::before   { background: #8d6e63; }
.tile.sports::before   { background: #5c6bc0; }
.tile.clothes::before  { background: #ff7043; }
.tile.tools::before    { background: #78909c; }
.tile.jobs::before     { background: #7e57c2; }
.tile.rooms::before    { background: #a1887f; }
.tile.travel::before   { background: #29b6f6; }
.tile.school::before   { background: #fdd835; }
.tile.kitchen::before  { background: #ec407a; }
.tile.ocean::before    { background: #0097a7; }
.tile.music::before    { background: #d81b60; }
.tile.flags::before    { background: #43a047; }
.tile.space::before    { background: #5e35b1; }

.tile .word {
    font-size: 0.9em;
    font-weight: bold;
    color: #333;
    text-align: center;
    padding: 2px 4px;
    width: 100%;
    line-height: 1.3;
}

.tile.emoji .word {
    font-size: 2em;
    line-height: 1;
}

/* Hidden tile (face-down) */
.tile.tile-hidden {
    background: #3a3a4a;
    border-color: #2a2a3a;
    cursor: default;
    box-shadow: inset 0 1px 4px rgba(0,0,0,0.3);
}

.tile.tile-hidden .word {
    color: rgba(255,255,255,0.7);
    font-size: 1.4em;
    font-weight: 800;
}

/* Frozen tile — 1 layer (cracked ice) */
.tile.tile-frozen {
    background: linear-gradient(135deg, #e1f5fe, #b3e5fc);
    border-color: #4fc3f7;
    border-style: dashed;
    box-shadow: inset 0 0 8px rgba(79,195,247,0.4);
}

.tile.tile-frozen .word {
    color: #0277bd;
}

/* Frozen tile — 2 layers (solid ice) */
.tile.tile-frozen.tile-frozen-2 {
    background: linear-gradient(135deg, #b3e5fc, #81d4fa);
    border-color: #29b6f6;
    border-style: solid;
    border-width: 3px;
    box-shadow: inset 0 0 12px rgba(41,182,246,0.5);
}

.tile.tile-frozen.tile-frozen-2 .word {
    color: #01579b;
}

/* Ice shatter / thaw animation */
@keyframes iceShatter {
    0% { transform: scale(1); box-shadow: inset 0 0 12px rgba(41,182,246,0.5); }
    30% { transform: scale(1.05); box-shadow: inset 0 0 16px rgba(41,182,246,0.7), 0 0 8px rgba(79,195,247,0.4); }
    60% { transform: scale(0.97); box-shadow: none; }
    100% { transform: scale(1); box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
}

.tile.just-thawed {
    animation: iceShatter 0.4s ease-out;
}

/* Bomb tile */
.tile.tile-bomb {
    border-color: #ff5722;
    box-shadow: 0 0 6px rgba(255,87,34,0.25);
}

/* Bomb countdown badge */
.bomb-timer {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ff5722;
    color: white;
    font-size: 0.6em;
    font-weight: 800;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    z-index: 2;
}

/* Urgent bomb (<= 3 moves left) */
.tile.tile-bomb.bomb-urgent {
    border-color: #d32f2f;
    box-shadow: 0 0 10px rgba(211,47,47,0.4);
    animation: bombPulse 0.6s ease-in-out infinite;
}

.tile.tile-bomb.bomb-urgent .bomb-timer {
    background: #d32f2f;
}

@keyframes bombPulse {
    0%, 100% { box-shadow: 0 0 6px rgba(211,47,47,0.3); }
    50% { box-shadow: 0 0 16px rgba(211,47,47,0.6); }
}

/* ============================================================
   DRAG AND DROP
   ============================================================ */

/* Floating drag ghost tile */
.tile.tile-drag-ghost {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.92;
    transform: scale(1.1) rotate(-2deg);
    box-shadow: 0 10px 28px rgba(0,0,0,0.35);
    transition: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* Dim the top tile in the source stack during drag */
.stack.drag-source .tile.top-tile {
    opacity: 0.25;
    transform: scale(0.95);
}

/* Highlight valid drop target on hover */
.stack.drag-over {
    border-color: #5c6bc0;
    box-shadow: 0 0 18px rgba(92,107,192,0.45);
    background: rgba(92,107,192,0.12);
    transform: scale(1.03);
}

/* Top tile highlight */
.tile.top-tile {
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    border-color: #b0bec5;
}

/* Selected tile (lifted) */
.tile.selected-tile {
    transform: translateY(-12px) scale(1.05);
    box-shadow: 0 8px 20px rgba(92,107,192,0.4);
    border-color: #5c6bc0;
    z-index: 10;
    background: #f5f3ff;
}

/* Sorted tile in complete stack */
.tile.sorted {
    opacity: 0.85;
}

.tile.sorted.animals  { background: #e8f5e9; border-color: #a5d6a7; }
.tile.sorted.food     { background: #fce4ec; border-color: #f48fb1; }
.tile.sorted.vehicles { background: #fff3e0; border-color: #ffcc80; }
.tile.sorted.weather  { background: #e3f2fd; border-color: #90caf9; }
.tile.sorted.colors   { background: #f3e5f5; border-color: #ce93d8; }
.tile.sorted.body     { background: #ffebee; border-color: #ef9a9a; }
.tile.sorted.home     { background: #e0f2f1; border-color: #80cbc4; }
.tile.sorted.nature   { background: #efebe9; border-color: #bcaaa4; }
.tile.sorted.sports   { background: #e8eaf6; border-color: #9fa8da; }
.tile.sorted.clothes  { background: #fbe9e7; border-color: #ffab91; }
.tile.sorted.tools    { background: #eceff1; border-color: #b0bec5; }
.tile.sorted.jobs     { background: #ede7f6; border-color: #b39ddb; }
.tile.sorted.rooms    { background: #efebe9; border-color: #bcaaa4; }
.tile.sorted.travel   { background: #e1f5fe; border-color: #81d4fa; }
.tile.sorted.school   { background: #fffde7; border-color: #fff176; }
.tile.sorted.kitchen  { background: #fce4ec; border-color: #f48fb1; }
.tile.sorted.ocean    { background: #e0f7fa; border-color: #80deea; }
.tile.sorted.music    { background: #fce4ec; border-color: #f48fb1; }
.tile.sorted.flags    { background: #e8f5e9; border-color: #a5d6a7; }
.tile.sorted.space    { background: #ede7f6; border-color: #b39ddb; }

/* ============================================================
   POWER-UP TOOLBAR
   ============================================================ */
.powerup-toolbar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: rgba(0,0,0,0.04);
    border-top: 1px solid rgba(0,0,0,0.06);
}

.powerup-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #fffcf7;
    color: #333;
    border: 2px solid #c5cae9;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.powerup-btn .powerup-icon { font-size: 1.2em; }

.powerup-charges {
    background: #5c6bc0;
    color: white;
    font-size: 0.7em;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 8px;
    margin-left: 2px;
    min-width: 22px;
    text-align: center;
    line-height: 1.3;
}

.powerup-btn:hover:not(.disabled) {
    border-color: #5c6bc0;
    background: #e8eaf6;
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(92,107,192,0.2);
}

.powerup-btn:active:not(.disabled) { transform: translateY(0); }
.powerup-btn.disabled { opacity: 0.4; cursor: not-allowed; }

/* Dev toolbar */
.dev-toolbar {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 6px 14px;
    background: rgba(92,107,192,0.08);
    border-top: 1px dashed rgba(92,107,192,0.3);
}

.dev-btn {
    padding: 6px 16px;
    border-radius: 8px;
    font-size: 0.8em;
    font-weight: 700;
    cursor: pointer;
    border: none;
    color: white;
}

.dev-btn-win { background: #43a047; }
.dev-btn-win:active { background: #2e7d32; }
.dev-btn-lose { background: #e53935; }
.dev-btn-lose:active { background: #c62828; }

/* ============================================================
   ANIMATIONS & PARTICLES
   ============================================================ */
/* Tile reveal animation (hidden -> visible) */
@keyframes tileReveal {
    0% { transform: rotateY(90deg); opacity: 0.5; }
    100% { transform: rotateY(0deg); opacity: 1; }
}

.tile.just-revealed {
    animation: tileReveal 0.3s ease-out;
}

@keyframes particleBurst {
    0% { opacity: 1; transform: translate(0,0) scale(1) rotate(0deg); }
    100% { opacity: 0; transform: translate(var(--tx),var(--ty)) scale(0) rotate(var(--rotation)); }
}

@keyframes fadeIn {
    from { opacity: 0; } to { opacity: 1; }
}

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

.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 99;
    animation: particleBurst 0.6s ease-out forwards;
}

.particle.animals  { background: #66bb6a; }
.particle.food     { background: #ec407a; }
.particle.vehicles { background: #ff9800; }
.particle.weather  { background: #42a5f5; }
.particle.colors   { background: #ab47bc; }
.particle.body     { background: #ef5350; }
.particle.home     { background: #26a69a; }
.particle.nature   { background: #8d6e63; }
.particle.sports   { background: #5c6bc0; }
.particle.clothes  { background: #ff7043; }
.particle.tools    { background: #78909c; }
.particle.jobs     { background: #7e57c2; }
.particle.rooms    { background: #a1887f; }
.particle.travel   { background: #29b6f6; }
.particle.school   { background: #fdd835; }
.particle.kitchen  { background: #ec407a; }
.particle.ocean    { background: #0097a7; }
.particle.music    { background: #d81b60; }
.particle.flags    { background: #43a047; }
.particle.space    { background: #5e35b1; }
.particle.neutral  { background: #999; }

/* Confetti */
@keyframes confettiFall {
    0% { opacity: 1; transform: translateY(-10px) translateX(0) rotate(0deg); }
    100% { opacity: 0; transform: translateY(100vh) translateX(var(--drift)) rotate(var(--rot)); }
}

.confetti {
    position: fixed;
    top: -10px;
    pointer-events: none;
    z-index: 9999;
    animation: confettiFall 2s ease-in forwards;
}

/* ============================================================
   MODALS
   ============================================================ */
.game-modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.game-modal.show { display: flex; animation: fadeIn 0.3s ease; }

.modal-content {
    background: white;
    padding: 36px 28px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    text-align: center;
    min-width: 280px;
    max-width: 360px;
    width: 90%;
    animation: slideUp 0.3s ease;
}

.modal-content h2 {
    font-size: 2em;
    margin-bottom: 12px;
}

.modal-content.win h2 { color: #2e7d32; }
.modal-content.lose h2 { color: #e53935; }
.modal-content.pause h2 { color: #5c6bc0; }
.modal-content.settings h2 { color: #333; }

.settings-options {
    margin-bottom: 18px;
}

.settings-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    cursor: pointer;
}

.toggle-label {
    font-size: 0.95em;
    font-weight: 600;
    color: #555;
}

.settings-toggle input { display: none; }

.toggle-slider {
    width: 46px;
    height: 26px;
    background: #ccc;
    border-radius: 13px;
    position: relative;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.settings-toggle input:checked + .toggle-slider {
    background: #5c6bc0;
}

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

.dev-settings {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dev-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dev-field-label {
    font-size: 0.9em;
    font-weight: 600;
    color: #555;
    display: flex;
    align-items: center;
    gap: 4px;
}

.dev-input {
    width: 80px;
    padding: 6px 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 600;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.dev-input:focus {
    border-color: #5c6bc0;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.btn-primary {
    background: #5c6bc0;
    color: white;
    border: none;
    padding: 14px 36px;
    border-radius: 12px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    max-width: 260px;
}

.btn-primary:hover { background: #3f51b5; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(92,107,192,0.4); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: white;
    color: #5c6bc0;
    border: 2px solid #5c6bc0;
    padding: 12px 28px;
    border-radius: 12px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    max-width: 260px;
}

.btn-secondary:hover { background: #e8eaf6; }

.btn-secondary.btn-danger {
    color: #e53935;
    border-color: #e53935;
}

.btn-secondary.btn-danger:hover { background: #ffebee; }

.restart-life-cost {
    display: inline-block;
    background: #ffebee;
    color: #e53935;
    font-size: 0.8em;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
}

.btn-tertiary {
    background: none;
    border: none;
    color: #888;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 20px;
    transition: all 0.2s;
    text-decoration: underline;
}

.btn-tertiary:hover { color: #5c6bc0; }

/* Pause help section */
.pause-help {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    text-align: left;
}

.pause-help.show {
    max-height: 300px;
    padding: 14px 0 0;
}

.pause-help p {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 6px;
    line-height: 1.4;
}

/* ============================================================
   WIN SCREEN
   ============================================================ */
.win-stats {
    margin-bottom: 14px;
    font-size: 1em;
    color: #555;
}

.win-stat {
    padding: 4px 0;
}

.win-unlock-banner {
    background: linear-gradient(135deg, #ffd54f, #ffb300);
    color: #5d4037;
    text-align: center;
    padding: 12px 16px;
    border-radius: 12px;
    font-weight: 700;
    margin-bottom: 14px;
    border: 2px solid rgba(255,255,255,0.5);
}
.win-unlock-banner .unlock-icon { display: block; font-size: 1.6em; margin-bottom: 2px; }
.win-unlock-banner .unlock-label { display: block; font-size: 0.7em; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; opacity: 0.65; margin-bottom: 4px; }
.win-unlock-banner .unlock-name { display: block; font-size: 1.3em; }

.win-coins-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 18px;
    font-size: 1.5em;
    font-weight: 700;
}

.win-coins-amount { color: #ffc107; }

/* ============================================================
   SHOP
   ============================================================ */
.modal-content.shop h2 { color: #333; }

.shop-powerups {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
}

.shop-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #f9f9f9;
    border-radius: 10px;
}

.shop-icon { font-size: 1.2em; }
.shop-name { flex: 1; font-weight: 600; font-size: 0.9em; color: #333; }
.shop-count { font-weight: 700; color: #5c6bc0; font-size: 1em; }

.shop-buy-btn {
    background: #43a047;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.8em;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}
.shop-buy-btn:active { transform: scale(0.95); }
.shop-buy-btn .coin-badge-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd54f, #ffb300);
    color: #7b5800;
    font-size: 0.55em;
    font-weight: 800;
}
.shop-buy-btn.cant-afford {
    background: #ccc;
    color: #888;
    cursor: default;
}

/* Ad reward button */
.btn-ad-reward {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    max-width: 260px;
    background: linear-gradient(180deg, #43e97b 0%, #38c96a 100%);
    color: white;
    border: none;
    border-bottom: 4px solid #2a9d50;
    padding: 12px 20px;
    border-radius: 14px;
    font-size: 1.1em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 4px 16px rgba(56,201,106,0.4);
}

.btn-ad-reward:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(56,201,106,0.5);
}

.btn-ad-reward:active {
    transform: translateY(2px);
    border-bottom-width: 2px;
    box-shadow: 0 2px 8px rgba(56,201,106,0.3);
}

.btn-ad-reward.used {
    background: #bbb;
    border-bottom-color: #999;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.5;
}

.ad-play-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(0,0,0,0.15);
    border-radius: 8px;
    font-size: 0.9em;
}

.ad-label {
    text-align: left;
    line-height: 1.2;
}

.ad-amount {
    font-size: 0.85em;
    opacity: 0.9;
}

.btn-ad-reward .coin-badge-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd54f, #ffb300);
    color: #7b5800;
    font-size: 0.55em;
    font-weight: 800;
    vertical-align: middle;
}

/* Mock ad overlay */
.mock-ad-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.mock-ad-content {
    background: white;
    padding: 60px 50px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    min-width: 260px;
}

.mock-ad-label {
    font-size: 2.5em;
    font-weight: 800;
    color: #bbb;
    letter-spacing: 4px;
    margin-bottom: 30px;
}

.btn-ad-close {
    background: #5c6bc0;
    color: white;
    border: none;
    padding: 12px 40px;
    border-radius: 12px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-ad-close:hover {
    background: #3f51b5;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(92,107,192,0.4);
}

.btn-ad-close:active { transform: translateY(0); }

/* ============================================================
   LOSE SCREEN
   ============================================================ */
.lose-life-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 4px 0 18px;
    animation: lifePopIn 0.4s ease-out;
}

.lose-heart-broken {
    font-size: 2.8em;
    line-height: 1;
    filter: drop-shadow(0 2px 6px rgba(239,83,80,0.3));
    position: relative;
    display: inline-block;
}

.lose-heart-minus {
    font-size: 1.5em;
    font-weight: 800;
    color: #c62828;
    text-shadow: 0 1px 3px rgba(0,0,0,0.15);
    margin-left: 2px;
}

@keyframes lifePopIn {
    0%   { transform: scale(0.3); opacity: 0; }
    60%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

.lose-progress {
    margin-bottom: 20px;
}

.lose-progress-bar-bg {
    height: 10px;
    background: #eee;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 8px;
}

.lose-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #ef5350, #e53935);
    border-radius: 5px;
    transition: width 0.4s ease;
}

.lose-progress-text {
    font-size: 0.95em;
    font-weight: 600;
    color: #666;
}

/* No lives */
.lose-no-lives { margin-top: 12px; }

.no-lives-heart {
    position: relative;
    display: inline-block;
    margin: 10px 0 16px;
}

.no-lives-heart .big-heart {
    font-size: 4em;
    color: #ef5350;
    filter: drop-shadow(0 2px 6px rgba(239,83,80,0.3));
}

.no-lives-heart .heart-count {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.8em;
    font-weight: 800;
    color: white;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.no-lives-timer {
    font-size: 1em;
    color: #888;
    margin-bottom: 18px;
    font-weight: 600;
}

.no-lives-timer span {
    color: #e53935;
    font-weight: 700;
    font-size: 1.1em;
}

#btn-buy-lives {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

#btn-buy-lives.cant-afford {
    background: #bbb;
    cursor: not-allowed;
}

#btn-buy-lives.cant-afford:hover {
    background: #bbb;
    transform: none;
    box-shadow: none;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    body {
        padding: 0;
        align-items: flex-start;
    }

    .screen { max-width: 100%; }

    /* Home */
    .logo-word { font-size: 2.2em; }
    .logo-sort { font-size: 1.1em; }
    .logo-icon { font-size: 3.5em; }
    .btn-play { padding: 14px 50px; font-size: 1.3em; }

    /* Map */
    .map-node.left { margin-left: 5%; }
    .map-node.right { margin-right: 5%; }
    .map-circle { width: 50px; height: 50px; font-size: 1.1em; }
    .map-name { font-size: 0.85em; }

    /* Game */
    .game-container { border-radius: 0; }
    .game-header { padding: 8px 10px 0; }
    .header-compact { gap: 6px; margin-bottom: 4px; }
    .btn-icon { width: 36px; height: 36px; font-size: 1em; }
    .level-indicator { font-size: 0.8em; }

    .sort-status { padding: 6px 12px; }
    .status-moves, .status-sorted { font-size: 0.8em; }

    .stacks-container {
        gap: 10px;
        padding: 10px 6px;
    }

    .stacks-row {
        gap: 8px;
    }

    .stack {
        padding: 5px 4px;
        width: 80px;
        border-radius: 12px;
    }

    .stack-label {
        font-size: 0.5em;
        padding: 2px 4px;
    }

    .tile-slot { min-height: 40px; }

    .tile {
        min-height: 38px;
        padding: 4px 1px;
        border-radius: 7px;
    }

    .tile .word { font-size: 0.7em; padding: 1px 2px; }
    .tile.emoji .word { font-size: 1.5em; }
    .tile.tile-hidden .word { font-size: 1.2em; }

    .bomb-timer { width: 16px; height: 16px; font-size: 0.55em; }

    .powerup-toolbar {
        gap: 6px;
        padding: 8px 10px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .powerup-btn { padding: 8px 12px; font-size: 0.8em; gap: 4px; border-radius: 10px; }
    .powerup-btn .powerup-icon { font-size: 1em; }
    .powerup-charges { font-size: 0.65em; padding: 1px 5px; }

    .particle { width: 6px; height: 6px; }

    .modal-content { padding: 28px 20px; min-width: auto; margin: 0 15px; }
    .modal-content h2 { font-size: 1.7em; }
    .btn-primary { padding: 12px 28px; font-size: 1em; }
    .btn-secondary { padding: 10px 24px; font-size: 0.9em; }
}

/* Extra small screens */
@media (max-width: 380px) {
    .logo-word { font-size: 1.9em; }
    .logo-sort { font-size: 1em; }
    .logo-icon { font-size: 3em; }
    .btn-play { padding: 12px 40px; font-size: 1.1em; }
    .map-circle { width: 44px; height: 44px; font-size: 1em; }
    .powerup-btn .powerup-name { display: none; }

    .stacks-container { gap: 8px; padding: 8px 4px; }
    .stacks-row { gap: 6px; }
    .stack { width: 70px; padding: 3px; }
    .tile-slot { min-height: 34px; }
    .tile { min-height: 32px; border-radius: 6px; }
    .tile .word { font-size: 0.6em; }
    .tile.emoji .word { font-size: 1.2em; }
    .tile.tile-hidden .word { font-size: 1em; }
    .bomb-timer { width: 14px; height: 14px; font-size: 0.5em; }
}
