:root {
    --bg-color: #111;
    --text-color: #eee;
    --gold: #d4af37;
    --gold-dark: #aa8c2c;
    --panel-bg: rgba(30, 30, 30, 0.9);
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

.screen {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.hidden {
    display: none !important;
}

.active {
    display: flex;
}

h1 {
    font-size: 3rem;
    color: var(--gold);
    text-shadow: 2px 2px 4px #000;
    margin-bottom: 2rem;
}

h2, h3 {
    color: var(--gold);
}

.btn-main, .btn-small {
    background: transparent;
    color: var(--gold);
    border: 2px solid var(--gold);
    padding: 15px 30px;
    font-size: 1.2rem;
    cursor: pointer;
    margin: 10px;
    transition: all 0.3s;
    border-radius: 5px;
}

.btn-small {
    padding: 8px 15px;
    font-size: 1rem;
}

.btn-main:hover, .btn-small:hover {
    background: var(--gold);
    color: var(--bg-color);
}

.btn-main:disabled, .btn-small:disabled {
    border-color: #555;
    color: #555;
    cursor: not-allowed;
}

.btn-main:disabled:hover, .btn-small:disabled:hover {
    background: transparent;
    color: #555;
}

.btn-danger {
    border-color: #d43737;
    color: #d43737;
}

.btn-danger:hover {
    background: #d43737;
    color: #fff;
}

.settings-box {
    margin-top: 30px;
    background: var(--panel-bg);
    padding: 20px;
    border: 1px solid #333;
    border-radius: 8px;
    text-align: center;
}

/* Phase Selection */
#screen-phase-selection {
    justify-content: flex-start;
    padding-top: 20px;
    overflow-y: auto;
}

#chapters-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 80%;
    max-width: 1000px;
}

.chapter-box {
    width: 100%;
    background: var(--panel-bg);
    border: 1px solid var(--gold-dark);
    margin: 15px 0;
    padding: 15px;
    border-radius: 8px;
}

.chapter-title {
    font-size: 1.5rem;
    color: var(--gold);
    margin-top: 0;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
}

.phases-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-top: 15px;
}

.phase-card {
    background: #222;
    border: 1px solid #444;
    padding: 15px;
    border-radius: 5px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
}

.phase-card:hover {
    transform: scale(1.05);
    border-color: var(--gold);
}

.phase-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #333;
}

.phase-card.locked:hover {
    transform: none;
    border-color: #333;
}

.phase-number {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--gold);
}

.phase-name {
    font-size: 0.9rem;
    margin: 10px 0;
}

.phase-stats {
    font-size: 0.8rem;
    color: #aaa;
}

/* Game Screen & Box Aesthetic */
#screen-game {
    justify-content: flex-start;
    background: radial-gradient(circle at center, #2a2a2a 0%, #050505 100%);
}

.hud {
    width: 100%;
    height: 60px;
    background: rgba(10, 10, 10, 0.8);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-sizing: border-box;
    border-bottom: 2px solid var(--gold-dark);
    box-shadow: 0 5px 15px rgba(0,0,0,0.8);
    z-index: 10;
}

#hud-phase-name {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 2px;
}

#hud-timer {
    font-size: 1.5rem;
    font-family: monospace;
    color: #ccc;
    text-shadow: 0 0 5px var(--gold);
}

.hud-buttons {
    display: flex;
    gap: 10px;
}

#puzzle-container {
    flex: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    perspective: 1000px; /* Para efeitos 3D futuros */
}

/* Base da Caixa (Estilo Boxes Lost Fragments) */
.puzzle-box-base {
    width: 80vw;
    max-width: 800px;
    height: 70vh;
    background: linear-gradient(135deg, #3d2c23 0%, #1a100c 100%);
    border: 15px solid #2a1f1a;
    border-radius: 10px;
    box-shadow: 
        inset 0 0 50px rgba(0,0,0,0.9),
        0 20px 50px rgba(0,0,0,0.8),
        0 0 0 4px var(--gold-dark);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 30px;
    overflow: hidden;
}

/* Adornos da caixa */
.puzzle-box-base::before, .puzzle-box-base::after {
    content: '';
    position: absolute;
    width: 50px;
    height: 50px;
    border: 5px solid var(--gold);
    border-radius: 50%;
    box-shadow: 0 0 10px #000;
}
.puzzle-box-base::before { top: 10px; left: 10px; border-bottom: none; border-right: none; }
.puzzle-box-base::after { bottom: 10px; right: 10px; border-top: none; border-left: none; }


/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background: var(--panel-bg);
    border: 2px solid var(--gold);
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    max-width: 500px;
    width: 90%;
}

.modal-content.large {
    max-width: 800px;
}

/* Conquistas */
#achievements-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.achievement {
    display: flex;
    align-items: center;
    background: #222;
    padding: 10px;
    border: 1px solid #444;
    border-radius: 5px;
    text-align: left;
}

.achievement.unlocked {
    border-color: var(--gold);
    background: #2a2510;
}

.achievement-icon {
    font-size: 2rem;
    margin-right: 15px;
    filter: grayscale(100%);
}

.achievement.unlocked .achievement-icon {
    filter: none;
}

.achievement-info h4 {
    margin: 0 0 5px 0;
    color: var(--gold);
}

.achievement-info p {
    margin: 0;
    font-size: 0.9rem;
    color: #ccc;
}

/* Puzzles genericos */
.puzzle-generic-btn {
    padding: 20px 40px;
    font-size: 1.5rem;
    background: #333;
    color: #fff;
    border: 2px solid #555;
    cursor: pointer;
    border-radius: 10px;
}

.puzzle-generic-btn:hover {
    border-color: var(--gold);
}

/* Fases Específicas */
.water-puzzle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.water-tank {
    width: 100px;
    height: 200px;
    border: 2px solid #444;
    position: relative;
    overflow: hidden;
    background: #111;
}

.water-level {
    position: absolute;
    bottom: 0;
    width: 100%;
    background: rgba(0, 150, 255, 0.6);
    transition: height 0.3s;
}

.valves {
    display: flex;
    gap: 20px;
}

.valve {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #333;
    border: 4px solid #555;
    cursor: pointer;
    transition: transform 0.3s;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
}
.valve:hover { border-color: var(--gold); }

.symbols {
    display: flex;
    gap: 10px;
}
.symbol {
    font-size: 2rem;
    cursor: pointer;
    user-select: none;
}

/* Caixa Marés */
.tide-box {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.tide-row {
    display: flex;
    gap: 20px;
    align-items: center;
}
.tide-item {
    font-size: 2.5rem;
    cursor: pointer;
}

/* Pérolas */
.pearl-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    background: #222;
    padding: 20px;
    border: 2px solid #444;
}
.pearl-slot {
    width: 60px;
    height: 60px;
    border: 2px dashed #555;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    cursor: pointer;
}
.pearl-slot.has-pearl {
    background: radial-gradient(circle, #fff, #aaa);
    border: 2px solid var(--gold);
}

/* Guardião */
.guardian-statue {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
.medallion-pieces {
    display: flex;
    gap: 10px;
}
.medallion-piece {
    width: 40px;
    height: 40px;
    background: #8B4513;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    cursor: pointer;
}
.medallion-slot {
    width: 100px;
    height: 100px;
    border: 2px solid var(--gold);
    border-radius: 50%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
}

/* Estação Esquecida - Fases 25-28 */

/* Trem / Mapas */
.map-puzzle {
    display: flex;
    gap: 20px;
    align-items: center;
}
.tickets-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.ticket {
    background: #e8dcc4;
    color: #333;
    padding: 10px;
    border: 2px dashed #888;
    cursor: pointer;
    text-align: center;
    font-weight: bold;
}
.ticket.selected {
    border-color: var(--gold);
    background: #fff8e7;
    transform: scale(1.05);
}

/* Painel Maquinista */
.train-panel {
    background: #444;
    padding: 30px;
    border-radius: 10px;
    border: 5px solid #222;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}
.levers-box {
    display: flex;
    justify-content: center;
    gap: 20px;
}
.lever-slot {
    width: 40px;
    height: 100px;
    background: #222;
    position: relative;
    border-radius: 5px;
}
.lever-handle {
    width: 30px;
    height: 30px;
    background: #880000;
    border-radius: 50%;
    position: absolute;
    left: 5px;
    top: 5px; /* top=5px -> UP, top=65px -> DOWN */
    cursor: pointer;
    transition: top 0.2s;
}
.circuits-box {
    display: flex;
    flex-wrap: wrap;
    width: 150px;
    gap: 10px;
}
.circuit {
    width: 40px;
    height: 40px;
    background: #222;
    border: 2px solid #666;
    cursor: pointer;
}
.circuit.on { background: #00aa00; border-color: #00ff00; }

/* Mala Passageiro */
.suitcase {
    background: #5c4033;
    width: 300px;
    height: 200px;
    border-radius: 10px;
    border: 3px solid #3a2818;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}
.combination-lock {
    display: flex;
    background: #gold;
    padding: 10px;
    border: 2px solid #111;
    gap: 10px;
}
.digit {
    background: #222;
    color: #fff;
    font-size: 2rem;
    padding: 5px 15px;
    cursor: pointer;
    user-select: none;
}

/* Última Plataforma */
.tracks-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    background: #444;
    padding: 10px;
}
.track-piece {
    width: 60px;
    height: 60px;
    background: #222;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    cursor: pointer;
    transition: transform 0.3s;
}

/* Mansão dos Espelhos - Fases 29-32 */

/* Retrato */
.paintings-container {
    display: flex;
    gap: 30px;
}
.painting {
    width: 150px;
    height: 200px;
    border: 10px solid #8b6508;
    background: #333;
    position: relative;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 4rem;
}
.difference-spot {
    position: absolute;
    width: 20px;
    height: 20px;
    background: transparent;
    border-radius: 50%;
}
.painting-key {
    position: absolute;
    font-size: 2rem;
    z-index: -1; /* starts behind painting */
}
.painting.fallen {
    transform: rotate(15deg) translateY(50px);
}

/* Corredor de Espelhos */
.mirror-hall {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 600px;
}
.mirror-door {
    width: 80px;
    height: 140px;
    border: 5px solid #aaa;
    background: linear-gradient(135deg, #eee 0%, #aaa 100%);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    color: transparent;
    transition: background 0.5s;
}
.mirror-door.revealed-false {
    background: #111;
    color: red;
}
.mirror-door.revealed-true {
    background: #4a4;
    color: #fff;
}

/* Caixa Reflexões */
.light-grid {
    display: grid;
    grid-template-columns: repeat(4, 60px);
    grid-template-rows: repeat(4, 60px);
    gap: 5px;
    background: #222;
    padding: 10px;
    border: 2px solid var(--gold);
}
.light-cell {
    background: #333;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    cursor: pointer;
    position: relative;
}
.light-cell.has-mirror {
    border: 2px solid #aaa;
    background: #555;
}

/* Quarto Proibido (Cofre) */
.safe-dial-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #333;
    padding: 40px;
    border-radius: 50%;
    border: 10px solid #222;
}
.safe-dial {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: #aaa;
    border: 5px solid #888;
    position: relative;
    cursor: pointer;
    transition: transform 0.3s;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}
.safe-marker {
    width: 10px;
    height: 20px;
    background: red;
}

/* Cidade Mecânica - Fases 33-36 */

/* Coração da Cidade (Engrenagens) */
.gears-container {
    display: flex;
    gap: 20px;
    align-items: center;
}
.gear {
    width: 80px;
    height: 80px;
    border: 10px dashed #666;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.3s;
}
.gear.connected {
    border-color: var(--gold);
    animation: spin 4s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Torre dos Sinos */
.bells-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    height: 150px;
}
.bell {
    background: var(--gold);
    border-radius: 50% 50% 10% 10%;
    cursor: pointer;
    position: relative;
}
.bell::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 10px;
    background: #333;
    border-radius: 50%;
}
.bell:active { transform: scale(0.95); }

/* Autômato */
.automaton-parts {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.part {
    width: 40px;
    height: 40px;
    background: #777;
    border: 2px solid #555;
    cursor: pointer;
}
.robot-body {
    width: 100px;
    height: 150px;
    border: 2px dashed var(--gold);
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
}

/* Conselho das Máquinas */
.council-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.council-node {
    width: 100px;
    height: 100px;
    background: #222;
    border: 2px solid #555;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}
.council-node.solved {
    border-color: #0f0;
    color: #0f0;
}

/* Santuário da Memória - Fases 37-40 */

/* Jardim do Tempo */
.seasons-box {
    display: flex;
    gap: 15px;
}
.season-btn {
    padding: 10px 20px;
    background: #333;
    border: 2px solid #555;
    cursor: pointer;
}
.season-btn.active-season {
    border-color: #0f0;
    background: #151;
}

/* Cofre Lembranças */
.timeline {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}
.event-slot {
    width: 100px;
    height: 100px;
    border: 2px dashed #aaa;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 0.8rem;
}
.event-item {
    width: 90px;
    height: 90px;
    background: #553311;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
    text-align: center;
}

/* Máquina Vazio */
.void-machine {
    width: 300px;
    height: 300px;
    border-radius: 50%;
    border: 10px solid #800;
    background: radial-gradient(circle, #f00 0%, #300 100%);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: pulse 2s infinite alternate;
}
@keyframes pulse { 0% { box-shadow: 0 0 10px #f00; } 100% { box-shadow: 0 0 50px #f00; } }
.crystal {
    position: absolute;
    width: 40px;
    height: 60px;
    background: #fff;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    cursor: pointer;
    transition: background 0.3s;
}
.crystal.off { background: #333; }

/* Destino Elias */
.final-decision-box {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}
.btn-ending {
    padding: 15px 30px;
    font-size: 1.2rem;
    cursor: pointer;
    border: 2px solid #fff;
    background: transparent;
    color: #fff;
    transition: all 0.3s;
}
.btn-ending.memory { border-color: #0af; color: #0af; }
.btn-ending.memory:hover { background: #0af; color: #fff; }
.btn-ending.void { border-color: #f00; color: #f00; }
.btn-ending.void:hover { background: #f00; color: #fff; }
.btn-ending.secret { border-color: var(--gold); color: var(--gold); }
.btn-ending.secret:hover { background: var(--gold); color: #000; }

