/* ============================================================
 *  Token 搖搖樂 - Pixel Edition v3
 *  Architecture-aligned stylesheet:
 *    - top-level layout (.game-container, .lobby-bar, .machines)
 *    - machine component (.machine ...) reusable for many instances
 *    - input bar / paytable / hotkeys / help modal
 *  Pure CSS, no preprocessor. Variables in :root.
 * ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

:root {
    --bg-dark:      #0d0221;
    --bg-mid:       #241734;
    --neon-pink:    #ff2e93;
    --neon-cyan:    #00f0ff;
    --neon-yellow:  #ffd60a;
    --neon-green:   #39ff14;
    --neon-purple:  #b026ff;
    --machine-body: #c93f55;
    --machine-shadow: #6b1f2c;
    --machine-light:  #ff7088;
    --screen-bg:   #1a0b2e;
    --screen-edge: #4a1942;
    --focus-ring:  #ffd60a;
}

html, body {
    height: 100%;
    font-family: 'Press Start 2P', "Microsoft JhengHei", "PingFang TC", monospace;
    background:
        radial-gradient(ellipse at top, #2d0a4e 0%, transparent 50%),
        radial-gradient(ellipse at bottom, #5a0e3d 0%, transparent 50%),
        var(--bg-dark);
    color: white;
    overflow-x: hidden;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: none;
    user-select: none;
}

.crt-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15) 0px,
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 3px
    );
    z-index: 1000;
    mix-blend-mode: multiply;
}

.game-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 16px 40px;
    gap: 24px;
}

/* === Title bar === */
.game-header {
    text-align: center;
    margin-top: 8px;
    position: relative;
    width: 100%;
    max-width: 1100px;
}
.sound-btn {
    position: absolute;
    top: -4px;
    right: 0;
    background: var(--bg-mid);
    color: var(--neon-cyan);
    border: 3px solid #000;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 9px;
    cursor: pointer;
    letter-spacing: 1px;
    box-shadow:
        inset -2px -2px 0 #110821,
        inset 2px 2px 0 #4a2d70,
        3px 3px 0 rgba(0, 0, 0, 0.5);
}
.sound-btn:hover { color: var(--neon-yellow); }
.sound-btn:active { transform: translate(1px, 1px); }
.sound-btn.muted { color: #777; }

.title {
    font-size: 42px;
    letter-spacing: 4px;
    text-shadow:
        3px 3px 0 var(--neon-pink),
        6px 6px 0 var(--neon-purple),
        9px 9px 0 rgba(0, 0, 0, 0.6);
    margin-bottom: 12px;
    line-height: 1;
}
.title span {
    display: inline-block;
    animation: bounce 2s ease-in-out infinite;
}
.title .title-tk-1 { color: #ff8c69; animation-delay: 0s;    }
.title .title-tk-2 { color: #ffd60a; animation-delay: 0.08s; }
.title .title-tk-3 { color: #00f0ff; animation-delay: 0.16s; }
.title .title-tk-4 { color: #b026ff; animation-delay: 0.24s; }
.title .title-tk-5 { color: #39ff14; animation-delay: 0.32s; }
.title .title-space { width: 18px; }
.title .title-cn-1 { color: #00f0ff; animation-delay: 0.40s; }
.title .title-cn-2 { color: #ff2e93; animation-delay: 0.48s; }
.title .title-cn-3 { color: #39ff14; animation-delay: 0.56s; }

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

.subtitle {
    font-size: 14px;
    color: var(--neon-cyan);
    letter-spacing: 2px;
    text-shadow: 2px 2px 0 #003344;
}

/* === Lobby bar === */
.lobby-bar {
    width: min(1100px, 100%);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px 18px;
    padding: 16px 20px;
    background: var(--bg-mid);
    border: 4px solid #000;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5);
}
.lobby-stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-right: 14px;
    border-right: 2px dashed rgba(255,255,255,0.1);
    min-width: 130px;
}
.lobby-stat:last-of-type { border-right: none; }
.lobby-label {
    font-size: 10px;
    letter-spacing: 1px;
    color: var(--neon-cyan);
}
.lobby-value {
    font-size: 22px;
    color: var(--neon-yellow);
    text-shadow: 0 0 6px rgba(255, 214, 10, 0.7);
}
.lobby-value.win-value {
    color: var(--neon-green);
    text-shadow: 0 0 6px var(--neon-green);
}
.lobby-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.lobby-btn {
    background: var(--neon-green);
    color: #003a00;
    border: 3px solid #000;
    padding: 12px 18px;
    font-family: inherit;
    font-size: 12px;
    letter-spacing: 2px;
    cursor: pointer;
    box-shadow:
        inset -3px -3px 0 #1f8c10,
        inset 3px 3px 0 #b3ff8a,
        3px 3px 0 rgba(0, 0, 0, 0.5);
}
.lobby-btn:hover { filter: brightness(1.1); }
.lobby-btn:active { transform: translate(2px, 2px); }
.lobby-btn:disabled {
    background: #555;
    color: #222;
    cursor: not-allowed;
    box-shadow: inset -3px -3px 0 #222, inset 3px 3px 0 #777;
}
.lobby-btn.add-btn {
    background: var(--neon-yellow);
    color: #4a3500;
    box-shadow:
        inset -3px -3px 0 #b8950a,
        inset 3px 3px 0 #ffe97a,
        3px 3px 0 rgba(0, 0, 0, 0.5);
}
.lobby-btn.spin-all-btn {
    background: var(--neon-pink);
    color: #2a0014;
    box-shadow:
        inset -3px -3px 0 #80174a,
        inset 3px 3px 0 #ff7eb8,
        3px 3px 0 rgba(0, 0, 0, 0.5);
}

/* Floating notice (e.g. "已達上限") */
.lobby-notice {
    width: min(1100px, 100%);
    text-align: center;
    color: var(--neon-yellow);
    font-size: 11px;
    letter-spacing: 1px;
    min-height: 16px;
    opacity: 0;
    transition: opacity 0.2s;
    text-shadow: 0 0 6px var(--neon-yellow);
    margin-top: -14px;
}
.lobby-notice.shown { opacity: 1; }

/* === Machines grid: layout depends on count (1..6), centred. === */
.machines {
    width: min(1100px, 100%);
    display: grid;
    gap: 24px;
    align-items: start;
    justify-content: center;
}
/* Per-count rules (max 3 columns, max 6 machines).
   For uneven last rows we use 6-column tracks so we can centre 1-2 items
   on the last row by spanning 3 tracks each. */
.machines[data-count="1"] { grid-template-columns: minmax(360px, 480px); }
.machines[data-count="2"] { grid-template-columns: repeat(2, minmax(340px, 460px)); }
.machines[data-count="3"] { grid-template-columns: repeat(3, minmax(280px, 1fr)); }
.machines[data-count="4"] { grid-template-columns: repeat(2, minmax(340px, 460px)); }
.machines[data-count="5"] {
    /* 6-column virtual grid: first row uses tracks 1-2, 3-4, 5-6;
       second row centres two items at tracks 2-3, 4-5. */
    grid-template-columns: repeat(6, 1fr);
}
.machines[data-count="5"] > .machine:nth-child(1) { grid-column: 1 / span 2; }
.machines[data-count="5"] > .machine:nth-child(2) { grid-column: 3 / span 2; }
.machines[data-count="5"] > .machine:nth-child(3) { grid-column: 5 / span 2; }
.machines[data-count="5"] > .machine:nth-child(4) { grid-column: 2 / span 2; }
.machines[data-count="5"] > .machine:nth-child(5) { grid-column: 4 / span 2; }
.machines[data-count="6"] { grid-template-columns: repeat(3, minmax(280px, 1fr)); }

/* === Machine component (instance) === */
.machine {
    background: var(--machine-body);
    border: 4px solid #000;
    padding: 16px;
    position: relative;
    box-shadow:
        inset -6px -6px 0 var(--machine-shadow),
        inset 6px 6px 0 var(--machine-light),
        8px 8px 0 rgba(0, 0, 0, 0.6);
    cursor: pointer;
    transition: outline 0.1s, transform 0.1s;
    outline: 3px solid transparent;
    outline-offset: 2px;
}
.machine.focused {
    outline-color: var(--focus-ring);
    box-shadow:
        inset -6px -6px 0 var(--machine-shadow),
        inset 6px 6px 0 var(--machine-light),
        8px 8px 0 rgba(0, 0, 0, 0.6),
        0 0 24px var(--focus-ring);
}
.machine-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.machine-label {
    color: white;
    font-size: 13px;
    letter-spacing: 2px;
    text-shadow: 2px 2px 0 var(--machine-shadow);
}
.remove-btn {
    background: var(--bg-mid);
    color: #ff5555;
    border: 2px solid #000;
    width: 30px;
    height: 30px;
    font-family: inherit;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    box-shadow: inset -2px -2px 0 #110821, inset 2px 2px 0 #4a2d70;
}
.remove-btn:hover { color: #ff8888; }

.machine-top {
    display: flex;
    justify-content: space-between;
    padding: 8px 6px;
    margin-bottom: 12px;
    background: #000;
    border: 3px solid var(--machine-shadow);
}
.bulb {
    width: 12px;
    height: 12px;
    background: var(--neon-yellow);
    border-radius: 50%;
    box-shadow: 0 0 6px var(--neon-yellow);
    animation: blink 1s steps(2, start) infinite;
}
.bulb:nth-child(odd)  { animation-delay: 0s;   background: var(--neon-pink);   box-shadow: 0 0 6px var(--neon-pink); }
.bulb:nth-child(even) { animation-delay: 0.5s; background: var(--neon-cyan);   box-shadow: 0 0 6px var(--neon-cyan); }

@keyframes blink {
    0%, 49%   { opacity: 1; }
    50%, 100% { opacity: 0.25; }
}

/* === Reels === */
.screen {
    background: var(--screen-bg);
    border: 4px solid #000;
    box-shadow: inset 0 0 0 3px var(--screen-edge), inset 0 0 30px rgba(0, 240, 255, 0.15);
    padding: 12px;
    position: relative;
}
.reels {
    display: flex;
    gap: 8px;
    justify-content: center;
    height: 130px;
    position: relative;
    overflow: hidden;
    background: #000;
    border: 3px solid #000;
    padding: 4px;
}
.reel {
    flex: 1;
    height: 100%;
    background: #110821;
    overflow: hidden;
    position: relative;
    border: 2px solid #2a1147;
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.8);
}
.reel-strip {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    transition: none;
}
.reel-cell {
    height: 118px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.reel-cell svg {
    width: 88px;
    height: 88px;
}
.payline {
    position: absolute;
    left: 12px;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    height: 2px;
    background: var(--neon-yellow);
    box-shadow: 0 0 10px var(--neon-yellow);
    pointer-events: none;
    opacity: 0.5;
}
.reel.win {
    animation: reelWin 0.4s ease-in-out 6;
}
@keyframes reelWin {
    0%, 100% { box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.8); border-color: #2a1147; }
    50%      { box-shadow: inset 0 0 24px var(--neon-yellow); border-color: var(--neon-yellow); }
}

/* === Info panel === */
.info-panel {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 8px;
    margin-top: 12px;
}
.info-box {
    background: #000;
    border: 3px solid var(--machine-shadow);
    padding: 8px 6px;
    text-align: center;
}
.info-label {
    font-size: 10px;
    color: var(--neon-cyan);
    margin-bottom: 6px;
    letter-spacing: 1px;
}
.info-value {
    font-size: 20px;
    color: var(--neon-yellow);
    text-shadow: 0 0 6px rgba(255, 214, 10, 0.7);
    min-height: 22px;
    line-height: 1;
    word-break: break-all;
}
.info-value.win-value {
    color: var(--neon-green);
    text-shadow: 0 0 6px var(--neon-green);
}
.bet-controls {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 6px;
}
.bet-btn {
    background: var(--neon-pink);
    color: white;
    border: 2px solid #000;
    width: 32px;
    height: 28px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    box-shadow: inset -2px -2px 0 #80174a, inset 2px 2px 0 #ff7eb8;
}
.bet-btn.allin {
    background: var(--neon-yellow);
    color: #4a3500;
    box-shadow: inset -2px -2px 0 #b8950a, inset 2px 2px 0 #ffe97a;
}
.bet-btn:hover { filter: brightness(1.15); }
.bet-btn:active { transform: translate(1px, 1px); }
.bet-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Spin / Auto buttons === */
.controls {
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 8px;
    margin-top: 12px;
}
.spin-btn {
    padding: 14px 0;
    background: var(--neon-green);
    color: #003a00;
    border: 4px solid #000;
    font-family: inherit;
    font-size: 20px;
    letter-spacing: 4px;
    cursor: pointer;
    box-shadow:
        inset -4px -4px 0 #1f8c10,
        inset 4px 4px 0 #b3ff8a,
        4px 4px 0 rgba(0, 0, 0, 0.5);
}
.spin-btn:hover { filter: brightness(1.1); }
.spin-btn:active {
    transform: translate(2px, 2px);
    box-shadow:
        inset 4px 4px 0 #1f8c10,
        inset -4px -4px 0 #b3ff8a,
        2px 2px 0 rgba(0, 0, 0, 0.5);
}
.spin-btn:disabled {
    background: #555;
    color: #222;
    cursor: not-allowed;
    box-shadow: inset -4px -4px 0 #222, inset 4px 4px 0 #777;
}
.spin-btn.auto {
    background: var(--neon-pink);
    color: #2a0014;
    box-shadow:
        inset -4px -4px 0 #80174a,
        inset 4px 4px 0 #ff7eb8,
        4px 4px 0 rgba(0, 0, 0, 0.5);
    animation: autoPulse 0.6s ease-in-out infinite alternate;
}
.auto-btn {
    background: var(--neon-cyan);
    color: #002233;
    border: 4px solid #000;
    font-family: inherit;
    font-size: 13px;
    letter-spacing: 2px;
    cursor: pointer;
    box-shadow:
        inset -3px -3px 0 #007a8a,
        inset 3px 3px 0 #aef9ff,
        3px 3px 0 rgba(0, 0, 0, 0.5);
}
.auto-btn:hover { filter: brightness(1.1); }
.auto-btn:active { transform: translate(2px,2px); }

@keyframes autoPulse {
    from { filter: brightness(1); }
    to   { filter: brightness(1.25); }
}
.auto-counter {
    font-size: 11px;
    color: var(--neon-yellow);
    margin-top: 8px;
    text-align: center;
    text-shadow: 0 0 4px var(--neon-yellow);
    min-height: 14px;
    letter-spacing: 1px;
}
.message {
    text-align: center;
    margin-top: 10px;
    font-size: 13px;
    color: var(--neon-cyan);
    min-height: 20px;
    text-shadow: 0 0 4px var(--neon-cyan);
    letter-spacing: 1px;
}
.message.win  { color: var(--neon-yellow); text-shadow: 0 0 8px var(--neon-yellow); animation: shake 0.2s 4; }
.message.big  { color: var(--neon-pink);   text-shadow: 0 0 10px var(--neon-pink);  font-size: 15px; animation: shake 0.2s 6; }
.message.lose { color: #ff5555; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-3px); }
    75%      { transform: translateX(3px); }
}

.win-popup {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--neon-yellow);
    font-size: 28px;
    text-shadow: 3px 3px 0 var(--neon-pink), 0 0 12px var(--neon-yellow);
    pointer-events: none;
    z-index: 10;
    animation: winPop 1.2s ease-out forwards;
}
@keyframes winPop {
    0%   { transform: translate(-50%, -50%) scale(0.2); opacity: 0; }
    20%  { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
    60%  { transform: translate(-50%, -80%) scale(1);   opacity: 1; }
    100% { transform: translate(-50%, -160%) scale(1);  opacity: 0; }
}

/* === Paytable === */
.paytable {
    width: min(1100px, 100%);
    background: var(--bg-mid);
    border: 4px solid #000;
    padding: 16px;
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.5);
}
.paytable-title {
    text-align: center;
    color: var(--neon-yellow);
    font-size: 14px;
    margin-bottom: 14px;
    letter-spacing: 2px;
    text-shadow: 0 0 6px var(--neon-yellow);
}
.paytable-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 2px dashed rgba(255, 255, 255, 0.1);
    font-size: 12px;
}
.paytable-row:last-child { border-bottom: none; }
.symbol-mini {
    width: 40px;
    height: 40px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    flex-shrink: 0;
}
.multiplier {
    margin-left: auto;
    color: var(--neon-green);
    font-size: 14px;
    text-shadow: 0 0 4px var(--neon-green);
}
.paytable-mix .any-text { color: white; font-size: 12px; }

/* === Hotkeys bar === */
.hotkeys-bar {
    width: min(1100px, 100%);
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    justify-content: center;
    padding: 14px 16px;
    background: rgba(0, 0, 0, 0.5);
    border: 3px solid #000;
    box-shadow: inset 0 0 0 2px var(--bg-mid), 4px 4px 0 rgba(0, 0, 0, 0.5);
    font-size: 10px;
    color: #d0c8e8;
    letter-spacing: 1px;
}
.hk-item { display: inline-flex; align-items: center; gap: 5px; }
kbd {
    display: inline-block;
    background: var(--bg-mid);
    color: var(--neon-yellow);
    border: 2px solid #000;
    padding: 3px 6px;
    font-family: inherit;
    font-size: 10px;
    line-height: 1;
    box-shadow: inset -1px -1px 0 #110821, inset 1px 1px 0 #4a2d70;
    min-width: 12px;
    text-align: center;
}

/* === Help modal === */
.help-modal[hidden] { display: none !important; }
.help-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 16px;
}
.help-card {
    background: var(--bg-mid);
    border: 4px solid #000;
    padding: 24px 24px 18px;
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.5);
    max-width: 520px;
    width: 100%;
}
.help-title {
    text-align: center;
    color: var(--neon-yellow);
    font-size: 16px;
    letter-spacing: 2px;
    margin-bottom: 18px;
    text-shadow: 0 0 8px var(--neon-yellow);
}
.help-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    color: white;
}
.help-table td {
    padding: 7px 6px;
    border-bottom: 2px dashed rgba(255, 255, 255, 0.1);
}
.help-table td:first-child {
    width: 45%;
    color: var(--neon-cyan);
}
.help-table tr:last-child td { border-bottom: none; }
.help-foot {
    text-align: center;
    color: #999;
    font-size: 10px;
    margin-top: 14px;
    letter-spacing: 1px;
}

/* === Mobile === */
@media (max-width: 720px) {
    .machines[data-count] { grid-template-columns: 1fr !important; }
    .machines[data-count="5"] > .machine:nth-child(4),
    .machines[data-count="5"] > .machine:nth-child(5) { grid-column: auto; max-width: none; }
    .lobby-bar { flex-direction: column; align-items: stretch; }
    .lobby-stat { border-right: none; border-bottom: 2px dashed rgba(255,255,255,0.1); padding-bottom: 8px; padding-right: 0; }
    .lobby-actions { margin-left: 0; }
}
@media (max-width: 480px) {
    .title { font-size: 28px; letter-spacing: 2px; }
    .reels { height: 110px; }
    .reel-cell { height: 100px; }
    .reel-cell svg { width: 72px; height: 72px; }
    .info-value { font-size: 16px; }
    .lobby-value { font-size: 18px; }
    .spin-btn { font-size: 16px; padding: 12px 0; }
    .hotkeys-bar { font-size: 9px; }
    kbd { font-size: 9px; padding: 2px 4px; }
}
