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

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

#app { max-width: 420px; margin: 0 auto; padding: 12px; }

header { text-align: center; padding: 14px 0 10px; }
header h1 {
    font-size: 1.7rem;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.subtitle { color: #888; margin-top: 4px; font-size: 0.85rem; }

#step-indicator { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; }

.step {
    width: 38px; height: 38px; border-radius: 8px; background: #2a2a4a;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 13px; color: #666; transition: all 0.3s;
}
.step.active { background: #667eea; color: #fff; transform: scale(1.1); }
.step.done { background: #00cc66; color: #fff; }

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

#face-label, #manual-face-label {
    text-align: center; font-size: 1.05rem; font-weight: 600;
    margin-bottom: 10px; color: #667eea;
}

#camera-container {
    position: relative; width: 300px; height: 300px;
    margin: 0 auto 10px; border-radius: 14px; overflow: hidden; background: #000;
}
#camera { width: 100%; height: 100%; object-fit: cover; }
#overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }

#grid-overlay {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 180px; height: 180px;
    display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
    gap: 4px; pointer-events: none;
}
.grid-cell { border: 2px solid rgba(255,255,255,0.6); border-radius: 6px; background: rgba(255,255,255,0.05); }

#detected-colors { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }
.color-preview { width: 36px; height: 36px; border-radius: 8px; background: #333; border: 2px solid #555; }

.btn {
    display: inline-block; padding: 12px 24px; border: none; border-radius: 12px;
    font-size: 15px; font-weight: 600; cursor: pointer; transition: all 0.15s; color: #fff;
}
.btn:active { transform: scale(0.95); }
.btn-primary { background: linear-gradient(135deg, #667eea, #764ba2); }
.btn-secondary { background: #2a2a4a; color: #ccc; }
.btn-small { padding: 10px 20px; font-size: 14px; border-radius: 10px; }

#scan-buttons, #manual-buttons, #preview-buttons {
    display: flex; gap: 12px; justify-content: center; margin: 12px 0;
}

#manual-grid {
    display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
    gap: 6px; width: 160px; height: 160px; margin: 14px auto;
}
.manual-cell { background: #333; border-radius: 10px; cursor: pointer; border: 3px solid transparent; transition: all 0.2s; }
.manual-cell.selected { border-color: #667eea; box-shadow: 0 0 12px rgba(102,126,234,0.5); }

#color-picker { display: flex; justify-content: center; gap: 10px; margin: 12px 0; }
.color-btn { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; transition: transform 0.2s; }
.color-btn:hover, .color-btn.active { transform: scale(1.15); border-color: #fff; }

#cube-net {
    display: grid;
    grid-template-areas: ".  U  .  ." "L  F  R  B" ".  D  .  .";
    grid-template-columns: repeat(4, 64px); grid-template-rows: repeat(3, 64px);
    gap: 4px; justify-content: center; margin: 16px auto;
}
.net-face { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 2px; background: #111; border-radius: 4px; }
.net-face[data-face="U"] { grid-area: U; }
.net-face[data-face="D"] { grid-area: D; }
.net-face[data-face="F"] { grid-area: F; }
.net-face[data-face="B"] { grid-area: B; }
.net-face[data-face="L"] { grid-area: L; }
.net-face[data-face="R"] { grid-area: R; }
.net-cell { width: 100%; aspect-ratio: 1; border-radius: 3px; border: 1px solid rgba(0,0,0,0.2); }

#solution-info { text-align: center; font-size: 15px; color: #00cc66; margin-bottom: 14px; font-weight: 600; }
#cube-3d-container { display: flex; justify-content: center; margin-bottom: 14px; }
#cube-3d { border-radius: 12px; background: #111; }
#move-display { margin-bottom: 14px; }
#move-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 0 8px; }

.move-badge {
    padding: 8px 14px; background: #2a2a4a; border-radius: 8px;
    font-weight: 700; font-size: 17px; color: #888; transition: all 0.3s;
    cursor: pointer; min-width: 44px; text-align: center;
}
.move-badge.current { background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; transform: scale(1.15); }
.move-badge.past { background: #00cc66; color: #fff; }

#solution-nav { display: flex; justify-content: center; align-items: center; gap: 16px; margin-bottom: 14px; }
#move-counter { color: #888; font-size: 15px; font-weight: 600; min-width: 60px; text-align: center; }
#btn-new-solve { display: block; margin: 0 auto; }

.hidden { display: none !important; }

#loading {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(26,26,46,0.95);
    display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 100;
}
.spinner { width: 44px; height: 44px; border: 4px solid #2a2a4a; border-top-color: #667eea; border-radius: 50%; animation: spin 0.7s linear infinite; margin-bottom: 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

.c-W { background: #FFFFFF; }
.c-Y { background: #FFD500; }
.c-R { background: #B71234; }
.c-O { background: #FF5800; }
.c-G { background: #009B48; }
.c-B { background: #0046AD; }

@media (max-width: 360px) {
    #camera-container { width: 260px; height: 260px; }
    #grid-overlay { width: 150px; height: 150px; }
    #cube-net { grid-template-columns: repeat(4, 52px); grid-template-rows: repeat(3, 52px); }
}
