:root {
    --bg-dark: #0f171e;
    --bg-light: #2b3a42;
    --balatro-red: #ec4e20;
    --balatro-blue: #0197f6;
    --text-glow: #e0e0e0;
    --card-bg: #fdfbf7;
    --card-shadow: rgba(0, 0, 0, 0.6);
}

body {
    margin: 0;
    padding: 20px 0;
    font-family: 'Jersey 10', 'VT323', Courier, monospace;
    background: radial-gradient(circle at center, var(--bg-light), var(--bg-dark)) fixed;
    color: var(--text-glow);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* CRT Scanline Overlay */
.crt::before {
    content: " ";
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    z-index: 999;
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
}

#app {
    width: 100%;
    max-width: 1200px;
    height: auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
}
.sound-toggle { position: fixed; z-index: 1001; top: calc(14px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right)); min-height: 40px; padding: 7px 11px; color: #dff4ff; background: rgba(8, 20, 28, .86); border: 1px solid rgba(1,151,246,.7); border-radius: 99px; font: 20px 'VT323', monospace; cursor: pointer; box-shadow: 0 3px 12px rgba(0,0,0,.4); }
.sound-toggle[aria-pressed="true"] { color: #a9a9a9; border-color: #66757b; }

*, *::before, *::after { box-sizing: border-box; }

.screen {
    display: none;
    width: 100%;
    height: auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: auto;
}

.screen.active {
    display: flex;
}

h1.balatro-title {
    font-family: 'Jersey 10', monospace;
    font-size: 80px;
    margin-bottom: 10px;
    text-shadow: 4px 4px 0px #000, 0 0 20px rgba(255,255,255,0.5);
    letter-spacing: 4px;
}

.hidden { display: none !important; }

/* === Lobby === */
.card-panel {
    background: rgba(0, 0, 0, 0.6);
    padding: 40px;
    border-radius: 16px;
    border: 2px solid #444;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8), inset 0 0 20px rgba(0,0,0,0.5);
    width: 80%;
    max-width: 400px;
    text-align: center;
    backdrop-filter: blur(5px);
}

/* Lobby: keep every way to start a game visible without a long single column. */
#screen-lobby { padding: 28px 20px; }
#screen-lobby .card-panel { max-width: 860px; width: min(100%, 860px); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; padding: 28px; align-items: start; }
#screen-lobby .card-panel > #btn-show-rules-lobby,
#screen-lobby .card-panel > .lobby-label,
#screen-lobby .card-panel > #input-player-name,
#screen-lobby .card-panel > #lobby-status { grid-column: 1 / -1; }
#screen-lobby .card-panel > #btn-show-rules-lobby { margin: 0 !important; }
#screen-lobby .card-panel > .divider { display: none; }
#screen-lobby .quick-start, #screen-lobby .bot-start, #screen-lobby .host-section, #screen-lobby .join-section { min-height: 196px; margin: 0; padding: 18px; border: 1px solid rgba(119, 151, 166, .35); border-radius: 12px; background: rgba(255,255,255,.035); }
#screen-lobby .host-section, #screen-lobby .join-section { display: flex; flex-direction: column; }
#screen-lobby .join-section .primary-btn { margin-top: auto; }

.divider {
    color: #666;
    margin: 20px 0;
    font-size: 24px;
}

.balatro-input {
    width: calc(100% - 24px);
    padding: 12px;
    margin-bottom: 15px;
    background: rgba(255,255,255,0.1);
    border: 2px solid #555;
    border-radius: 8px;
    color: #fff;
    font-family: 'VT323', monospace;
    font-size: 24px;
    text-align: center;
}
.balatro-input:focus {
    outline: none;
    border-color: var(--balatro-blue);
    box-shadow: 0 0 10px var(--balatro-blue);
}

.balatro-btn {
    width: 100%;
    padding: 15px;
    border: 2px solid #000;
    border-radius: 8px;
    font-family: 'Jersey 10', monospace;
    font-size: 28px;
    cursor: pointer;
    text-transform: uppercase;
    transition: transform 0.1s, filter 0.1s, box-shadow 0.1s;
    color: white;
    text-shadow: 2px 2px 0px #000;
    box-shadow: 0 6px 0px #000;
}
.balatro-btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0px #000;
}
.balatro-btn:hover {
    filter: brightness(1.2);
}

.primary-btn { background-color: var(--balatro-red); }
.success-btn { background-color: var(--balatro-blue); margin-top: 15px; }

.glow-text {
    color: #fff;
    text-shadow: 0 0 10px var(--balatro-blue), 0 0 20px var(--balatro-blue);
    font-size: 32px;
}
.players-box {
    margin-top: 15px;
    padding: 10px;
    background: rgba(0,0,0,0.5);
    border: 1px dashed #666;
    font-family: 'VT323', monospace;
    font-size: 24px;
}

.quick-start { margin: 4px 0 22px; }
.quick-start h3, .bot-start h3, .host-section h3, .join-section h3 { font-size: 30px; margin: 0 0 8px; color: #ffeb3b; }
.bot-start { margin: 4px 0; }
.bot-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 15px; text-align: left; font-size: 20px; color: #c9d3d7; }
.bot-options label { display: grid; gap: 5px; }
.balatro-select { width: 100%; min-height: 42px; padding: 6px 8px; color: #fff; background: #27353c; border: 2px solid #55636a; border-radius: 7px; font: 20px 'VT323', monospace; }
.bot-btn { background: #7448d9; }
.text-btn { margin-top: 12px; border: 0; background: none; color: #a8dfff; font: 22px 'VT323', monospace; cursor: pointer; text-decoration: underline; }
.visibility-toggle { display: flex; align-items: center; gap: 12px; text-align: left; margin: 0 0 16px; padding: 12px; border: 1px solid #4b5d68; border-radius: 10px; cursor: pointer; }
.visibility-toggle input { position: absolute; opacity: 0; }
.visibility-toggle small { display: block; color: #aab5ba; font: 18px 'VT323', monospace; margin-top: 2px; }
.toggle-track { width: 42px; height: 24px; flex: 0 0 auto; border-radius: 99px; background: #48545b; position: relative; transition: background .2s; }
.toggle-track::after { content: ''; width: 18px; height: 18px; position: absolute; top: 3px; left: 3px; border-radius: 50%; background: #fff; transition: transform .2s; }
.visibility-toggle input:checked + .toggle-track { background: var(--balatro-blue); }
.visibility-toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.visibility-toggle:has(input:focus-visible) { outline: 2px solid var(--balatro-blue); outline-offset: 2px; }

/* === RPS Screen === */
.rps-choices {
    display: flex;
    gap: 30px;
    margin-top: 40px;
}
.rps-btn {
    font-size: 60px;
    background: rgba(255,255,255,0.1);
    border: 4px solid #444;
    border-radius: 16px;
    width: 120px;
    height: 120px;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}
.rps-btn:hover { 
    transform: scale(1.1) translateY(-10px); 
    border-color: var(--balatro-blue); 
    background: rgba(255,255,255,0.2);
}
.status-blink {
    animation: blink 1.5s infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }

/* === Game Screen Layout === */
.game-container {
    display: flex;
    width: 100%;
    height: auto;
    min-height: min(800px, 100vh);
    padding: 20px;
    box-sizing: border-box;
}

.sidebar {
    width: 250px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-right: 20px;
}

.score-panel, .deck-panel { min-height: 112px; justify-content: center; }
.opponents-panel { align-items: stretch; }

.sidebar-panel {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #555;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.panel-label {
    font-size: 20px;
    color: #aaa;
    letter-spacing: 2px;
    margin-bottom: 5px;
}

.score-value {
    font-family: 'Jersey 10', monospace;
    font-size: 64px;
    color: #fff;
    text-shadow: 2px 2px 0px #000, 0 0 15px rgba(255,255,255,0.3);
    line-height: 1;
}

.opponent-card {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.opponent-card.active-turn {
    border-color: var(--balatro-blue);
    box-shadow: 0 0 10px rgba(1, 151, 246, 0.5);
}
.opp-name { font-size: 24px; color: #ffeb3b; }
.opp-stat { font-family: 'VT323', monospace; font-size: 20px; }

.main-play-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}

.turn-text {
    font-size: 36px;
    letter-spacing: 2px;
    margin-top: 20px;
    color: var(--balatro-blue);
    text-shadow: 0 0 10px rgba(1, 151, 246, 0.8);
}

.play-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.played-cards-area {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.table-placeholder {
    border: 3px dashed #555;
    border-radius: 12px;
    width: 110px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #666;
}

/* === Action Bar & Buttons === */
.action-bar {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
}

.action-btn {
    padding: 12px 30px;
    font-family: 'Jersey 10', monospace;
    font-size: 32px;
    border: 2px solid #000;
    border-radius: 8px;
    cursor: pointer;
    color: white;
    text-shadow: 2px 2px 0px #000;
    box-shadow: 0 6px 0px #000, 0 10px 15px rgba(0,0,0,0.5);
    transition: transform 0.1s, box-shadow 0.1s;
}
.action-btn:active:not(:disabled) {
    transform: translateY(4px);
    box-shadow: 0 2px 0px #000;
}
.action-btn:disabled {
    filter: grayscale(1) opacity(0.5);
    cursor: not-allowed;
    box-shadow: 0 2px 0px #000;
    transform: translateY(4px);
}
.play-btn { background: var(--balatro-blue); }
.pass-btn { background: var(--balatro-red); }

/* === Balatro Style Cards === */
.hand-cards {
    display: flex;
    justify-content: center;
    flex-wrap: wrap; /* 允许换行 */
    gap: 0;
    padding: 20px 40px;
    perspective: 1000px;
}

.card {
    width: 120px;
    height: 175px;
    background: var(--card-bg);
    border-radius: 10px;
    border: 2px solid #222;
    box-shadow: -5px 5px 15px var(--card-shadow), inset 0 0 10px rgba(0,0,0,0.1);
    position: relative;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), margin 0.2s;
    font-family: -apple-system, sans-serif;
    margin-bottom: 20px;
}

.card:hover {
    transform: translateY(-25px) rotate(-2deg) scale(1.05);
    z-index: 50 !important;
    box-shadow: -10px 15px 25px rgba(0,0,0,0.8);
    margin-left: 15px;
    margin-right: 15px;
}

.card.selected {
    transform: translateY(-35px) scale(1.05);
    border-color: #ffeb3b;
    box-shadow: 0 0 20px #ffeb3b, 0 15px 30px rgba(0,0,0,0.8);
    z-index: 40;
}

.card-inner {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px;
    box-sizing: border-box;
}

.suit-red { color: #d32f2f; }
.suit-black { color: #111; }

.card-top, .card-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.card-top { align-self: flex-start; }
.card-bottom { align-self: flex-end; transform: rotate(180deg); }

.card .rank {
    font-size: 24px;
    font-weight: 900;
    letter-spacing: -1px;
}
.card .suit {
    font-size: 20px;
}

.card-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 54px;
}

/* === Rules Modal === */
.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: 1000;
    backdrop-filter: blur(10px);
}
.modal-content {
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    text-align: left;
}
.rules-text {
    font-family: 'VT323', monospace;
    font-size: 24px;
    line-height: 1.4;
    color: #ddd;
}
.rules-text p {
    margin-bottom: 15px;
}
.rules-text .highlight {
    color: var(--balatro-blue);
    font-weight: bold;
}

@media (max-width: 800px) {
    body { padding: 0; }
    #app { min-height: 100dvh; }
    #screen-lobby { padding: 22px 14px calc(28px + env(safe-area-inset-bottom)); justify-content: flex-start; }
    h1.balatro-title { font-size: clamp(56px, 15vw, 76px); margin: 0 0 14px; }
    #screen-lobby .card-panel { grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; border-radius: 12px; }
    #screen-lobby .quick-start, #screen-lobby .bot-start, #screen-lobby .host-section, #screen-lobby .join-section { min-height: 180px; padding: 14px; }
    #screen-lobby .host-section, #screen-lobby .join-section { grid-column: span 1; }
    .game-container { min-height: 100dvh; padding: 10px; flex-direction: column; gap: 12px; }
    .sidebar { width: 100%; margin: 0; display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
    .sidebar-panel { padding: 9px; border-radius: 9px; box-shadow: 0 4px 10px rgba(0,0,0,.45); }
    .score-panel, .deck-panel { min-height: 76px; }
    .panel-label { font-size: 15px; letter-spacing: 1px; }
    .score-value { font-size: 44px; }
    #btn-show-rules-game { min-width: 58px; padding: 8px !important; font-size: 0 !important; box-shadow: none; }
    #btn-show-rules-game::after { content: '?'; font-size: 28px; }
    .opponents-panel { grid-column: 1 / -1; display: flex; flex-direction: row; gap: 8px; overflow-x: auto; padding: 8px; scroll-snap-type: x proximity; }
    .opponent-card { flex: 0 0 132px; width: 132px; min-height: 72px; margin: 0; padding: 7px; scroll-snap-align: start; }
    .opp-name { font-size: 20px; white-space: nowrap; overflow: hidden; max-width: 118px; text-overflow: ellipsis; }
    .opp-stat { font-size: 17px; }
    .main-play-area { min-height: 0; width: 100%; }
    .turn-text { margin: 2px 0 8px; font-size: clamp(23px, 7vw, 32px); text-align: center; }
    .play-zone { min-height: 145px; align-items: flex-start; }
    .table-placeholder { width: 82px; height: 116px; font-size: 18px; }
    .player-area { width: 100%; position: sticky; bottom: 0; padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg-dark) 24%); }
    .action-bar { margin: 0 0 10px; gap: 10px; justify-content: stretch; }
    .action-btn { flex: 1; min-height: 48px; padding: 9px 12px; font-size: 26px; }
    .hand-cards { min-height: 128px; padding: 10px 2px 18px; flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; overflow-y: visible; gap: 0; -webkit-overflow-scrolling: touch; }
    .hand-cards .card { flex: 0 0 84px; width: 84px; height: 124px; margin: 0 -19px 0 0; }
    .hand-cards .card:last-child { margin-right: 8px; }
    .hand-cards .card:hover { transform: translateY(-12px); margin-left: 0; margin-right: -19px; }
    .hand-cards .card.selected { transform: translateY(-18px); }
    .card-inner { padding: 5px; }
    .card .rank { font-size: 18px; }.card .suit { font-size: 16px; }.card-center { font-size: 40px; }
    .modal-content { width: calc(100% - 24px); max-height: calc(100dvh - 32px); padding: 20px; }
    .rules-text { font-size: 20px; }
}

@media (max-width: 520px) {
    .sound-toggle { top: calc(8px + env(safe-area-inset-top)); right: calc(9px + env(safe-area-inset-right)); min-height: 36px; padding: 5px 9px; font-size: 17px; }
    #screen-lobby .card-panel { grid-template-columns: 1fr; }
    #screen-lobby .quick-start, #screen-lobby .bot-start, #screen-lobby .host-section, #screen-lobby .join-section { grid-column: auto; min-height: auto; }
    .bot-options { grid-template-columns: 1fr 1fr; }
    .balatro-btn { min-height: 48px; font-size: 25px; padding: 11px; }
    .balatro-input { min-height: 48px; font-size: 22px; }
    .rps-choices { gap: 10px; margin-top: 20px; }
    .rps-btn { width: min(27vw, 94px); height: min(27vw, 94px); font-size: 42px; }
    .play-zone { min-height: 110px; }
    .played-cards-area .card { transform: scale(.78); margin: -20px; }
}
