:root {
    --bg-parchment: #f5f4ed;
    --bg-ivory: #faf9f5;
    --bg-white: #ffffff;
    --bg-sand: #e8e6dc;
    --bg-dark: #30302e;
    --bg-deep: #141413;

    --text-primary: #141413;
    --text-secondary: #5e5d59;
    --text-tertiary: #87867f;
    --text-emphasis: #3d3d3a;
    --text-on-dark: #b0aea5;

    --brand: #c96442;
    --brand-soft: #d97757;
    --danger: #b53333;
    --focus: #3898ec;

    --border-cream: #f0eee6;
    --border-warm: #e8e6dc;
    --border-dark: #30302e;

    --ring-warm: #d1cfc5;
    --ring-deep: #c2c0b6;
    --shadow-whisper: rgba(0, 0, 0, 0.05) 0px 4px 24px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--bg-parchment);
    color: var(--text-primary);
    font-family: "Inter", "Segoe UI", Arial, sans-serif;
    line-height: 1.6;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 500;
    line-height: 1.2;
    color: var(--text-primary);
}

h1 {
    font-size: clamp(2rem, 5vw, 4rem);
    line-height: 1.1;
}

h2 {
    font-size: clamp(1.6rem, 3.2vw, 3rem);
}

h3 {
    font-size: clamp(1.2rem, 2.3vw, 2rem);
}

p {
    color: var(--text-secondary);
}

.hidden {
    display: none !important;
}

.muted-note {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.94rem;
    margin-top: 20px;
}

/* Shared containers */
.container {
    width: min(460px, calc(100vw - 32px));
    margin: 6vh auto;
    padding: 32px;
    border-radius: 16px;
    background: var(--bg-ivory);
    border: 1px solid var(--border-cream);
    box-shadow: var(--ring-warm) 0 0 0 1px, var(--shadow-whisper);
}

input,
select,
textarea {
    width: 100%;
    margin: 10px 0;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-warm);
    background: var(--bg-white);
    color: var(--text-primary);
    font-size: 15px;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--focus);
    box-shadow: var(--focus) 0 0 0 2px;
}

button {
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    margin-top: 12px;
    font-size: 15px;
    cursor: pointer;
    background: var(--bg-sand);
    color: #4d4c48;
    box-shadow: var(--ring-warm) 0 0 0 1px;
    transition: 0.2s ease;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: var(--ring-deep) 0 0 0 1px;
}

.btn-primary {
    background: var(--brand);
    color: var(--bg-ivory);
    box-shadow: var(--brand) 0 0 0 1px;
}

.btn-danger {
    background: var(--danger);
    color: var(--bg-ivory);
    box-shadow: var(--danger) 0 0 0 1px;
}

.btn-secondary {
    background: var(--bg-sand);
    color: var(--text-emphasis);
}

.sm-btn {
    width: auto;
    margin-top: 0;
    padding: 8px 14px;
    font-size: 14px;
}

/* Lobby */
.lobby-header {
    position: sticky;
    top: 0;
    z-index: 20;
    height: 72px;
    padding: 0 24px;
    background: rgba(245, 244, 237, 0.92);
    backdrop-filter: blur(4px);
    border-bottom: 1px solid var(--border-warm);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info h2 {
    font-size: 1.65rem;
}

#welcome-msg {
    color: var(--text-secondary);
    font-size: 14px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-actions button {
    width: auto;
    margin-top: 0;
}

.lobby-container {
    width: min(1280px, calc(100vw - 24px));
    margin: 16px auto 24px;
    padding: 8px;
}

.lobby-content-wrapper {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 16px;
    min-height: calc(100vh - 124px);
}

.room-list-panel,
.chat-panel,
.room-shell,
.warehouse-container {
    background: var(--bg-ivory);
    border: 1px solid var(--border-cream);
    border-radius: 16px;
    box-shadow: var(--ring-warm) 0 0 0 1px, var(--shadow-whisper);
}

.panel-header {
    padding: 18px;
    border-bottom: 1px solid var(--border-cream);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.panel-header h3 {
    font-size: 1.35rem;
}

.room-list {
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    padding: 12px;
}

.mode-card {
    background: var(--bg-white);
    border: 1px solid var(--border-warm);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: 0.2s ease;
}

.mode-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--ring-warm) 0 0 0 1px, var(--shadow-whisper);
}

.room-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.room-card-header h3 {
    font-size: 1rem;
}

.room-status {
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    letter-spacing: 0.2px;
}

.room-status.waiting {
    background: #efe8d5;
    color: #826d2f;
}

.room-status.playing {
    background: #f6e2db;
    color: #9a3f2a;
}

.room-id,
.room-type,
.player-count {
    color: var(--text-tertiary);
    font-size: 13px;
}

.room-footer {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-cream);
    display: flex;
    justify-content: space-between;
}

.player-count.open {
    color: #596b4f;
}

.player-count.full {
    color: #9b4d3a;
}

.chat-panel {
    display: grid;
    grid-template-columns: 220px 1fr;
    overflow: hidden;
    min-width: 0;
}

.chat-sidebar {
    border-right: 1px solid var(--border-cream);
    background: #f3f2ea;
    padding: 12px;
}

.channel-tabs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.channel-tabs button {
    margin: 0;
    width: 100%;
    text-align: left;
    font-size: 14px;
    border-radius: 8px;
    padding: 10px;
    background: transparent;
    box-shadow: var(--ring-warm) 0 0 0 1px;
}

.channel-tabs button.active-channel {
    color: var(--bg-ivory);
    background: var(--brand);
    box-shadow: var(--brand) 0 0 0 1px;
}

.chat-main {
    display: grid;
    grid-template-rows: 56px 1fr auto;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 0 18px;
    border-bottom: 1px solid var(--border-cream);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.2rem;
}

.chat-messages {
    padding: 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

.chat-msg {
    max-width: 92%;
    border-radius: 12px;
    background: var(--bg-white);
    border: 1px solid var(--border-cream);
    padding: 10px 12px;
    color: var(--text-secondary);
}

.chat-sender {
    color: var(--brand);
    font-weight: 600;
    margin-right: 8px;
}

.chat-time {
    float: right;
    color: var(--text-tertiary);
    font-size: 12px;
}

.chat-input-area {
    border-top: 1px solid var(--border-cream);
    padding: 12px;
    display: flex;
    gap: 10px;
}

#chat-input {
    margin: 0;
}

.btn-send {
    width: auto;
    min-width: 84px;
    margin-top: 0;
    background: var(--brand);
    color: var(--bg-ivory);
    box-shadow: var(--brand) 0 0 0 1px;
}

/* Room page */
.room-shell {
    width: min(920px, calc(100vw - 24px));
    margin: 20px auto;
    padding: 24px;
}

#player-list {
    margin-top: 12px;
    border: 1px solid var(--border-cream);
    border-radius: 12px;
    background: var(--bg-white);
}

.player-item {
    padding: 9px 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-cream);
}

.player-item:last-child {
    border-bottom: none;
}

.settings {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 12px 0 4px;
    padding: 14px;
    border: 1px solid var(--border-cream);
    border-radius: 12px;
    background: var(--bg-white);
}

.settings label {
    color: var(--text-secondary);
    font-size: 14px;
}

.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.button-row button {
    margin-top: 0;
}

.deck-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(20, 20, 19, 0.58);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.deck-modal-panel {
    width: min(920px, 100%);
    max-height: 92vh;
    overflow: auto;
    padding: 18px;
    border-radius: 16px;
    background: var(--bg-ivory);
    border: 1px solid var(--border-cream);
}

.deck-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-cream);
    padding-bottom: 10px;
}

.modal-close {
    background: transparent;
    box-shadow: none;
    margin-top: 0;
    font-size: 28px;
    line-height: 1;
    padding: 2px 8px;
}

.deck-section-title {
    margin: 14px 0 8px;
}

.deck-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px;
    background: var(--bg-white);
    border: 1px solid var(--border-cream);
    border-radius: 12px;
}

.counter-chip {
    width: 100%;
    text-align: center;
    padding: 8px;
    margin-bottom: 10px;
    border-radius: 8px;
    background: var(--bg-sand);
    color: var(--text-secondary);
    font-weight: 600;
}

.counter-chip .ok {
    color: #556f48;
}

.counter-chip .warn {
    color: var(--danger);
}

.select-card {
    position: relative;
    width: 82px;
    min-height: 96px;
    border-radius: 10px;
    border: 1px solid var(--border-warm);
    background: var(--bg-parchment);
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    padding: 5px 4px;
    transition: 0.2s ease;
}

.select-card:hover {
    transform: translateY(-1px);
}

.select-card img {
    width: 45px;
    height: 45px;
    object-fit: contain;
}

.select-card .title {
    font-size: 10px;
    text-align: center;
    line-height: 1.2;
}

.select-card .level-badge,
.card-level {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 999px;
    background: rgba(20, 20, 19, 0.8);
    color: #e9d79f;
}

.select-card.is-selected {
    border-color: #8aa06f;
    background: #edf3e5;
    color: #43563a;
}

.select-card.is-unselected {
    opacity: 0.72;
}

/* Warehouse */
.warehouse-body {
    min-height: 100vh;
    padding: 24px 0;
}

.warehouse-container {
    width: min(1200px, calc(100vw - 24px));
    margin: 0 auto;
    padding: 24px;
}

.warehouse-container .card-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px;
    margin-bottom: 24px;
}

.warehouse-container .card {
    position: relative;
    width: 108px;
    min-height: 134px;
    border-radius: 12px;
    border: 1px solid var(--border-warm);
    background: var(--bg-white);
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px;
    cursor: pointer;
    transition: 0.2s ease;
}

.warehouse-container .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-whisper);
}

.warehouse-container .card img {
    width: 58px;
    height: 58px;
    object-fit: contain;
    margin-bottom: 6px;
}

.warehouse-container .card.owned {
    background: #f4f8ef;
    border-color: #d2e0bf;
}

.warehouse-container .card.locked {
    filter: grayscale(100%);
    opacity: 0.6;
}

.card-name {
    font-size: 13px;
    text-align: center;
}

.card-status {
    font-size: 11px;
    color: var(--danger);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(20, 20, 19, 0.55);
    padding: 14px;
}

.modal-content {
    width: min(760px, 100%);
    border-radius: 16px;
    background: var(--bg-ivory);
    border: 1px solid var(--border-cream);
    box-shadow: var(--ring-warm) 0 0 0 1px, var(--shadow-whisper);
    padding: 20px;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 28px;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
}

.modal-body {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
}

.modal-left {
    background: var(--bg-white);
    border: 1px solid var(--border-cream);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-left img {
    width: 160px;
    height: 160px;
    object-fit: contain;
}

.modal-right {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-item {
    border: 1px solid var(--border-cream);
    background: var(--bg-white);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text-secondary);
}

.stat-label {
    color: var(--text-emphasis);
    font-weight: 600;
    margin-right: 8px;
}

#modal-desc {
    margin: 8px 0 0;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 991px) {
    .lobby-content-wrapper {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .room-list {
        max-height: 320px;
    }

    .chat-panel {
        min-height: 500px;
    }
}

@media (max-width: 767px) {
    .container,
    .room-shell,
    .warehouse-container {
        width: calc(100vw - 16px);
        padding: 16px;
    }

    .lobby-header {
        padding: 0 12px;
        height: auto;
        min-height: 72px;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .chat-panel {
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border-cream);
    }

    .modal-body {
        grid-template-columns: 1fr;
    }
}