* { box-sizing: border-box; }

:root {
    --felt: #1d6b45;
    --felt-dark: #145233;
    --card: #ffffff;
    --ink: #1c2833;
    --accent: #b03a2e;
    --accent-dark: #8c2d23;
    --gold: #f1c40f;
}

html, body {
    margin: 0;
    height: 100%;
    font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
    background: var(--felt-dark);
    color: var(--ink);
}

.app-main { min-height: 100vh; }

.app-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    font-size: 4rem;
    animation: pulse 1.2s infinite;
}

@keyframes pulse {
    50% { opacity: 0.4; }
}

/* ---------- Lobby ---------- */

.lobby {
    max-width: 26rem;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
    color: #fff;
}

.lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.lobby-header h1 { margin: 0.5rem 0; font-size: 1.8rem; }

.tagline { opacity: 0.85; }

.lobby-card {
    background: var(--card);
    color: var(--ink);
    border-radius: 12px;
    padding: 1rem 1.25rem 1.25rem;
    margin-top: 1rem;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.lobby-card h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }

.field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.field input, .field select {
    padding: 0.55rem 0.7rem;
    border: 1px solid #b9c2c9;
    border-radius: 8px;
    font-size: 1rem;
    color: var(--ink);
}

button {
    font-family: inherit;
    cursor: pointer;
}

.primary, .button-link {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.65rem 1.4rem;
    font-size: 1rem;
    text-decoration: none;
}

.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: 0.5; cursor: default; }

.secondary {
    background: transparent;
    color: var(--ink);
    border: 1px solid #b9c2c9;
    border-radius: 8px;
    padding: 0.65rem 1.4rem;
    font-size: 1rem;
}

.lang-toggle {
    background: rgba(255, 255, 255, 0.15);
    color: inherit;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 999px;
    padding: 0.25rem 0.9rem;
    font-size: 0.85rem;
}

.player-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
}

.player-list li {
    display: flex;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px dashed #d5dbdf;
}

.room-code { letter-spacing: 0.2em; font-weight: 700; }

.error-banner, .notice-banner {
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

.error-banner { background: #fdecea; color: #b03a2e; }
.notice-banner { background: #fef9e7; color: #7d6608; cursor: pointer; }

.center-note {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    color: #fff;
}

/* ---------- Tiles ---------- */

.tile {
    position: relative;
    aspect-ratio: 3 / 4;
    flex: none;
    user-select: none;
}

.tile-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.tile-lg { width: clamp(2.2rem, 8vw, 3.4rem); }
.tile-md { width: 2.2rem; }
.tile-sm { width: 1.7rem; }
.tile-xs { width: 1.15rem; }

.tile-clickable { cursor: pointer; }

.tile-selected {
    transform: translateY(-0.6rem);
    filter: drop-shadow(0 0 6px var(--gold));
}

.tile-row {
    display: flex;
    gap: 2px;
    align-items: flex-end;
    min-height: 1.2rem;
}

.tile-row.wrap { flex-wrap: wrap; }

.meld {
    display: inline-flex;
    gap: 1px;
    margin-right: 0.5rem;
}

/* ---------- Table ---------- */

.table-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 64rem;
    margin: 0 auto;
    padding: 0.5rem 0.75rem 1rem;
    background: var(--felt);
    color: #fff;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    opacity: 0.95;
}

.header-buttons {
    display: flex;
    gap: 0.4rem;
}

.opponents {
    display: flex;
    justify-content: space-around;
    gap: 0.75rem;
    padding: 0.5rem 0;
    flex-wrap: wrap;
}

.opponent {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 10px;
    padding: 0.4rem 0.6rem;
    min-width: 10rem;
}

.active-seat { outline: 2px solid var(--gold); }

.seat-label {
    display: flex;
    gap: 0.4rem;
    align-items: baseline;
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
}

.balance { margin-left: auto; font-weight: 700; color: var(--gold); }

.discard-area {
    flex: 1;
    background: rgba(0, 0, 0, 0.12);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    margin: 0.25rem 0;
}

.discard-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0.2rem 0;
}

.discard-name {
    width: 6.5rem;
    flex: none;
    font-size: 0.75rem;
    opacity: 0.85;
    padding-top: 0.3rem;
}

.action-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    min-height: 3rem;
    padding: 0.25rem 0;
}

.action-bar .hint { font-size: 0.85rem; opacity: 0.9; }

.action-button {
    background: #fff;
    color: var(--ink);
    border: none;
    border-radius: 999px;
    padding: 0.55rem 1.2rem;
    font-size: 1.05rem;
    font-weight: 700;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.hu-button { background: var(--accent); color: #fff; }

.own-area {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 12px;
    padding: 0.5rem 0.75rem 0.9rem;
}

.own-hand {
    display: flex;
    gap: 3px;
    margin-top: 0.4rem;
    padding-top: 0.6rem;
    flex-wrap: wrap;
}

/* ---------- Settlement board (docked, never hides the table) ---------- */

.settlement-dock {
    position: fixed;
    top: 3.5rem;
    right: 1rem;
    width: min(23rem, calc(100vw - 2rem));
    max-height: calc(100vh - 5rem);
    overflow-y: auto;
    z-index: 10;
}

.settlement {
    background: var(--card);
    color: var(--ink);
    border-radius: 14px;
    padding: 1.1rem 1.4rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(0, 0, 0, 0.2);
}

.win-desc {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    opacity: 0.85;
}

.winning-hand {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.6rem;
    margin-bottom: 0.6rem;
}

.won-on {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    padding-top: 0.5rem;
}

.settlement h2 { margin-top: 0; }

.score-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.75rem;
}

.score-table td { padding: 0.25rem 0; }
.score-table td:last-child { text-align: right; font-weight: 700; }
.score-total td { border-top: 2px solid var(--ink); font-size: 1.1rem; }

.balance-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
}

.balance-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    border-bottom: 1px dashed #d5dbdf;
}

.negative { color: var(--accent); font-weight: 700; }

.settlement-buttons { display: flex; gap: 0.75rem; }

#blazor-error-ui { display: none; }

/* ---------- Mobile (portrait) ---------- */

@media (max-width: 640px) {
    /* Settlement becomes a bottom sheet; the table stays visible above it. */
    .settlement-dock {
        top: auto;
        right: 0.5rem;
        left: 0.5rem;
        bottom: 0.5rem;
        width: auto;
        max-height: 60vh;
    }
    .opponent { min-width: 8rem; padding: 0.3rem 0.45rem; }
    .discard-name { width: 4.5rem; }
    .tile-sm { width: 1.35rem; }
    .tile-xs { width: 0.85rem; }
    .table-page { padding: 0.4rem 0.4rem 0.75rem; }
    .action-button { padding: 0.5rem 1rem; font-size: 1rem; }
}
