:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --primary-color: #00e5ff;
    /* Cyan Neon */
    --secondary-color: #ff00ff;
    /* Magenta Neon */
    --text-color: #e0e0e0;
    --text-muted: #a0a0a0;
    --border-color: #333;
    --success-color: #00ff9d;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 800px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-sizing: border-box;
}

header {
    text-align: center;
    margin-bottom: 20px;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 0 0 10px var(--primary-color);
    color: #fff;
}

/* Mode Switcher */
.mode-switcher {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

button {
    cursor: pointer;
    border: none;
    outline: none;
    font-family: inherit;
    transition: all 0.3s ease;
}

.mode-switcher button {
    background: var(--surface-color);
    color: var(--text-muted);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
}

.mode-switcher button.active {
    background: var(--primary-color);
    color: #000;
    font-weight: bold;
    box-shadow: 0 0 15px var(--primary-color);
    border-color: var(--primary-color);
}

/* Game Sections */
.game-section {
    background: var(--surface-color);
    padding: 20px;
    border-radius: 15px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.game-section.hidden {
    display: none;
}

/* Controls */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.control-group {
    flex: 1;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    justify-content: flex-end;
    /* Align to bottom so label spacer works */
}

.control-group.full-width {
    flex-basis: 100%;
}

label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

input,
select,
textarea {
    background: #2a2a2a;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: 5px;
    font-family: inherit;
    font-size: 1rem;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-color);
    outline: none;
}

/* Game Area */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    min-height: 200px;
}

#dice-container {
    width: 100%;
    min-height: 150px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    padding: 20px;
    background: #151515;
    border-radius: 10px;
    border: 1px dashed var(--border-color);
}

.placeholder-text {
    color: var(--text-muted);
    font-style: italic;
}

.action-btn {
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    padding: 12px 40px;
    border-radius: 30px;
    font-size: 1.2rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.3);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 30px rgba(255, 0, 255, 0.5);
}

.action-btn:active {
    transform: translateY(1px);
}

.secondary-btn {
    background: rgba(255, 0, 255, 0.1);
    border: 2px solid var(--secondary-color);
    color: var(--secondary-color);
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.secondary-btn:hover {
    background: rgba(255, 0, 255, 0.2);
    box-shadow: 0 0 15px rgba(255, 0, 255, 0.4);
    transform: translateY(-2px);
}

.secondary-btn:active {
    transform: translateY(0px);
}

li {
    margin-bottom: 5px;
}

/* Dice Styles */
.dice {
    width: clamp(50px, 10vw, 80px);
    height: clamp(50px, 10vw, 80px);
    background: var(--surface-color);
    border: 2px solid var(--primary-color);
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    color: #fff;
    box-shadow: 0 0 10px var(--primary-color);
    transition: transform 0.2s;
    position: relative;
}

.dice::after {
    content: attr(data-type);
    position: absolute;
    bottom: 2px;
    right: 5px;
    font-size: 0.6rem;
    color: var(--text-muted);
}

.dice.rolling {
    animation: shake 0.5s infinite;
    color: var(--secondary-color);
    border-color: var(--secondary-color);
    box-shadow: 0 0 15px var(--secondary-color);
}

@keyframes shake {
    0% {
        transform: translate(1px, 1px) rotate(0deg);
    }

    10% {
        transform: translate(-1px, -2px) rotate(-1deg);
    }

    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);
    }
}

.winner-highlight {
    color: var(--success-color);
    font-weight: bold;
    transform: translateX(-20px);
}

.tie-indicator {
    color: #FFD700;
    font-weight: bold;
    margin-left: 5px;
    font-size: 0.9em;
}

/* Physics Controls */
.physics-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
    width: 100%;
}

/* Physics Canvas */
#physics-canvas-container {
    width: 100%;
    height: clamp(250px, 70vh, 600px);
    background: #000;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Responsive - Tablet (768px) */
@media (max-width: 768px) {
    .roulette-container {
        max-width: clamp(300px, 70vw, 400px);
    }
}

/* Responsive - Mobile Large (600px) */
@media (max-width: 600px) {
    h1 {
        font-size: 2rem;
    }

    .controls {
        flex-direction: column;
    }

    .control-group {
        width: 100%;
    }

    .app-container {
        padding: 10px;
    }

    .game-section {
        padding: 15px;
    }

    .action-btn {
        font-size: 1rem;
        padding: 12px 30px;
        min-height: 44px;
    }

    .secondary-btn {
        min-height: 44px;
        padding: 10px 24px;
    }

    .roulette-container {
        max-width: clamp(250px, 60vw, 300px);
    }

    .dice {
        font-size: 1.5rem;
    }

    .roulette-indicator {
        font-size: 2rem;
        right: -15px;
    }

    #modal-result-text {
        font-size: 2rem;
    }

    .modal-content {
        padding: 20px;
        min-width: 250px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }

    .action-btn {
        font-size: 0.9rem;
        padding: 10px 24px;
        min-height: 44px;
    }

    .secondary-btn {
        min-height: 44px;
        padding: 10px 20px;
    }

    .mode-switcher button {
        font-size: 0.8rem;
        padding: 8px 15px;
        min-height: 40px;
    }

    .dice {
        font-size: 1.2rem;
    }

    .roulette-container {
        max-width: clamp(200px, 55vw, 250px);
    }

    .roulette-indicator {
        font-size: 1.5rem;
        right: -10px;
    }

    textarea,
    input,
    select {
        padding: 8px 10px;
        font-size: 0.9rem;
        min-height: 44px;
    }
}

/* 행운의 룰렛 */
.roulette-container {
    position: relative;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    max-width: 500px;
    margin: 0 auto 20px;
}

#roulette-canvas {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    transition: transform 5s cubic-bezier(0.25, 0.1, 0.25, 1);
    /* CSS transition for simple spin, but we use JS */
}

.roulette-indicator {
    position: absolute;
    top: 50%;
    right: -20px;
    transform: translateY(-50%);
    font-size: 3rem;
    color: #fff;
    text-shadow: 0 0 10px #ff0000;
    z-index: 10;
    pointer-events: none;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--surface-color);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    border: 2px solid var(--primary-color);
    box-shadow: 0 0 50px var(--primary-color);
    position: relative;
    min-width: 300px;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.hidden .modal-content {
    transform: scale(0.7);
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-muted);
}

.close-modal:hover {
    color: #fff;
}

#modal-result-text {
    font-size: 3rem;
    font-weight: bold;
    margin: 20px 0;
    color: var(--secondary-color);
    text-shadow: 0 0 20px var(--secondary-color);
}

/* Confetti */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #f00;
    animation: fall linear forwards;
}

@keyframes fall {
    to {
        transform: translateY(100vh) rotate(720deg);
    }
}

/* Footer Styles */
.app-footer {
    text-align: center;
    padding: 20px;
    margin-top: 30px;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.app-footer p {
    margin: 0;
}

.app-footer a {
    color: var(--primary-color);
    text-shadow: 0 0 8px var(--primary-color);
    font-weight: 600;
    text-decoration: none;
}

.app-footer a:hover,
.app-footer a:focus-visible {
    text-decoration: underline;
}

.app-footer .version {
    color: var(--secondary-color);
    font-weight: 500;
}

/* Version 2: clearer game state, race HUD, and accessible controls. */
body { background: radial-gradient(ellipse at 50% 0, #132333 0, #121212 60%); }
.app-container { max-width: 920px; }
header { margin-bottom: 0; }
h1 { margin-bottom: 4px; }
.header-caption { color: #a4b9c9; margin-bottom: 24px; font-size: .9rem; }
.mode-switcher { flex-wrap: wrap; }
.section-heading { margin-bottom: 24px; }
.eyebrow { color: var(--primary-color); font-size: .72rem; letter-spacing: .13em; }
.section-heading h2 { margin: 5px 0 8px; font-size: 1.5rem; color: #f0f7fc; }
.section-heading p, .helper-text { color: #aab7c5; font-size: .85rem; }
button:focus-visible, summary:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
    outline: 3px solid #ffdf85; outline-offset: 4px;
}
button:disabled { cursor: default; opacity: .45; transform: none; box-shadow: none; }
.action-btn { color: #081a25; background: linear-gradient(110deg, #00e5ff, #8beeea); box-shadow: 0 0 20px #00e5ff22; }
.secondary-btn { color: #d1b9f7; border-color: #7e629d; background: #302338; }
.button-row, .physics-controls { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.game-status { color: #bceff7; text-align: center; padding: 10px; }
.results h3 { color: #b4cfdd; font-size: .95rem; margin-bottom: 12px; }
.results ul, .results ol { list-style-position: inside; }
#dice-logs, #roulette-history, #physics-ranking { max-height: 420px; overflow-y: auto; }
.log-entry { list-style: none; background: #151a22; padding: 14px; border-radius: 10px; margin: 10px 0; border-left: 3px solid #526171; }
.log-entry strong { display: block; margin-bottom: 8px; color: #bbd9e9; }
.log-entry ul { padding-left: 10px; font-size: .9rem; }
.won-round { border-left-color: var(--success-color); }
.race-dashboard { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; font-size: .85rem; color: #b5d8e6; }
.race-setup { margin-bottom: 20px; }
.race-setup summary { cursor: pointer; color: #b4cfdd; font-size: .9rem; padding: 8px 0; }
.race-setup .controls { margin-top: 12px; }
#physics-status { color: #9cedc5; }
#race-time { font-variant-numeric: tabular-nums; }
.race-progress { width: 100%; height: 4px; background: #283441; border-radius: 8px; overflow: hidden; margin-top: -10px; }
#race-progress-fill { width: 0; height: 100%; background: linear-gradient(90deg, #00e5ff, #c49cff); transition: width .2s; }
#physics-canvas-container { height: clamp(320px, 62vh, 600px); border-color: #244553; background: #0b101d; }
.race-camera { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; width: 100%; font-size: .85rem; }
.race-camera select { font-size: .85rem; max-width: 65%; }
#race-leader { color: #c9e9ba; margin-left: auto; overflow-wrap: anywhere; }
#physics-ranking li, #roulette-history li { padding: 10px 14px; background: #151a22; border-radius: 8px; margin-bottom: 8px; overflow-wrap: anywhere; }
#physics-ranking .ranking-winner { border: 1px solid #429577; color: #9cedc5; }
.input-error { color: #ffbba6; font-size: .85rem; min-height: 1.4em; }
.probability-panel { padding: 14px; margin-bottom: 22px; border: 1px solid #354354; border-radius: 10px; color: #bcd3e4; }
.probability-panel summary { cursor: pointer; }
#roulette-probabilities { list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 6px 16px; margin-top: 12px; font-size: .85rem; overflow-wrap: anywhere; }
.roulette-container { max-width: 470px; width: calc(100% - 30px); }
.roulette-indicator { right: -17px; font-size: 2.4rem; color: #fff3b5; text-shadow: 0 0 10px #ffd66e66; }
.modal.hidden { display: none; }
.modal-content { min-width: 0; width: min(90vw, 500px); max-height: 85vh; overflow-y: auto; }
.close-modal { background: transparent; min-width: 44px; min-height: 44px; padding: 0; }
#modal-result-text { font-size: clamp(1.5rem, 5vw, 3rem); overflow-wrap: anywhere; }
#confetti-container { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.confetti { top: -15px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 14px 22px; background: #213244; border: 1px solid #4e8198; color: #e4f7ff; border-radius: 12px; max-width: min(90vw, 600px); z-index: 3000; box-shadow: 0 8px 30px #0008; overflow-wrap: anywhere; }
.toast[hidden] { display: none; }
@media (max-width: 600px) {
    .section-heading h2 { font-size: 1.25rem; }
    .roulette-container { max-width: 340px; }
    .physics-controls { gap: 8px; }
    .physics-controls button { padding: 10px 16px; font-size: .85rem; }
    .race-dashboard { font-size: .75rem; }
    .race-camera select { max-width: 75%; }
    #race-leader { width: 100%; margin-left: 0; }
    textarea, input, select { font-size: 1rem; }
    .modal-content { padding: 24px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

.race-stage { display: grid; grid-template-columns: minmax(0, 1fr) 116px; gap: 12px; width: 100%; }
.minimap-panel { display: flex; flex-direction: column; height: clamp(320px, 62vh, 600px); padding: 8px; border: 1px solid #315066; border-radius: 10px; background: #101a28; overflow: hidden; }
.minimap-panel h3 { color: #bfdeec; font-size: .75rem; text-align: center; margin-bottom: 6px; }
.minimap-panel p { color: #819ab0; font-size: .65rem; text-align: center; margin-top: 4px; }
#race-minimap { flex: 1; width: 100%; height: 0; min-height: 0; cursor: crosshair; touch-action: manipulation; }
.race-highlights { width: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: -8px; font-size: .8rem; }
#race-action { color: #b2c5d6; flex: 1; min-width: 180px; }
#race-overtakes { color: #f4da98; font-variant-numeric: tabular-nums; }
.live-standings { display: flex; gap: 7px; flex-wrap: wrap; width: 100%; margin-top: -8px; }
.standing-chip { border: 1px solid; border-left-width: 4px; background: #142132; color: #dcebf6; padding: 8px 10px; border-radius: 7px; font-size: .8rem; max-width: 170px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.wheel-options { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; }
.wheel-options label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.wheel-options input { min-height: 0; accent-color: var(--primary-color); width: 18px; height: 18px; }
@media (max-width: 600px) {
    .race-stage { grid-template-columns: minmax(0, 1fr) 68px; gap: 6px; }
    .minimap-panel { padding: 4px; }
    .minimap-panel h3 { font-size: .65rem; }
    .minimap-panel p { font-size: .55rem; }
    .race-highlights { font-size: .72rem; }
    .standing-chip { max-width: 135px; font-size: .72rem; }
}

.mode-switcher { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 660px; margin: 0 auto 24px; }
.mode-switcher button { min-height: 44px; padding: 10px 8px; border-radius: 12px; }
.party-setup { margin-bottom: 16px; }
.party-setup summary { cursor: pointer; color: #b4cfdd; padding: 8px 0; font-size: .9rem; }
.party-setup .controls { margin-top: 12px; }
.party-canvas-wrap { width: 100%; border: 1px solid #2f4c60; border-radius: 12px; overflow: hidden; margin: 12px 0 20px; background: #0b1423; }
.party-canvas-wrap canvas { width: 100%; height: auto; aspect-ratio: 800 / 560; }
#bomb-history, #ladder-history { margin-top: 12px; max-height: 360px; overflow-y: auto; padding: 0; list-style: none; }
#bomb-history li, #ladder-history li { padding: 12px 14px; margin-bottom: 8px; background: #152133; border-radius: 8px; overflow-wrap: anywhere; }
#mode-bomb .results, #mode-ladder .results { margin-top: 22px; }
#ladder-players .revealed { background: #203d36; }
#ladder-players .selected { box-shadow: 0 0 0 2px #e7f9ff; }
#ladder-canvas { cursor: pointer; }
.number-stepper { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; gap: 8px; align-items: center; }
.stepper-button { width: 48px; height: 48px; border: 1px solid #3a6b7b; border-radius: 10px; background: #193442; color: #baf4ff; font-size: 1.6rem; font-weight: bold; touch-action: manipulation; }
.stepper-value { position: relative; }
#player-count { width: 100%; height: 48px; text-align: center; padding: 8px 35px 8px 12px; font-size: 1.2rem; font-weight: bold; appearance: textfield; -moz-appearance: textfield; }
#player-count::-webkit-inner-spin-button, #player-count::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-value span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: .85rem; color: #a9c4d6; pointer-events: none; }
#player-count-help { min-height: 2.5em; font-size: .75rem; }
.cards-board { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 16px; margin-bottom: 24px; }
.luck-card { display: flex; flex-direction: column; gap: 10px; background: transparent; color: #d4e8f3; padding: 4px; border-radius: 10px; perspective: 800px; }
.card-person { overflow-wrap: anywhere; font-weight: bold; }
.card-flipper { display: block; position: relative; width: 100%; height: 155px; transform-style: preserve-3d; transition: transform .55s ease; }
.card-front, .card-back { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 2px solid #456e91; border-radius: 12px; backface-visibility: hidden; }
.card-front { background: repeating-linear-gradient(45deg, #18354f 0, #18354f 10px, #143049 10px, #143049 20px); font-size: 3rem; color: #a3e0ee; }
.card-back { transform: rotateY(180deg); background: #183629; border-color: #77bfa1; gap: 8px; }
.card-symbol { font-size: 2.5rem; }
.card-outcome { font-size: 1.2rem; font-weight: bold; }
.is-revealed .card-flipper { transform: rotateY(180deg); }
.is-winner .card-back { color: #ffe496; background: #403720; border-color: #ebc960; box-shadow: 0 0 20px #e4b95133; }
.luck-card:disabled { opacity: 1; }
#cards-history { list-style: none; margin-top: 12px; max-height: 300px; overflow-y: auto; }
#cards-history li { padding: 12px; margin-bottom: 8px; background: #2f2b1d; color: #ffe7a4; border-radius: 8px; overflow-wrap: anywhere; }
#mode-cards .results { margin-top: 20px; }
@media (max-width: 480px) { .cards-board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } .card-flipper { height: 135px; } }
@media (prefers-reduced-motion: reduce) { .card-flipper { transition: none; } }
@media (max-width: 480px) {
    .mode-switcher { gap: 7px; }
    .mode-switcher button { font-size: .75rem; padding: 9px 4px; }
    .party-canvas-wrap { margin-top: 8px; }
}
