/* Core Variables and Resets */
:root {
    --bg-dark: #1a1a2e;
    --panel-bg: rgba(30, 30, 40, 0.85);
    --primary: #4ecca3;
    --primary-hover: #45b393;
    --text-main: #eeeeee;
    --dora-color: #ffb84d;
    --vn-bg: rgba(10, 10, 15, 0.9);
}

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

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    /* Basic background texture simulation */
    background-image: radial-gradient(circle at center, #232336 0%, #11111a 100%);
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* Scene Management */
.scene {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}

.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.active {
    display: flex;
    opacity: 1;
}

/* Typography and Buttons */
/* ---------- Title / Orientation Overlay ---------- */
#orientation-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(4, 6, 12, 0.9);
    backdrop-filter: blur(10px);
}

.orientation-card {
    width: min(88vw, 520px);
    padding: 28px 24px;
    border-radius: 22px;
    text-align: center;
    background: linear-gradient(180deg, rgba(20, 26, 44, 0.96) 0%, rgba(9, 11, 21, 0.96) 100%);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.orientation-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.orientation-card h2 {
    margin-bottom: 10px;
    font-size: 2rem;
}

.orientation-card p {
    margin-bottom: 0;
    line-height: 1.7;
    color: #d8deef;
}

#scene-title {
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 22%, rgba(121, 175, 255, 0.28) 0%, rgba(121, 175, 255, 0) 42%),
        radial-gradient(circle at 80% 72%, rgba(146, 96, 255, 0.18) 0%, rgba(146, 96, 255, 0) 34%),
        linear-gradient(180deg, #090b15 0%, #101626 48%, #070910 100%);
}

.title-backdrop,
.title-particles {
    position: absolute;
    inset: -8%;
    pointer-events: none;
}

.title-backdrop {
    background:
        radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0) 40%),
        linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0) 24%, rgba(0,0,0,0.25) 100%);
}

.title-particles-a {
    background-image:
        radial-gradient(circle, rgba(255,255,255,0.38) 0 1px, transparent 2px),
        radial-gradient(circle, rgba(144, 204, 255, 0.22) 0 1px, transparent 2px);
    background-size: 180px 180px, 240px 240px;
    animation: titleDrift 28s linear infinite;
    opacity: 0.5;
}

.title-particles-b {
    background-image:
        radial-gradient(circle, rgba(190, 160, 255, 0.18) 0 1px, transparent 2px);
    background-size: 320px 320px;
    animation: titleDriftReverse 34s linear infinite;
    opacity: 0.34;
}

.title-content {
    position: relative;
    z-index: 2;
    width: min(100vw, 1400px);
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3vh 4vw 8vh;
}

.title-video-shell {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    background: #05070d;
}

.title-video-shell::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(5, 7, 13, 0.18) 0%, rgba(5, 7, 13, 0.06) 42%, rgba(5, 7, 13, 0.34) 100%);
    pointer-events: none;
}

.title-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
    background: #05070d;
}

.title-fallback-layer {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#scene-title.has-title-video .title-fallback-layer {
    display: none;
}

.title-logo-image {
    max-width: min(62vw, 760px);
    max-height: 16vh;
    margin-bottom: 12px;
    object-fit: contain;
    filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.38));
}

.title-copy-block {
    position: absolute;
    top: 7vh;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

.title-copy-block h1 {
    font-size: clamp(2.6rem, 6vw, 5.6rem);
    letter-spacing: 0.12em;
    margin-bottom: 0.4rem;
    text-shadow: 0 0 28px rgba(164, 209, 255, 0.35), 0 8px 24px rgba(0,0,0,0.45);
}

.title-copy-block p {
    font-size: clamp(1rem, 1.8vw, 1.35rem);
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: rgba(231, 236, 248, 0.82);
    margin-bottom: 0;
}

.title-hero-image {
    width: min(90vw, 1180px);
    max-height: 68vh;
    object-fit: contain;
    filter: drop-shadow(0 24px 38px rgba(0, 0, 0, 0.42));
    animation: titleFloat 5.2s ease-in-out infinite, titleBreath 11s ease-in-out infinite;
    user-select: none;
    -webkit-user-drag: none;
}

.title-bottom-ui {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 3.5vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.title-start-hint {
    font-size: clamp(1.25rem, 2.5vw, 2.1rem);
    font-weight: 800;
    letter-spacing: 0.28em;
    color: rgba(255,255,255,0.96);
    text-shadow: 0 0 18px rgba(164, 209, 255, 0.28), 0 0 24px rgba(0,0,0,0.55);
    animation: tapStartPulse 2.6s ease-in-out infinite;
}

.title-sub-hint {
    font-size: 0.95rem;
    letter-spacing: 0.1em;
    color: rgba(223, 230, 244, 0.68);
}

.title-screen-hitarea {
    position: absolute;
    inset: 0;
    z-index: 3;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: transparent;
}

.title-screen-hitarea:hover,
.title-screen-hitarea:focus {
    transform: none;
    background: transparent;
    outline: none;
}

.title-menu-buttons {
    position: absolute;
    top: 18px;
    right: 18px;
    z-index: 4;
    display: flex;
    gap: 10px;
}

.title-menu-buttons .btn-secondary {
    min-width: 132px;
    backdrop-filter: blur(10px);
    background: rgba(19, 24, 36, 0.72);
    border-color: rgba(255,255,255,0.14);
}

body.orientation-blocked #scene-title {
    filter: blur(3px);
}

@keyframes tapStartPulse {
    0%, 100% { opacity: 0.18; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-3px); }
}

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

@keyframes titleBreath {
    0%, 100% { scale: 1; }
    50% { scale: 1.02; }
}

@keyframes titleDrift {
    0% { transform: translate3d(0, 0, 0); }
    100% { transform: translate3d(-40px, 32px, 0); }
}

@keyframes titleDriftReverse {
    0% { transform: translate3d(0, 0, 0); }
    100% { transform: translate3d(34px, -28px, 0); }
}

h1 {
    font-size: 4rem;
    margin-bottom: 0.5rem;
    text-shadow: 0 0 10px rgba(78, 204, 163, 0.5);
}

h2 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
}

p {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    color: #a0a0b0;
}

button {
    padding: 12px 24px;
    font-size: 1.2rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin: 10px;
    transition: all 0.2s;
    font-weight: bold;
}

.btn-primary {
    background-color: var(--primary);
    color: #111;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
}

.btn-primary:disabled {
    background-color: #555;
    color: #888;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: #3a3a50;
    color: var(--text-main);
    border: 1px solid #5a5a70;
}

.btn-secondary:hover {
    background-color: #4a4a60;
}

.btn-danger {
    background-color: #e05e5e;
    color: white;
}

/* Character Selection */
#scene-char-select {
    justify-content: flex-start;
    padding-top: 5vh;
}

#char-select-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    max-width: 800px;
    margin-bottom: 20px;
}

.char-card {
    position: relative;
    width: 100px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--panel-bg);
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
    text-align: center;
    padding-bottom: 8px;
}

.char-card img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    border-bottom: 1px solid #333;
}

.char-card:hover {
    transform: translateY(-5px);
    border-color: #666;
}

.char-card.selected-main {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(78, 204, 163, 0.4);
}

.char-card.selected-opp {
    border-color: #e05e5e;
    box-shadow: 0 0 15px rgba(224, 94, 94, 0.4);
}

.rules-toggle {
    background: var(--panel-bg);
    padding: 15px 30px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.rules-toggle label {
    margin: 0 15px;
    cursor: pointer;
    font-size: 1.1rem;
}

.quick-select-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
}

.quick-select-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.selection-status {
    min-height: 1.4em;
    color: #cbd5e1;
    font-size: 1rem;
    text-align: center;
}


.char-card.focused {
    transform: translateY(-3px);
    border-color: #7dd3fc;
    box-shadow: 0 0 16px rgba(125, 211, 252, 0.28);
}

.char-card-mode-badge {
    position: absolute;
    right: 8px;
    top: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    background: rgba(17, 24, 39, 0.88);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.12);
    pointer-events: none;
}

.char-detail-popup {
    position: fixed;
    inset: 0;
    z-index: 2400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.char-detail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 8, 18, 0.72);
    backdrop-filter: blur(4px);
}

.char-detail-window {
    position: relative;
    z-index: 1;
    width: min(92vw, 920px);
    max-height: min(84vh, 720px);
    min-height: 170px;
    margin: 0;
    background: linear-gradient(180deg, rgba(14, 16, 25, 0.98), rgba(10, 12, 19, 0.97));
    border: 1px solid #4a5674;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
    overflow: auto;
}

.char-detail-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    padding: 0;
    margin: 0;
    font-size: 1.6rem;
    line-height: 1;
    background: rgba(255, 255, 255, 0.08);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.12);
    z-index: 2;
}

.char-detail-close:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: scale(1.04);
}

.char-detail-content {
    display: flex;
    gap: 18px;
    padding: 22px 22px 20px;
    align-items: stretch;
}

#char-detail-face {
    width: 140px;
    height: 140px;
    object-fit: cover;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.char-detail-text-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.char-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    border-bottom: 1px solid #414b63;
    padding-bottom: 8px;
    padding-right: 48px;
}

#char-detail-name {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--primary);
}

.char-detail-role {
    font-size: 0.95rem;
    color: #d6def0;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    padding: 4px 10px;
    white-space: nowrap;
}

.char-detail-desc {
    color: #d3d8e4;
    line-height: 1.5;
    min-height: 2.4em;
}

.char-detail-mode-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 10px 12px;
}

.char-detail-mode-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.char-detail-mode-meta .label {
    font-size: 0.82rem;
    color: #94a3b8;
}

#char-detail-mode {
    font-size: 1rem;
    color: #f8fafc;
    font-weight: 600;
}

.char-detail-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
}

.char-detail-stat {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.char-detail-stat.full {
    grid-column: 1 / -1;
}

.char-detail-stat .label {
    font-size: 0.85rem;
    color: #94a3b8;
}

.char-detail-stat span:last-child {
    font-size: 1rem;
    color: #f8fafc;
    line-height: 1.4;
}

/* Mahjong Table Layout */
#scene-game {
    display: block;
    /* Override default flex from .scene */
}

#mahjong-table {
    width: 100%;
    height: 100vh;
    /* Full screen */
    position: relative;
    background: #113322;
    /* Classic Green Table */
    perspective: 1000px;
}

/* Table Areas */
.player-area {
    position: absolute;
    /* We don't use flex centering here anymore to prevent dynamic shifting */
}

/* Center Info */
#table-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.6);
    padding: 15px 25px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid #444;
}

.round-info {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 5px;
}

.tiles-left,
.dora-indicator {
    font-size: 1.1rem;
    margin: 3px 0;
}

.dealer-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 4px 0 6px;
    font-size: 1rem;
    font-weight: 700;
}

.dealer-info img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(255,255,255,0.35);
}

#dora-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
    min-height: 36px;
    vertical-align: middle;
}

.dora-indicator-tile {
    width: 28px;
    height: auto;
    margin-right: 0;
}

#btn-in-game-settings {
    position: absolute;
    top: -20px;
    right: -20px;
    padding: 8px;
    border-radius: 50%;
    font-size: 1.2rem;
}

/* Player Info Badges */
.player-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--panel-bg);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 8px;
    gap: 5px;
    width: 100px;
}

.player-info img.avatar {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    object-fit: cover;
}

.player-info .name {
    font-weight: bold;
    min-width: 60px;
}

.player-info .score {
    font-family: monospace;
    font-size: 1.2rem;
    color: var(--primary);
}

/* Hand and River (Discard) setup */
.hand {
    display: flex;
    gap: 2px;
    height: 60px;
    /* Fixed height to prevent vertical shifting */
    z-index: 10;
    position: relative;
    /* Need position relative for z-index to work */
}

.river {
    display: flex;
    width: 240px;
    /* space for 6 tiles wide */
    height: 160px;
    /* Fixed height for 3 rows of discards */
    flex-wrap: wrap;
    align-content: flex-start;
    margin-top: 5px;
    margin-bottom: 5px;
    gap: 2px;
}

.tile {
    width: 36px;
    height: 48px;
    border-radius: 3px;
    object-fit: cover;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.5);
    user-select: none;
    -webkit-user-drag: none;
}



/* Main Player Positioning */
#player-bottom {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
    height: 250px;
}

#player-bottom .river {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
}

#player-bottom .player-info {
    position: absolute;
    left: 20px;
    bottom: 20px;
    background: rgba(30, 30, 40, 0.95);
    border-color: var(--primary);
}

#player-bottom .hand {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

#player-bottom .hand .tile {
    width: 48px;
    height: 64px;
    font-size: 2rem;
    cursor: pointer;
    transition: transform 0.1s;
}

#player-bottom .hand .tile:hover {
    transform: translateY(-10px);
}

/* Opponent Positioning */
#player-top {
    top: 20px;
    left: 50%;
    transform: translateX(-50%) rotate(180deg);
    width: 800px;
    height: 250px;
}

#player-top .river {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
}

#player-top .player-info {
    position: absolute;
    left: 20px;
    bottom: 20px;
    transform: rotate(180deg);
}

#player-top .hand {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

#player-left {
    top: 50%;
    left: 40px;
    transform: translateY(-50%) rotate(90deg);
    width: 800px;
    height: 250px;
}

#player-left .river {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
}

#player-left .player-info {
    position: absolute;
    left: 20px;
    bottom: 20px;
    transform: rotate(-90deg);
}

#player-left .hand {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

#player-right {
    top: 50%;
    right: 40px;
    transform: translateY(-50%) rotate(-90deg);
    width: 800px;
    height: 250px;
}

#player-right .river {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
}

#player-right .player-info {
    position: absolute;
    left: 20px;
    bottom: 20px;
    transform: rotate(90deg);
}

#player-right .hand {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

/* Action Buttons Popup */
#action-buttons {
    position: fixed;
    bottom: 30vh;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
    background: rgba(0, 0, 0, 0.85);
    padding: 15px 25px;
    border-radius: 10px;
    border: 2px solid var(--primary);
    z-index: 200;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.7);
}

#action-buttons.hidden {
    display: none !important;
}

#action-buttons button {
    padding: 12px 24px;
    margin: 0;
    font-size: 1.5rem;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.1s;
}

#action-buttons button:hover {
    transform: scale(1.05);
}

/* VN Message Window */
#vn-window {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 25vh;
    /* Lower 25% of screen */
    background: var(--vn-bg);
    border-top: 2px solid #333;
    display: flex;
    justify-content: center;
    z-index: 100;
    transition: transform 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
    /* Allow tile clicks through the VN window */
}

#vn-window.hidden {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

.vn-content {
    width: 90%;
    max-width: 1000px;
    height: 100%;
    display: flex;
    align-items: flex-end;
    padding: 10px 20px;
    gap: 20px;
    pointer-events: auto;
    /* Re-enable clicks for VN text/buttons */
}

#vn-face {
    height: 90%;
    aspect-ratio: 1/1;
    object-fit: contain;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
}

.vn-text-area {
    flex-grow: 1;
    height: 85%;
    background: rgba(20, 20, 30, 0.6);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
}

#vn-name {
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 10px;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
}

#vn-text {
    font-size: 1.2rem;
    line-height: 1.5;
}

/* Cutin Overlay */
#cutin-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cutin-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: cutinSlide 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

#cutin-img {
    width: 300px;
    height: 300px;
    object-fit: cover;
    border-radius: 50%;
    border: 5px solid var(--primary);
    box-shadow: 0 0 30px var(--primary);
    margin-bottom: 20px;
}

.glow-text {
    font-size: 6rem;
    color: #fff;
    text-shadow: 0 0 20px var(--primary), 0 0 40px var(--primary);
    margin: 0;
    font-style: italic;
}

#cutin-voice {
    font-size: 1.8rem;
    margin-top: 10px;
    color: #ffd700;
}

@keyframes cutinSlide {
    0% {
        transform: scale(0.5) translateY(100px);
        opacity: 0;
    }

    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* Modal Windows */
.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: 300;
}

.modal-content {
    background: var(--panel-bg);
    padding: 30px;
    border-radius: 12px;
    border: 1px solid #555;
    min-width: 300px;
    text-align: center;
}

.setting-group {
    margin: 15px 0;
    text-align: left;
}

.setting-group label {
    display: block;
    margin-bottom: 5px;
}

.setting-group input[type="range"] {
    width: 100%;
}

/* Agari Result Modal */
.agari-content {
    background: rgba(10, 20, 30, 0.95);
    border: 2px solid var(--primary);
    box-shadow: 0 0 30px rgba(78, 204, 163, 0.6);
    color: white;
    min-width: 400px;
    padding: 40px;
}

#agari-title {
    font-size: 3rem;
    color: var(--primary);
    text-shadow: 0 0 10px var(--primary);
    margin-bottom: 20px;
}

.yaku-list {
    text-align: left;
    margin: 20px 0;
    font-size: 1.5rem;
    border-top: 1px solid #444;
    border-bottom: 1px solid #444;
    padding: 15px 0;
}

.yaku-item {
    display: flex;
    justify-content: space-between;
    margin: 5px 0;
}

.agari-score {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#agari-han-fu {
    font-size: 1.5rem;
    color: #ccc;
}

#agari-points {
    font-size: 3rem;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 10px #aa8800;
}

/* Ryuukyoku Modal */
.ryuukyoku-content {
    background: rgba(30, 30, 40, 0.95);
    border: 2px solid #5a5a70;
    box-shadow: 0 0 30px rgba(90, 90, 112, 0.6);
    color: #ccc;
    min-width: 400px;
    padding: 40px;
}

#ryuukyoku-title {
    font-size: 2.5rem;
    color: #aaa;
    margin-bottom: 20px;
    letter-spacing: 2px;
}

/* Yaku Assist UI */
#yaku-assist {
    position: absolute;
    bottom: 250px;
    /* Above the player area */
    left: 20px;
    background: rgba(20, 40, 60, 0.85);
    border: 1px solid var(--primary);
    border-radius: 8px;
    width: 250px;
    padding: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    z-index: 50;
    transition: opacity 0.3s;
}

.assist-header {
    color: var(--primary);
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(78, 204, 163, 0.5);
    padding-bottom: 4px;
}

#assist-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

#assist-list li {
    font-size: 0.95rem;
    margin-bottom: 5px;
    color: #e0e0e0;
}

#assist-list li::before {
    content: "💡 ";
}

/* Open Tiles Layer */
.open-tiles {
    z-index: 5;
}

/* Dora Glow */
.dora-glow {
    box-shadow: 0 0 15px #ffff00, inset 0 0 10px rgba(255, 255, 0, 0.5) !important;
    color: #ffcc00 !important;
}

/* Dora Flash (after kan) */
.dora-flash {
    animation: doraFlash 1.5s ease forwards;
}

@keyframes doraFlash {
    0% {
        box-shadow: 0 0 0px transparent;
    }

    30% {
        box-shadow: 0 0 25px #ffd700, 0 0 40px #ffb84d;
    }

    70% {
        box-shadow: 0 0 20px #ffd700;
    }

    100% {
        box-shadow: 0 0 0px transparent;
    }
}

/* Dice Modal */
.dice-content {
    background: rgba(20, 20, 30, 0.95);
    border: 2px solid #fff;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.4);
    color: white;
    min-width: 300px;
    padding: 30px;
}

.dice-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 20px 0;
}

.dice-anim {
    font-size: 5rem;
    animation: diceRoll 0.5s ease-in-out infinite alternate;
}

@keyframes diceRoll {
    0% {
        transform: translateY(0) rotate(-10deg);
    }

    100% {
        transform: translateY(-20px) rotate(10deg);
    }
}

/* Match Result Modal */
.match-result-content {
    background: rgba(10, 10, 20, 0.97);
    border: 2px solid var(--primary);
    box-shadow: 0 0 40px rgba(78, 204, 163, 0.5);
    color: white;
    min-width: 440px;
    max-width: 90vw;
    padding: 40px;
    text-align: center;
}

.match-result-content h2 {
    font-size: 2.5rem;
    color: var(--primary);
    text-shadow: 0 0 14px var(--primary);
    margin-bottom: 25px;
    letter-spacing: 4px;
}

.match-rankings {
    margin: 0 auto 20px;
    width: 100%;
}

.rank-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    margin: 6px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.rank-number {
    font-size: 1.8rem;
    font-weight: bold;
    width: 40px;
    flex-shrink: 0;
}

.rank-number.first {
    color: #ffd700;
    text-shadow: 0 0 10px #ffd700;
}

.rank-number.second {
    color: #c0c0c0;
}

.rank-number.third {
    color: #cd7f32;
}

.rank-number.other {
    color: #888;
}

.rank-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #555;
    flex-shrink: 0;
}

.rank-info {
    flex: 1;
    text-align: left;
}

.rank-name {
    font-size: 1.2rem;
    font-weight: bold;
}

.rank-title {
    font-size: 0.9rem;
    margin-top: 2px;
}

.rank-title.kansokukami {
    color: #ffd700;
}

.rank-title.support {
    color: #60a5fa;
}

.rank-title.observer {
    color: #aaa;
}

.rank-score {
    font-size: 1.4rem;
    font-family: monospace;
    color: var(--primary);
    flex-shrink: 0;
}

.match-mvp {
    font-size: 0.95rem;
    color: #aaa;
    border-top: 1px solid #333;
    padding-top: 14px;
    margin-top: 14px;
    line-height: 1.8;
    text-align: left;
}

/* ============================================================
   MOBILE RESPONSIVE LAYOUT (雀魂/MJ style)
   PC layout is NOT affected — all changes inside @media only
   ============================================================ */
@media screen and (max-width: 768px) {

    /* ---------- Global Mobile Overrides ---------- */
    body {
        overflow-x: hidden;
    }

    h1 {
        font-size: 2.2rem;
    }

    h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    p {
        font-size: 1rem;
        margin-bottom: 1.2rem;
    }

    button {
        padding: 10px 18px;
        font-size: 1rem;
        margin: 6px;
    }

    /* ---------- Title Screen ---------- */
    .orientation-card {
        width: min(92vw, 420px);
        padding: 22px 18px;
    }

    .orientation-card h2 {
        font-size: 1.5rem;
    }

    .title-copy-block {
        top: 5vh;
        width: 100%;
        padding: 0 10vw;
    }

    .title-logo-image {
        max-width: 78vw;
        max-height: 13vh;
        margin-bottom: 6px;
    }

    .title-hero-image {
        width: min(104vw, 960px);
        max-height: 58vh;
    }

    .title-start-hint {
        font-size: 1.25rem;
        letter-spacing: 0.18em;
    }

    .title-sub-hint {
        font-size: 0.8rem;
    }

    .title-menu-buttons {
        top: 10px;
        right: 10px;
    }

    .title-menu-buttons .btn-secondary {
        min-width: 110px;
        padding: 10px 14px;
    }

    /* ---------- Character Selection ---------- */
    #scene-char-select {
        padding-top: 2vh;
        overflow-y: auto;
    }

    #char-select-grid {
        max-width: 95vw;
        gap: 8px;
    }

    .char-card {
        width: 70px;
    }

    .char-card img {
        aspect-ratio: 1/1;
    }

    .rules-toggle {
        padding: 10px 15px;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .rules-toggle label {
        margin: 0;
        font-size: 0.95rem;
    }

    #btn-confirm-chars,
    #btn-back-title {
        width: 70%;
        display: block;
        margin: 6px auto;
    }


    .char-card-mode-badge {
    position: absolute;
    right: 8px;
    top: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    background: rgba(17, 24, 39, 0.88);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.12);
    pointer-events: none;
}

.char-detail-popup {
        padding: 12px;
    }

    .char-detail-window {
        width: 94vw;
        max-height: 86vh;
        min-height: 0;
    }

    .char-detail-close {
        top: 10px;
        right: 10px;
        width: 36px;
        height: 36px;
        font-size: 1.4rem;
    }

    .char-detail-content {
        flex-direction: column;
        padding: 12px;
        gap: 12px;
    }

    #char-detail-face {
        width: 92px;
        height: 92px;
    }

    .char-detail-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 6px;
        padding-right: 0;
    }

    #char-detail-name {
        font-size: 1.2rem;
    }

    .char-detail-desc {
        font-size: 0.95rem;
    }

    .char-detail-mode-row {
        flex-direction: column;
        align-items: stretch;
    }

    .char-detail-stats {
        grid-template-columns: 1fr;
    }

    /* ---------- Mahjong Table ---------- */
    #mahjong-table {
        overflow: hidden;
    }

    /* --- Tiles (global mobile size) --- */
    .tile {
        width: 24px;
        height: 32px;
        font-size: 1rem;
        border-bottom-width: 2px;
    }

    .hand {
        height: 40px;
        gap: 1px;
    }

    .river {
        width: 160px;
        height: 110px;
        gap: 1px;
        margin-top: 2px;
        margin-bottom: 2px;
    }

    /* --- Player Info (compact) --- */
    .player-info {
        width: auto;
        flex-direction: row;
        padding: 4px 8px;
        gap: 4px;
        border-radius: 4px;
    }

    .player-info img.avatar {
        width: 24px;
        height: 24px;
        border-radius: 3px;
    }

    .player-info .name {
        font-size: 0.7rem;
        min-width: unset;
    }

    .player-info .score {
        font-size: 0.8rem;
    }

    /* --- Bottom Player (self) --- */
    #player-bottom {
        bottom: 5px;
        left: 0;
        transform: none;
        width: 100vw;
        height: auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0 5px;
    }

    #player-bottom .player-info {
        position: static;
        margin-bottom: 2px;
    }

    #player-bottom .river {
        position: static;
        transform: none;
        margin-bottom: 2px;
    }

    #player-bottom .hand {
        position: static;
        transform: none;
    }

    #player-bottom .hand .tile {
        width: 28px;
        height: 38px;
        font-size: 1.2rem;
        cursor: pointer;
    }

    #player-bottom .hand .tile:hover {
        transform: translateY(-5px);
    }

    /* --- Top Player (opponent across) --- */
    #player-top {
        top: 5px;
        left: 0;
        transform: rotate(180deg);
        width: 100vw;
        height: auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0 5px;
    }

    #player-top .player-info {
        position: static;
        transform: rotate(180deg);
        margin-bottom: 2px;
    }

    #player-top .river {
        position: static;
        transform: none;
        margin-bottom: 2px;
    }

    #player-top .hand {
        position: static;
        transform: none;
    }

    /* --- Left Player (side panel style) --- */
    #player-left {
        top: 50%;
        left: 0;
        right: auto;
        transform: translateY(-50%);
        /* Remove the 90deg rotation for mobile */
        width: auto;
        height: auto;
        max-height: 60vh;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 4px;
    }

    #player-left .player-info {
        position: static;
        transform: none;
        flex-direction: column;
        width: auto;
        padding: 3px 5px;
    }

    #player-left .hand {
        position: static;
        transform: none;
        flex-direction: column;
        height: auto;
        gap: 1px;
    }

    #player-left .hand .tile {
        width: 20px;
        height: 26px;
        font-size: 0.7rem;
    }

    #player-left .river {
        position: static;
        transform: none;
        width: 52px;
        height: auto;
        max-height: 120px;
        flex-wrap: wrap;
        overflow: hidden;
    }

    #player-left .river .tile {
        width: 16px;
        height: 20px;
        font-size: 0.55rem;
    }

    /* --- Right Player (side panel style) --- */
    #player-right {
        top: 50%;
        right: 0;
        left: auto;
        transform: translateY(-50%);
        /* Remove the -90deg rotation for mobile */
        width: auto;
        height: auto;
        max-height: 60vh;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 4px;
    }

    #player-right .player-info {
        position: static;
        transform: none;
        flex-direction: column;
        width: auto;
        padding: 3px 5px;
    }

    #player-right .hand {
        position: static;
        transform: none;
        flex-direction: column;
        height: auto;
        gap: 1px;
    }

    #player-right .hand .tile {
        width: 20px;
        height: 26px;
        font-size: 0.7rem;
    }

    #player-right .river {
        position: static;
        transform: none;
        width: 52px;
        height: auto;
        max-height: 120px;
        flex-wrap: wrap;
        overflow: hidden;
    }

    #player-right .river .tile {
        width: 16px;
        height: 20px;
        font-size: 0.55rem;
    }

    /* --- Table Center Info --- */
    #table-center {
        padding: 8px 12px;
        border-radius: 6px;
    }

    .round-info {
        font-size: 1rem;
        margin-bottom: 2px;
    }

    .tiles-left,
    .dora-indicator {
        font-size: 0.8rem;
        margin: 1px 0;
    }

    #btn-in-game-settings {
        top: -14px;
        right: -14px;
        padding: 5px;
        font-size: 0.9rem;
    }

    /* ---------- Action Buttons ---------- */
    #action-buttons {
        bottom: auto;
        top: 50%;
        transform: translate(-50%, -50%);
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 14px;
        max-width: 90vw;
        justify-content: center;
    }

    #action-buttons button {
        padding: 10px 16px;
        font-size: 1.1rem;
    }

    /* ---------- VN Window ---------- */
    #vn-window {
        height: 20vh;
    }

    .vn-content {
        width: 95%;
        padding: 6px 10px;
        gap: 10px;
    }

    #vn-face {
        height: 70%;
        max-width: 60px;
    }

    .vn-text-area {
        padding: 8px;
    }

    #vn-name {
        font-size: 1rem;
        margin-bottom: 5px;
    }

    #vn-text {
        font-size: 0.9rem;
        line-height: 1.3;
    }

    /* ---------- Cutin Overlay ---------- */
    #cutin-img {
        width: 150px;
        height: 150px;
        border-width: 3px;
        margin-bottom: 12px;
    }

    .glow-text {
        font-size: 3rem;
    }

    #cutin-voice {
        font-size: 1.2rem;
    }

    /* ---------- Modals (all) ---------- */
    .modal-content {
        min-width: unset !important;
        width: 90vw;
        max-width: 400px;
        padding: 20px;
    }

    /* Agari Result */
    .agari-content {
        min-width: unset !important;
        width: 90vw;
        padding: 20px;
    }

    #agari-title {
        font-size: 2rem;
        margin-bottom: 12px;
    }

    .yaku-list {
        font-size: 1.1rem;
        padding: 10px 0;
    }

    #agari-han-fu {
        font-size: 1.1rem;
    }

    #agari-points {
        font-size: 2rem;
    }

    /* Ryuukyoku */
    .ryuukyoku-content {
        min-width: unset !important;
        width: 90vw;
        padding: 20px;
    }

    #ryuukyoku-title {
        font-size: 1.8rem;
    }

    /* Dice */
    .dice-content {
        min-width: unset !important;
        width: 85vw;
        padding: 20px;
    }

    .dice-anim {
        font-size: 3rem;
    }

    /* Match Result */
    .match-result-content {
        min-width: unset !important;
        width: 92vw;
        padding: 20px;
    }

    .match-result-content h2 {
        font-size: 1.8rem;
        margin-bottom: 15px;
    }

    .rank-row {
        gap: 8px;
        padding: 6px 10px;
    }

    .rank-number {
        font-size: 1.4rem;
        width: 30px;
    }

    .rank-avatar {
        width: 36px;
        height: 36px;
    }

    .rank-name {
        font-size: 1rem;
    }

    .rank-score {
        font-size: 1.1rem;
    }

    /* Yaku Assist */
    #yaku-assist {
        bottom: auto;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 80vw;
        max-width: 280px;
        z-index: 60;
    }

    /* Settings Modal */
    .setting-group label {
        font-size: 0.9rem;
    }
}

/* Extra small screens (≤ 380px, e.g. iPhone SE) */
@media screen and (max-width: 380px) {
    #player-bottom .hand .tile {
        width: 24px;
        height: 34px;
        font-size: 1rem;
    }

    .tile {
        width: 20px;
        height: 28px;
        font-size: 0.85rem;
    }

    #table-center {
        padding: 5px 8px;
    }

    .round-info {
        font-size: 0.85rem;
    }

    .tiles-left,
    .dora-indicator {
        font-size: 0.7rem;
    }

    .char-card {
        width: 60px;
    }
}

#scene-game.voice-paused #mahjong-table,
#scene-game.voice-paused #action-buttons,
#scene-game.voice-paused #player-hand {
    pointer-events: none;
}

#scene-game.voice-paused::after {
    content: "ボイス再生中...";
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 1200;
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    letter-spacing: 0.08em;
}
