:root {
    --bg: #0d1713;
    --panel: #17251f;
    --panel-2: #1d3028;
    --felt: #164a35;
    --felt-dark: #0e3526;
    --line: rgba(255,255,255,.12);
    --text: #f5f7f6;
    --muted: #aab9b1;
    --accent: #e9c46a;
    --accent-2: #f4d98d;
    --danger: #b93b45;
    --warning: #b97828;
    --success: #2e8b62;
    --shadow: 0 14px 40px rgba(0,0,0,.28);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top, rgba(38,84,64,.35), transparent 35rem),
        var(--bg);
    color: var(--text);
}
button, input { font: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; }
.topbar {
    min-height: 74px;
    padding: 14px clamp(16px, 3vw, 42px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--line);
    background: rgba(8,18,14,.78);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { font-weight: 900; letter-spacing: .08em; font-size: 1.45rem; }
.brand-sub { color: var(--muted); font-size: .78rem; margin-top: 1px; }
.top-status { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: .82rem;
    background: rgba(255,255,255,.05);
}
.badge-accent { border-color: rgba(233,196,106,.45); color: var(--accent-2); }

main { width: min(1280px, 100%); margin: 0 auto; padding: clamp(16px, 2.5vw, 34px); }
.view { width: 100%; }
.hero-card {
    padding: clamp(24px, 5vw, 56px);
    border: 1px solid var(--line);
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(33,77,57,.72), rgba(18,31,26,.92));
    box-shadow: var(--shadow);
}
.hero-card h1 { margin: 5px 0 12px; font-size: clamp(2rem, 5vw, 4rem); line-height: 1.02; max-width: 850px; }
.hero-card p:not(.eyebrow) { color: var(--muted); max-width: 720px; margin-bottom: 0; }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .13em; font-size: .76rem; font-weight: 800; margin: 0 0 6px; }

.home-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
.panel {
    background: rgba(23,37,31,.95);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.form-panel { padding: 24px; display: grid; gap: 11px; }
.form-panel h2 { margin: 0 0 5px; }
label { font-size: .88rem; color: var(--muted); }
input {
    width: 100%;
    min-height: 48px;
    border-radius: 11px;
    border: 1px solid rgba(255,255,255,.16);
    background: #0f1c17;
    color: var(--text);
    padding: 0 13px;
    outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(233,196,106,.12); }
.room-input { text-transform: uppercase; letter-spacing: .15em; font-weight: 800; }

.btn {
    border: 1px solid transparent;
    border-radius: 11px;
    min-height: 44px;
    padding: 9px 15px;
    cursor: pointer;
    font-weight: 760;
    transition: transform .12s ease, filter .12s ease, opacity .12s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: .42; }
.btn-primary { background: var(--accent); color: #17130a; }
.btn-secondary { background: #315f4d; color: white; border-color: rgba(255,255,255,.08); }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-ghost { background: rgba(255,255,255,.055); border-color: var(--line); color: var(--text); }
.btn-small { min-height: 36px; padding: 6px 10px; font-size: .83rem; }
.btn-mini { min-height: 32px; padding: 4px 9px; font-size: .76rem; }

.game-view { display: grid; gap: 14px; }
.compact-panel { padding: 12px 14px; }
.game-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toolbar-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.connection { margin-left: 8px; font-size: .76rem; }
.connection.online { color: #77d7a6; }
.connection.offline { color: #ef9a9a; }

.lobby-panel, .score-panel { padding: clamp(18px, 3vw, 30px); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.section-heading h2 { margin: 0; }
.room-code-box { text-align: right; }
.room-code-box span { color: var(--muted); display: block; font-size: .72rem; text-transform: uppercase; }
.room-code-box strong { font-size: 1.5rem; letter-spacing: .13em; color: var(--accent); }
.player-list { display: grid; gap: 8px; margin: 20px 0; }
.player-row, .score-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 14px;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: rgba(255,255,255,.035);
}
.player-meta { color: var(--muted); font-size: .82rem; }
.dot { width: 8px; height: 8px; display: inline-block; border-radius: 50%; margin-right: 6px; background: #65736d; }
.dot.online { background: #63ca92; }
.round-start-area { margin-top: 25px; border-top: 1px solid var(--line); padding-top: 22px; }
.round-start-area h3 { margin-top: 0; }
.rule-choice-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; margin-bottom: 15px; }
.rule-choice { display: block; cursor: pointer; }
.rule-choice input { position: absolute; opacity: 0; pointer-events: none; }
.rule-choice-body {
    display: block;
    min-height: 118px;
    padding: 16px;
    border-radius: 13px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.035);
}
.rule-choice-body strong { display: block; color: var(--text); margin-bottom: 7px; }
.rule-choice-body small { color: var(--muted); line-height: 1.45; }
.rule-choice input:checked + .rule-choice-body {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(233,196,106,.12) inset;
    background: rgba(233,196,106,.07);
}

.table-wrap { display: grid; gap: 12px; }
.felt-table {
    min-height: 650px;
    position: relative;
    overflow: hidden;
    border-radius: 34px;
    border: 8px solid #35281c;
    background:
        radial-gradient(ellipse at center, rgba(255,255,255,.06), transparent 55%),
        linear-gradient(145deg, var(--felt), var(--felt-dark));
    box-shadow: inset 0 0 80px rgba(0,0,0,.35), var(--shadow);
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 16px;
    padding: 18px;
}
.opponents { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; min-height: 72px; }
.opponent {
    min-width: 120px;
    padding: 9px 11px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,.13);
    background: rgba(0,0,0,.20);
    text-align: center;
}
.opponent.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(233,196,106,.18), 0 0 25px rgba(233,196,106,.12); }
.opponent.offline { opacity: .55; }
.opponent-name { display: block; font-weight: 780; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opponent-stats { color: #d1ddd7; font-size: .76rem; margin-top: 3px; }

.center-table { align-self: center; display: grid; justify-items: center; gap: 18px; }
.round-info { text-align: center; display: grid; gap: 3px; }
.round-info > span:first-child { font-weight: 800; font-size: 1.08rem; }
.muted { color: var(--muted); }
.piles { display: flex; align-items: center; justify-content: center; gap: 25px; }
.pile {
    width: 104px;
    height: 146px;
    border-radius: 10px;
    border: 2px solid rgba(255,255,255,.38);
    position: relative;
    padding: 0;
    box-shadow: 0 8px 18px rgba(0,0,0,.25);
}
.card-back {
    background:
        linear-gradient(45deg, transparent 45%, rgba(255,255,255,.08) 45%, rgba(255,255,255,.08) 55%, transparent 55%),
        linear-gradient(-45deg, transparent 45%, rgba(255,255,255,.08) 45%, rgba(255,255,255,.08) 55%, transparent 55%),
        #782e34;
    background-size: 18px 18px;
}
.pile-count { position: absolute; right: 6px; bottom: 5px; background: rgba(0,0,0,.55); border-radius: 999px; padding: 2px 6px; color: white; font-size: .72rem; }
.discard-pile { background: rgba(0,0,0,.14); display: grid; place-items: center; }
.empty-discard { color: rgba(255,255,255,.45); }
.final-phase-notice { padding: 8px 12px; border-radius: 10px; background: rgba(185,59,69,.18); border: 1px solid rgba(255,173,181,.35); text-align: center; }

.my-zone { align-self: end; background: rgba(0,0,0,.18); border-radius: 18px; border: 1px solid rgba(255,255,255,.09); padding: 12px; }
.my-zone-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 9px; }
.sort-actions { display: flex; gap: 6px; }
.hand {
    display: flex;
    align-items: flex-end;
    min-height: 154px;
    overflow-x: auto;
    padding: 4px 5px 10px;
    scrollbar-width: thin;
}
.playing-card {
    --overlap: -33px;
    flex: 0 0 88px;
    width: 88px;
    height: 126px;
    margin-left: var(--overlap);
    border-radius: 9px;
    border: 2px solid rgba(0,0,0,.18);
    background: #f7f5ef;
    color: #161616;
    position: relative;
    cursor: pointer;
    box-shadow: 0 7px 15px rgba(0,0,0,.25);
    transform: translateY(0);
    transition: transform .12s ease, box-shadow .12s ease, outline .12s ease;
    user-select: none;
}
.playing-card:first-child { margin-left: 0; }
.playing-card.red { color: #bc2434; }
.playing-card.selected { transform: translateY(-14px); outline: 3px solid var(--accent); box-shadow: 0 12px 24px rgba(0,0,0,.36); }
.playing-card.wild { box-shadow: 0 0 0 3px rgba(233,196,106,.7) inset, 0 7px 15px rgba(0,0,0,.25); }
.card-corner { position: absolute; left: 7px; top: 5px; font-weight: 900; line-height: .92; text-align: center; font-size: 1.05rem; }
.card-corner.bottom { left: auto; top: auto; right: 7px; bottom: 5px; transform: rotate(180deg); }
.card-suit-center { position: absolute; inset: 0; display: grid; place-items: center; font-size: 2.45rem; }
.card-joker { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 950; letter-spacing: .08em; transform: rotate(-8deg); font-size: .9rem; color: #51358f; }
.discard-pile .playing-card { margin: 0; width: 100%; height: 100%; border: 0; }

.action-panel { display: grid; gap: 10px; }
.selection-info { font-size: .86rem; color: var(--muted); }
.action-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.knock-btn { letter-spacing: .08em; }
.hand-check { padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.035); }
.hand-check.good { color: #91e0b5; border-color: rgba(99,202,146,.35); }
.hand-check.bad { color: #f1b1b7; border-color: rgba(185,59,69,.4); }

.score-table { display: grid; gap: 7px; margin-top: 18px; }
.score-row { grid-template-columns: minmax(0,1fr) 110px 120px; }
.score-row.header { color: var(--muted); font-size: .78rem; text-transform: uppercase; background: transparent; border-style: dashed; }
.score-row.winner { border-color: rgba(233,196,106,.55); background: rgba(233,196,106,.08); }
#betweenRoundActions { margin-top: 18px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: max(18px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 100;
    max-width: min(92vw, 640px);
    padding: 11px 15px;
    border-radius: 10px;
    background: #f3f5f4;
    color: #14201b;
    box-shadow: 0 10px 35px rgba(0,0,0,.42);
    font-weight: 700;
}
.toast.error { background: #ffd7da; color: #5b141b; }

.rules-dialog { width: min(720px, 92vw); max-height: 82vh; border: 1px solid var(--line); border-radius: 16px; color: var(--text); background: #15241e; padding: 0; box-shadow: var(--shadow); }
.rules-dialog::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; }
.icon-btn { border: 0; background: transparent; color: white; font-size: 1.8rem; cursor: pointer; }
.rules-content { padding: 18px; line-height: 1.58; color: #d6e0db; }
.rules-content h3 { color: var(--accent-2); margin-bottom: 4px; }

@media (max-width: 760px) {
    main { padding: 12px; }
    .topbar { min-height: 64px; padding: 10px 13px; }
    .brand-sub { display: none; }
    .top-status .badge:nth-child(1) { display: none; }
    .home-grid, .rule-choice-grid { grid-template-columns: 1fr; }
    .game-toolbar { align-items: flex-start; }
    .toolbar-actions { max-width: 190px; }
    .felt-table { min-height: 620px; border-width: 5px; border-radius: 23px; padding: 10px; }
    .opponents { gap: 6px; }
    .opponent { min-width: 94px; padding: 7px; }
    .pile { width: 84px; height: 120px; }
    .playing-card { --overlap: -42px; flex-basis: 76px; width: 76px; height: 110px; }
    .hand { min-height: 142px; }
    .action-buttons .btn { flex: 1 1 42%; }
    .score-row { grid-template-columns: minmax(0,1fr) 72px 80px; gap: 8px; }
}

@media (max-width: 430px) {
    .hero-card { padding: 24px 18px; }
    .section-heading { align-items: center; }
    .playing-card { --overlap: -48px; }
    .playing-card:first-child { margin-left: 0; }
    .my-zone-head { align-items: flex-start; }
    .sort-actions { flex-direction: column; }
    .action-buttons .btn { flex-basis: 100%; }
}
