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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #1a1a2e;
    color: #eee;
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    max-width: 900px;
    margin: 0 auto;
    padding: 10px;
}

.screen { display: none; }
.screen.active { display: block; }

/* Stage Selection */
h1 {
    text-align: center;
    margin: 20px 0 5px;
    font-size: 1.8em;
    color: #e94560;
}

.subtitle {
    text-align: center;
    color: #888;
    margin-bottom: 15px;
}

.stage-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
    padding: 10px;
}

.stage-btn {
    aspect-ratio: 1;
    border: 1px solid #333;
    border-radius: 4px;
    background: #16213e;
    color: #ccc;
    font-size: 0.7em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.stage-btn:hover {
    background: #0f3460;
    border-color: #e94560;
}

/* Game Screen */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #333;
    margin-bottom: 8px;
}

.btn-back, .btn-reset, .btn-hint {
    background: #16213e;
    border: 1px solid #444;
    color: #ccc;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
}

.btn-back:hover, .btn-reset:hover, .btn-hint:hover {
    background: #0f3460;
}

.btn-hint {
    border-color: #ffeb3b;
    color: #ffeb3b;
}

.btn-hint:hover {
    background: #3d3d00;
}

.header-info {
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 0.9em;
}

#stage-label { color: #e94560; font-weight: bold; }
.moves { color: #4ecdc4; }
.score { color: #ffd93d; }

/* Game Layout (board + side panel) */
.game-layout {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.game-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.missions-panel {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.mission-item {
    background: #16213e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: help;
    transition: transform 0.1s, border-color 0.2s;
}

.mission-item:hover {
    transform: scale(1.02);
    border-color: #555;
}

.mission-item.complete {
    border-color: #4ecdc4;
    opacity: 0.7;
}

.mission-item.complete:hover {
    border-color: #6eeee4;
}

.mission-icon {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mission-icon-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.mission-icon-text {
    font-size: 16px;
    text-align: center;
    line-height: 32px;
}

.mission-label {
    color: #ccc;
    font-size: 0.85em;
    min-width: 50px;
}

.mission-progress {
    color: #fff;
    font-weight: bold;
    margin-left: auto;
}

/* Board */
.board-container {
    width: 100%;
    max-width: 450px;
    aspect-ratio: 9 / 12;
}

.board-svg {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    background: #0f0f23;
}

/* Block cells */
.cell-bg {
    fill: #1a1a3e;
    stroke: #252550;
    stroke-width: 0.5;
}

.cell-bg.not-stage {
    fill: #0a0a15;
    stroke: #1a1a2e;
    stroke-width: 1;
}
.cell-bg.entrance {
    fill: #1a2a4e;
    stroke: #2a4a6e;
}
.cell-bg.pass {
    fill: #0d0d20;
    stroke: #252550;
    stroke-dasharray: 2,2;
}

/* Cell type indicators */
.cell-indicator {
    fill: rgba(255, 255, 255, 0.4);
    pointer-events: none;
}
.entrance-indicator {
    fill: #4a9eff;
}
.pass-indicator {
    fill: #666688;
}

.cell-bg.carpet { fill: #3d1f00; }
.cell-bg.jelly { fill: #1a0033; }

/* Block colors */
.block { cursor: pointer; transition: opacity 0.1s; }
.block:hover { opacity: 0.85; }
.block.selected { stroke: #fff; stroke-width: 2; }

.color-book { fill: #e74c3c; }
.color-crown { fill: #f39c12; }
.color-gem { fill: #9b59b6; }
.color-leaf { fill: #27ae60; }
.color-shield { fill: #3498db; }
.color-collect_red { fill: #ff6b6b; }
.color-collect_green { fill: #51cf66; }

/* Special blocks */
.special-block { fill: #fff; stroke-width: 1.5; }
.special-target { stroke: #e74c3c; }
.special-line_v { stroke: #3498db; }
.special-line_h { stroke: #3498db; }
.special-boom { stroke: #f39c12; }
.special-rainbow { stroke: #9b59b6; }

/* Gimmick blocks */
.gimmick-block {
    fill: #5a4a3a;
    stroke: #8a7a6a;
    stroke-width: 1;
}

/* Cover overlay */
.cover-overlay {
    fill: rgba(100, 100, 100, 0.5);
    stroke: #888;
    stroke-width: 1;
    stroke-dasharray: 3,2;
    pointer-events: none;
}

/* Selection arrows */
.direction-arrow {
    fill: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: fill 0.1s;
}
.direction-arrow:hover {
    fill: #4ecdc4;
}

/* Reward log (side panel) */
.reward-log {
    max-height: 80px;
    overflow-y: auto;
    font-size: 0.8em;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reward-entry {
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: bold;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-5px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Side panel */
.side-panel {
    width: 180px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}

/* Cascade delay control */
.cascade-control {
    background: #16213e;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 8px;
}

.cascade-control label {
    display: block;
    font-size: 0.75em;
    color: #aaa;
    margin-bottom: 4px;
}

.cascade-control input[type="range"] {
    width: 100%;
    cursor: pointer;
}

/* Legend panel */
.legend-panel {
    background: #16213e;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 8px;
    font-size: 0.7em;
    max-height: 400px;
    overflow-y: auto;
}

.legend-panel h3 {
    color: #e94560;
    margin-bottom: 6px;
    font-size: 1.1em;
}

.legend-section {
    margin-bottom: 6px;
}

.legend-section h4 {
    color: #888;
    margin-bottom: 3px;
    font-size: 0.95em;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.legend-swatch {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    color: #fff;
    flex-shrink: 0;
}

.legend-swatch-img {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    flex-shrink: 0;
    object-fit: contain;
}

.legend-label {
    color: #ccc;
    white-space: nowrap;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal.hidden { display: none; }

.modal-content {
    background: #16213e;
    border: 1px solid #444;
    border-radius: 12px;
    padding: 30px 40px;
    text-align: center;
}

.modal-content h2 {
    margin-bottom: 10px;
    font-size: 1.5em;
}

#game-over-title.win { color: #4ecdc4; }
#game-over-title.lose { color: #e94560; }

#game-over-score {
    color: #ffd93d;
    margin-bottom: 20px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-buttons button {
    padding: 10px 20px;
    border: 1px solid #444;
    border-radius: 6px;
    background: #0f3460;
    color: #eee;
    cursor: pointer;
    font-size: 1em;
}

.modal-buttons button:hover {
    background: #1a5090;
}

/* Connection status */
.connection-status {
    position: fixed;
    bottom: 10px;
    right: 10px;
    font-size: 0.75em;
    padding: 4px 8px;
    border-radius: 3px;
    background: #333;
    color: #888;
}

.connection-status.connected { color: #4ecdc4; }
.connection-status.disconnected { color: #e94560; }

/* Responsive */
@media (max-width: 700px) {
    .game-layout {
        flex-direction: column;
        align-items: center;
    }
    .side-panel {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .legend-panel { max-height: 200px; }
}

@media (max-width: 480px) {
    .stage-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    .game-header { font-size: 0.85em; }
}
