:root {
    --machine-bg: linear-gradient(180deg, #1e1e24 0%, #0d0d12 100%);
    --panel-border: #444;
    --gold: #ffd700;
    --neon-blue: #00f0ff;
    --neon-red: #ff3366;
    --lcd-border: #222;
    --reel-bg: #e6e6e6;
    --btn-stop-color: linear-gradient(to bottom, #ff4c4c, #cc0000);
    --btn-spin-color: linear-gradient(to bottom, #4caf50, #2e7d32);
}

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

body {
    font-family: 'Noto Sans TC', 'Outfit', sans-serif;
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Lock to the viewport (not min-height) so the flex container centers the
       machine within the real viewport height. The machine keeps its 900px
       layout box, but is scaled to fit via transform — see fitMachine(). */
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Machine Casing */
#pachislot-machine {
    /* Fixed design size — the whole machine is scaled to fit the viewport
       via fitMachine() in main.js (transform: scale). This guarantees the
       full portrait machine is always visible (letterboxed) on any viewport,
       instead of being clipped on short (desktop) viewports. */
    width: 480px;
    height: 900px;
    flex: none;
    background: var(--machine-bg);
    border: 4px solid #333;
    border-radius: 15px;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.8), 0 10px 30px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 10px;
    transform-origin: center center;
}

@media (min-width: 768px) {
    #pachislot-machine {
        border: 8px solid #333;
        border-radius: 25px;
    }
}

/* 1. Top: LCD Screen */
#lcd-screen {
    flex: 1.2;
    position: relative;
    border: 5px solid var(--lcd-border);
    border-radius: 10px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
    margin-bottom: 10px;
}

.lcd-bg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    z-index: 1;
}

#wolf-container {
    position: absolute;
    right: 5%;
    bottom: 20%;
    width: 45%;
    height: 70%;
    z-index: 2;
    display: flex;
    align-items: flex-end;
}

#wolf-character {
    width: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 10px rgba(255, 51, 102, 0.5));
}

#sheep-container {
    position: absolute;
    left: 5%;
    bottom: 10%;
    width: 35%;
    height: 50%;
    z-index: 3;
    display: flex;
    align-items: flex-end;
    opacity: 0; /* Hidden by default until attack */
    transform: translateX(-50px);
    transition: opacity 0.3s;
}

#sheep-character {
    width: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 10px rgba(0, 240, 255, 0.5));
}

/* Damage Text Overlay */
#damage-text {
    position: absolute;
    right: 25%;
    top: 40%;
    z-index: 10;
    font-size: 3rem;
    font-weight: 900;
    color: #ffcc00;
    -webkit-text-stroke: 2px #cc0000;
    filter: drop-shadow(0 5px 5px rgba(0,0,0,0.8));
    pointer-events: none;
}
#damage-text.hidden { display: none; }

/* LCD UI Layer */
#ui-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 5;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.wolf-status {
    background: rgba(0,0,0,0.6);
    padding: 5px 15px;
    border-bottom-right-radius: 15px;
    display: inline-block;
    align-self: flex-start;
    backdrop-filter: blur(5px);
}

#wolf-state {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--neon-blue);
}

#wolf-hp-bar {
    width: 150px; height: 12px;
    background: rgba(255,255,255,0.2);
    border: 1px solid #000;
    border-radius: 6px;
    margin-top: 5px;
    overflow: hidden;
}

#wolf-hp-fill {
    width: 100%; height: 100%;
    background: linear-gradient(90deg, #ff0044, #ff3366);
    transition: width 0.3s ease-out;
}

#lcd-log {
    background: linear-gradient(transparent, rgba(0,0,0,0.9));
    color: #fff;
    padding: 15px;
    text-align: center;
    font-size: 1.1rem;
    font-weight: bold;
    text-shadow: 0 2px 4px #000;
}

/* 2. Middle: Reels Window */
#reels-window {
    flex: none;
    height: 320px; /* 3 rows of 100px + 20px padding */
    background: #111;
    border: 8px solid #555;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    padding: 10px;
    position: relative;
    box-shadow: inset 0 20px 30px rgba(0,0,0,0.8);
    overflow: hidden;
}

.payline-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 10;
    pointer-events: none;
}

.win-line {
    position: absolute;
    background: rgba(0, 240, 255, 0.6);
    box-shadow: 0 0 15px var(--neon-blue);
    z-index: 10;
    animation: line-flash 0.5s infinite alternate;
}
@keyframes line-flash {
    0% { opacity: 0.5; filter: brightness(1); }
    100% { opacity: 1; filter: brightness(1.5); }
}

.win-line.horizontal { width: 100%; height: 8px; left: 0; }
.win-line.row-1 { top: 16%; }
.win-line.row-2 { top: 50%; transform: translateY(-50%); }
.win-line.row-3 { bottom: 16%; }

.win-line.diagonal { width: 140%; height: 8px; left: -20%; top: 50%; transform-origin: center; }
.win-line.TL-BR { transform: translateY(-50%) rotate(25deg); }
.win-line.BL-TR { transform: translateY(-50%) rotate(-25deg); }

.reel-container {
    width: 32%;
    height: 100%;
    background: var(--reel-bg);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
    /* mask to fade edges */
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 15%, black 85%, transparent 100%);
}

.reel-strip {
    width: 100%;
    display: flex;
    flex-direction: column;
    /* transition is set via JS for spinning */
}

.reel-symbol {
    width: 100%;
    height: 100px; /* Base height, adjusted in JS to fit 3 in view */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3.5rem;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    position: relative;
    user-select: none;
}
.reel-symbol span.name {
    position: absolute; bottom: 2px;
    font-size: 0.7rem; color: #555; font-weight: bold;
}

.reel-strip.blur .reel-symbol {
    filter: blur(3px);
}

/* 3. Bottom: Control Deck */
#control-deck {
    flex: 0.6;
    background: linear-gradient(145deg, #2a2a35, #1a1a20);
    border-radius: 10px;
    border: 2px solid #444;
    margin-top: 10px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    box-shadow: inset 0 2px 10px rgba(255,255,255,0.1);
}

.stats-board {
    display: flex;
    justify-content: space-between;
    background: #000;
    padding: 8px 15px;
    border-radius: 6px;
    border: 2px inset #333;
    color: #0f0; /* Digital LED green */
    font-family: monospace;
    font-size: 1.2rem;
    font-weight: bold;
}

#win-display { color: var(--gold); }

.deck-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

.btn-spin {
    width: 70px; height: 70px;
    border-radius: 50%;
    background: var(--btn-spin-color);
    border: 4px solid #111;
    box-shadow: 0 8px 0 #1b4d1e, 0 15px 20px rgba(0,0,0,0.5);
    cursor: pointer;
    position: relative;
}
.btn-spin::after {
    content: 'SPIN';
    color: rgba(255,255,255,0.8);
    font-weight: 900;
    font-size: 14px;
}
.btn-spin:active:not(:disabled) {
    transform: translateY(8px);
    box-shadow: 0 0 0 #1b4d1e, 0 5px 10px rgba(0,0,0,0.5);
}

.stop-buttons-group {
    display: flex;
    gap: 15px;
    flex: 1;
    justify-content: flex-end;
}

.btn-stop {
    width: 60px; height: 60px;
    border-radius: 8px;
    background: var(--btn-stop-color);
    border: 2px solid #333;
    box-shadow: 0 6px 0 #800000, 0 10px 15px rgba(0,0,0,0.5);
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.1s;
}
.btn-stop.active {
    opacity: 1;
    box-shadow: 0 6px 0 #800000, 0 0 15px var(--neon-red), inset 0 0 10px rgba(255,255,255,0.5);
}
.btn-stop:active:not(:disabled) {
    transform: translateY(6px);
    box-shadow: 0 0 0 #800000, 0 2px 5px rgba(0,0,0,0.5);
}

/* Animations */
@keyframes dash-attack {
    0% { transform: translateX(-50px); opacity: 1; }
    50% { transform: translateX(150px) scale(1.2); opacity: 1; }
    80% { transform: translateX(120px); opacity: 1; }
    100% { transform: translateX(-50px); opacity: 0; }
}
.anim-dash {
    animation: dash-attack 0.8s ease-out forwards;
    opacity: 1 !important;
}

@keyframes shake-damage {
    0% { transform: translate(1px, 1px) rotate(0deg); filter: brightness(1) drop-shadow(0 0 10px red); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); filter: brightness(1.5) drop-shadow(0 0 20px red); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); filter: brightness(1); }
}
.anim-shake {
    animation: shake-damage 0.5s;
}

@keyframes wolf-lunge {
    0% { transform: translateX(0); filter: drop-shadow(0 0 10px rgba(255, 153, 0, 0.5)); }
    10% { transform: translateX(-50px) scale(1.05); filter: drop-shadow(0 0 20px #ff9900); }
    20% { transform: translateX(-40px) scale(1.05); }
    30% { transform: translateX(0); filter: drop-shadow(0 0 10px rgba(255, 153, 0, 0.5)); }
    100% { transform: translateX(0); }
}
.anim-wolf-lunge {
    animation: wolf-lunge 2.5s infinite;
}

@keyframes win-symbol-pulse {
    0% { transform: scale(1); filter: brightness(1); background: transparent; }
    50% { transform: scale(1.1); filter: brightness(1.5); background: rgba(255, 215, 0, 0.4); border-radius: 10px; z-index: 20; box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);}
    100% { transform: scale(1); filter: brightness(1); background: transparent; }
}
.win-pulse {
    animation: win-symbol-pulse 0.6s infinite;
    z-index: 20;
}

@keyframes float-up {
    0% { transform: translateY(0) scale(0.5); opacity: 1; }
    20% { transform: translateY(-20px) scale(1.2); opacity: 1; }
    80% { transform: translateY(-50px) scale(1); opacity: 0.8; }
    100% { transform: translateY(-80px) scale(1); opacity: 0; }
}
.anim-damage-text {
    display: block !important;
    animation: float-up 1s ease-out forwards;
}

/* Bonus UI */
#bonus-indicator {
    align-self: flex-end;
    background: linear-gradient(135deg, #ff00ff, #ff0044);
    padding: 5px 15px;
    border-bottom-left-radius: 15px;
    color: white;
    font-weight: bold;
    text-shadow: 0 0 5px #fff;
    box-shadow: 0 0 10px #ff00ff;
    animation: pulse-bonus 1.5s infinite;
    display: flex;
    flex-direction: column;
    align-items: center;
}
#bonus-indicator.hidden { display: none !important; }

@keyframes pulse-bonus {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); filter: drop-shadow(0 0 20px #ff00ff); }
    100% { transform: scale(1); }
}

#bonus-panel {
    margin-top: 10px;
    background: rgba(255, 0, 100, 0.1);
    border: 2px dashed #ff0044;
    border-radius: 8px;
    padding: 10px;
}
.bonus-title {
    color: #ff99cc;
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 8px;
    font-weight: bold;
}
.bonus-buttons {
    display: flex;
    gap: 5px;
    justify-content: center;
}
.bonus-buttons button {
    background: #330011;
    color: #ff99cc;
    border: 1px solid #ff0044;
    border-radius: 4px;
    padding: 8px 5px;
    font-size: 0.75rem;
    cursor: pointer;
    flex: 1;
    transition: all 0.2s;
}
.bonus-buttons button:hover {
    background: #ff0044;
    color: white;
    box-shadow: 0 0 10px #ff0044;
}
