:root {
    --bg-deep: #0B0F0D;
    --bg-felt: #0E1A14;
    --felt: #1A3D2A;
    --felt-light: #245438;
    --gold: #D4A843;
    --gold-bright: #F0C95C;
    --gold-dim: #8B7230;
    --jade: #3CB371;
    --jade-dim: #2E8B57;
    --ivory: #F5F0E8;
    --text-primary: #E8E0D0;
    --text-secondary: #9B9484;
    --text-muted: #6B6458;
    --red-suit: #C0392B;
    --black-suit: #1A1A1A;
    --danger: #C0392B;
    --panel-bg: #141E18;
    --panel-border: rgba(212, 168, 67, 0.18);
    --radius: 12px;
    --radius-lg: 18px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'LXGW WenKai TC', 'Noto Serif TC', 'Microsoft JhengHei', serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 50% 0%, rgba(30, 80, 50, 0.35) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(212, 168, 67, 0.06) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ── Screen ──────────────────────────────────────── */
.screen {
    display: none;
    width: 100vw;
    height: 100vh;
    position: relative;
    z-index: 1;
}

.screen.active {
    display: flex;
    animation: screenIn 0.45s ease both;
}

@keyframes screenIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Panel ───────────────────────────────────────── */
.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ── Inputs ──────────────────────────────────────── */
.input-field {
    display: block;
    width: 100%;
    background: #1A2620;
    border: 1px solid rgba(212, 168, 67, 0.15);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 0.95rem;
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    font-family: inherit;
}

.input-field:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(212, 168, 67, 0.12);
}

.input-field::placeholder { color: var(--text-muted); }

.input-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--gold-dim);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 6px;
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
    display: inline-block;
    border: none;
    border-radius: var(--radius);
    padding: 12px 32px;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.04em;
    text-decoration: none;
    text-align: center;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    filter: brightness(1.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.btn:active:not(:disabled) { transform: translateY(0); }

.btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.btn-gold {
    background: linear-gradient(135deg, var(--gold), var(--gold-bright));
    color: var(--bg-deep);
}

.btn-jade {
    background: linear-gradient(135deg, var(--jade-dim), var(--jade));
    color: #fff;
}

.btn-danger {
    background: linear-gradient(135deg, #8B2020, var(--danger));
    color: #fff;
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-sm {
    padding: 5px 14px;
    font-size: 0.75rem;
    border-radius: 8px;
}

.btn-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 18px;
}

/* ── LOBBY ───────────────────────────────────────── */
#lobby {
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.lobby-wrapper { text-align: center; }

.lobby-brand { margin-bottom: 36px; }

.lobby-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--felt), var(--felt-light));
    border: 2px solid var(--gold-dim);
    margin-bottom: 14px;
    font-size: 1.7rem;
    box-shadow: 0 0 32px rgba(212, 168, 67, 0.1);
    animation: iconFloat 3s ease-in-out infinite;
}

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

.lobby-title {
    font-family: 'Noto Serif TC', serif;
    font-size: 2.8rem;
    font-weight: 900;
    color: var(--ivory);
    line-height: 1.2;
    margin-bottom: 6px;
    background: linear-gradient(135deg, var(--ivory) 30%, var(--gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.lobby-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    letter-spacing: 0.2em;
}

.lobby-form {
    padding: 32px 36px;
    width: 400px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 auto;
}

.lobby-form .input-group { margin-bottom: 8px; }

.lobby-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--panel-border), transparent);
    margin: 14px 0;
}

.lobby-or {
    color: var(--text-muted);
    font-size: 0.8rem;
    letter-spacing: 0.15em;
    margin: 8px 0 4px;
}

.lobby-footer {
    margin-top: 20px;
}

.download-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.82rem;
    text-decoration: none;
    transition: color var(--transition);
    letter-spacing: 0.02em;
}

.download-link:hover {
    color: var(--gold);
}

.download-link .dl-icon {
    font-size: 1rem;
}

/* ── WAITING ROOM ────────────────────────────────── */
#waitingRoom {
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.waiting-wrapper { text-align: center; }

.waiting-header { margin-bottom: 24px; }

.waiting-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 0.2em;
}

.waiting-title {
    font-family: 'Noto Serif TC', serif;
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--ivory);
}

.room-code-display {
    font-family: 'Noto Serif TC', monospace;
    font-size: 3rem;
    font-weight: 900;
    color: var(--gold);
    letter-spacing: 12px;
    margin: 6px 0 4px;
    text-shadow: 0 0 24px rgba(212, 168, 67, 0.2);
}

.room-code-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.seats-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 18px;
    width: 480px;
    margin: 20px auto 0;
}

.seat-slot {
    background: #161F1A;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all var(--transition);
}

.seat-slot.occupied {
    border-color: rgba(60, 179, 113, 0.35);
    background: rgba(60, 179, 113, 0.08);
}

.seat-slot.ai {
    border-color: rgba(212, 168, 67, 0.25);
    background: rgba(212, 168, 67, 0.06);
}

.seat-info { text-align: left; }

.seat-name {
    display: block;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: color var(--transition);
}

.seat-status {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.seat-slot.occupied .seat-name { color: var(--jade); }
.seat-slot.ai .seat-name { color: var(--gold); }
.seat-slot.ai .seat-status { color: var(--gold-dim); }

.waiting-status {
    color: var(--gold);
    font-weight: 700;
    font-size: 0.88rem;
    text-align: center;
    margin-top: 16px;
    min-height: 1.4em;
}

/* ── GAME LAYOUT ─────────────────────────────────── */
.game-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 12px 16px;
    gap: 8px;
    max-width: 1140px;
    margin: 0 auto;
    width: 100%;
}

.opponent-row {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.opponent-slot {
    flex: 1;
    padding: 10px 12px;
}

.opponent-slot .player-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.opponent-cards {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    height: 85px;
    position: relative;
}

.card-back {
    width: 38px;
    height: 55px;
    background: linear-gradient(145deg, var(--felt-light), var(--felt));
    border: 1px solid rgba(212, 168, 67, 0.2);
    border-radius: 5px;
    margin-left: -16px;
    transform-origin: center 120%;
    flex-shrink: 0;
}

.card-back:first-child { margin-left: 0; }

/* Player badge */
.player-badge {
    display: flex;
    align-items: center;
    gap: 8px;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.78rem;
    color: white;
    flex-shrink: 0;
    border: 2px solid transparent;
    transition: all var(--transition);
}

.badge-text { display: flex; flex-direction: column; }
.badge-name { font-size: 0.82rem; font-weight: 700; color: var(--text-secondary); transition: color var(--transition); }
.badge-cards { font-size: 0.68rem; color: var(--text-muted); }

.player-badge.active .avatar {
    border-color: var(--gold);
    box-shadow: 0 0 12px rgba(212, 168, 67, 0.35);
}
.player-badge.active .badge-name { color: var(--gold); }

/* Center area */
.center-area {
    flex: 1;
    display: flex;
    gap: 10px;
    min-height: 0;
}

.table-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: radial-gradient(ellipse at center, rgba(26, 61, 42, 0.4) 0%, var(--panel-bg) 70%);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
}

.table-cards {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

.table-empty {
    color: var(--text-muted);
    font-size: 0.88rem;
    font-style: italic;
}

.table-info {
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--gold-dim);
    text-align: center;
}

.log-panel {
    width: 200px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.log-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--gold-dim);
    letter-spacing: 0.1em;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--panel-border);
}

.log-content {
    flex: 1;
    overflow-y: auto;
    font-size: 0.73rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.log-content::-webkit-scrollbar { width: 3px; }
.log-content::-webkit-scrollbar-track { background: transparent; }
.log-content::-webkit-scrollbar-thumb { background: rgba(212, 168, 67, 0.15); border-radius: 2px; }

/* Bottom area */
.bottom-area { flex-shrink: 0; }

.my-info-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 6px;
    padding: 0 4px;
}

.my-info-row .status-text {
    flex: 1;
    color: var(--gold);
    font-weight: 700;
    font-size: 0.88rem;
    text-align: center;
}

.hand-type-chip {
    font-size: 0.82rem;
    color: var(--jade);
    font-weight: 700;
    min-width: 80px;
    text-align: right;
}

.hand-area {
    padding: 10px;
    padding-top: 20px;
    overflow-x: auto;
    overflow-y: visible;
    min-height: 132px;
    background: radial-gradient(ellipse at 50% 100%, rgba(26, 61, 42, 0.25) 0%, var(--panel-bg) 60%);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
}

.hand-container {
    display: flex;
    position: relative;
    min-height: 96px;
    padding-bottom: 4px;
}

/* ── Card ─────────────────────────────────────────── */
.card {
    width: 66px;
    height: 96px;
    border-radius: 8px;
    background: linear-gradient(160deg, #FFFEF8, #F0EDE0);
    border: 1px solid rgba(0, 0, 0, 0.08);
    position: relative;
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease;
    flex-shrink: 0;
    margin-right: -22px;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.card:last-child { margin-right: 0; }
.card:hover { transform: translateY(-5px); z-index: 2; }

.card.selected {
    transform: translateY(-16px);
    box-shadow: 0 0 16px rgba(212, 168, 67, 0.4), 1px 2px 6px rgba(0, 0, 0, 0.35);
    border-color: var(--gold);
}

.card .card-corner {
    position: absolute;
    top: 4px;
    left: 6px;
    font-size: 0.7rem;
    line-height: 1.15;
    text-align: center;
    font-weight: 700;
}

.card .card-center {
    font-size: 1.6rem;
    margin-top: 8px;
}

.card.red { color: var(--red-suit); }
.card.black { color: var(--black-suit); }

.card.table-card {
    cursor: default;
    margin-right: -10px;
}
.card.table-card:hover { transform: none; z-index: auto; }

/* ── Modal ────────────────────────────────────────── */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    padding: 40px 52px;
    text-align: center;
    min-width: 320px;
    animation: modalIn 0.3s ease both;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.result-icon { font-size: 3.2rem; margin-bottom: 12px; }

.result-title {
    font-family: 'Noto Serif TC', serif;
    font-size: 1.6rem;
    font-weight: 900;
    margin-bottom: 8px;
}

.result-sub {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 768px) {
    .lobby-form { width: 92vw; padding: 24px 20px; }
    .lobby-title { font-size: 2rem; }
    .seats-panel { width: 92vw; }
    .log-panel { display: none; }
    .card { width: 52px; height: 76px; margin-right: -18px; }
    .card .card-center { font-size: 1.2rem; }
    .opponent-cards { height: 60px; }
    .card-back { width: 32px; height: 48px; }
    .room-code-display { font-size: 2.4rem; letter-spacing: 8px; }
}
