:root {
    --bg: #0a0a0d;
    --bg-elev: #15151b;
    --bg-card: #1a1a22;
    --border: #2a2a36;
    --text: #ececf1;
    --text-dim: #9090a0;
    --accent: #ff5d8f;
    --accent-2: #6ee7b7;
    --tile-bg: #f5e6c8;
    --tile-bg-2: #e6d2a8;
    --tile-shadow: rgba(0,0,0,.6);
    --tile-selected: #ff5d8f;
    --tile-text: #2c1810;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; overscroll-behavior: contain; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
button, input { font: inherit; }

/* ===== Topbar ===== */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    padding-top: max(10px, env(safe-area-inset-top));
    position: sticky; top: 0; z-index: 50;
}
.brand { font-weight: 700; font-size: 16px; }
.brand-mini { font-weight: 700; font-size: 14px; color: var(--text-dim); }
.ghost {
    color: var(--text-dim);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
}
.ghost:hover { color: var(--text); background: var(--border); }

/* ===== Login ===== */
.login-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.login-card {
    width: 100%; max-width: 360px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px 24px;
}
.brand-title { margin: 0 0 4px; font-size: 26px; text-align: center; }
.subtle { color: var(--text-dim); text-align: center; margin: 0 0 24px; font-size: 14px; }
.subtle.small { font-size: 12px; line-height: 1.5; max-width: 480px; margin: 24px auto 16px; padding: 0 16px; }
form label { display: block; margin-bottom: 14px; }
form label > span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
input[type=text], input[type=password] {
    width: 100%; padding: 12px 14px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
}
input:focus { border-color: var(--accent); }

.btn-primary {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 12px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 15px;
    min-height: 48px;
    width: 100%;
    margin-top: 6px;
    cursor: pointer;
}
.btn-primary:disabled { background: #555; cursor: not-allowed; }

/* ===== Lobby ===== */
.lobby-wrap { max-width: 480px; margin: 0 auto; padding: 24px 16px; text-align: center; }
.lobby-wrap h1 { margin: 0 0 24px; font-size: 24px; }
.lobby-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    margin-bottom: 20px;
}
#players-list { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; min-height: 36px; }
.player-chip {
    padding: 6px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 14px;
}
.player-chip.me { background: var(--accent); color: #fff; border-color: var(--accent); }
.status-text { margin: 16px 0; color: var(--text-dim); font-size: 14px; }

/* ===== Game Topbar ===== */
.game-topbar { padding: 8px 12px; }

/* ===== Status-Bar ===== */
.status-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    align-items: center;
    position: sticky; top: 49px; z-index: 40;
}
.player-status { min-width: 0; }
.player-name {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-status.me .player-name { color: var(--accent-2); }
.player-status.opp .player-name { color: var(--accent); }
.versus { font-weight: 700; color: var(--text-dim); font-size: 12px; padding: 0 6px; }

.progress {
    position: relative;
    height: 18px;
    background: var(--bg);
    border-radius: 9px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.progress-fill {
    position: absolute; left: 0; top: 0; bottom: 0;
    transition: width .35s ease-out;
}
.progress-fill.me { background: linear-gradient(90deg, #6ee7b7, #34d399); }
.progress-fill.opp { background: linear-gradient(90deg, #ff5d8f, #f43f5e); }
.progress-label {
    position: absolute; left: 0; right: 0; top: 0; bottom: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: var(--text);
    text-shadow: 0 0 4px rgba(0,0,0,.8);
}
.remaining { font-size: 11px; color: var(--text-dim); margin-top: 3px; text-align: right; }

@keyframes flash-penalty {
    0%, 100% { background: transparent; }
    50% { background: rgba(255,93,143,.25); }
}
.penalty-flash { animation: flash-penalty .6s ease-out; }

/* ===== Board ===== */
.board-wrap {
    overflow: hidden;
    width: 100vw;
    max-width: 100vw;
    height: calc(100vh - 49px - 70px);
    padding: 4px;
    -webkit-overflow-scrolling: touch;
}
.board {
    position: relative;
    transform-origin: top left;
    will-change: transform;
}

/* ===== Tiles ===== */
.tile {
    position: absolute;
    width: 50px;
    height: 64px;
    background: linear-gradient(135deg, #fafafa 0%, #e6e6e6 100%);
    border: 1px solid #888;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    box-shadow:
        2px 2px 0 0 #555,
        3px 3px 0 0 #333,
        4px 4px 8px rgba(0,0,0,.4);
    cursor: pointer;
    user-select: none;
    transition: transform .12s ease, box-shadow .12s ease, opacity .25s ease;
    color: #111;
    font-weight: 800;
}
.tile .symbol {
    font-size: 38px;
    line-height: 1;
    pointer-events: none;
    font-weight: 900;
}
.tile .symbol.symbol-text {
    font-size: 16px;
    letter-spacing: 0.5px;
}

/* === Suit-Farben === */
.tile.suit-b {
    background: linear-gradient(135deg, #c8f0c8 0%, #80c880 100%);
    color: #1a4a1a;
}
.tile.suit-c {
    background: linear-gradient(135deg, #cce0ff 0%, #6fa3e0 100%);
    color: #0a2a55;
}
.tile.suit-o {
    background: linear-gradient(135deg, #fff2c8 0%, #f5c850 100%);
    color: #5a3a0a;
}
.tile.suit-w {
    background: linear-gradient(135deg, #e0e0e0 0%, #a0a0a0 100%);
    color: #1a1a1a;
}
.tile.suit-d.dragon-r {
    background: linear-gradient(135deg, #ffb0b0 0%, #e04040 100%);
    color: #5a0000;
}
.tile.suit-d.dragon-g {
    background: linear-gradient(135deg, #a0d8a0 0%, #2a8a2a 100%);
    color: #ffffff;
}
.tile.suit-d.dragon-w {
    background: linear-gradient(135deg, #ffffff 0%, #d0d0d0 100%);
    color: #555;
    border: 2px solid #555;
}
.tile.suit-f {
    background: linear-gradient(135deg, #ffd5e8 0%, #f590bd 100%);
    color: #5a0a3a;
}
.tile.suit-s {
    background: linear-gradient(135deg, #c8f0f0 0%, #6fc8c8 100%);
    color: #0a4a5a;
}

.tile.blocked {
    filter: brightness(.55) saturate(.4);
    cursor: not-allowed;
}
.tile.free:active {
    transform: translate(1px, 1px);
    box-shadow:
        1px 1px 0 0 #6b5a3e,
        2px 2px 0 0 #5a4a2e,
        2px 2px 6px rgba(0,0,0,.4);
}
.tile.selected {
    outline: 3px solid var(--tile-selected);
    outline-offset: -3px;
    box-shadow:
        2px 2px 0 0 #6b5a3e,
        3px 3px 0 0 #5a4a2e,
        0 0 16px rgba(255,93,143,.7);
    z-index: 999 !important;
}
.tile.removing {
    transform: scale(.5) translate(-30%, -30%);
    opacity: 0;
}
.tile.shake { animation: shake .3s ease; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}
.tile.penalty-just-added { animation: penalty-pop .8s ease-out; }
@keyframes penalty-pop {
    0% { transform: scale(0) rotate(45deg); opacity: 0; }
    40% { transform: scale(1.2) rotate(0); opacity: 1; box-shadow: 0 0 20px rgba(255,93,143,.8), 2px 2px 0 0 #6b5a3e; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ===== Game Over ===== */
.game-over {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.8);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: 20px;
}
.game-over.hidden { display: none; }
.game-over-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 32px 24px;
    max-width: 360px;
    text-align: center;
}
.game-over-card h2 { margin: 0 0 12px; font-size: 28px; }
.game-over-card p { color: var(--text-dim); margin: 0 0 20px; }

/* ===== Toast ===== */
.toast-stack {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    z-index: 200; display: flex; flex-direction: column; gap: 8px;
    width: calc(100% - 32px); max-width: 400px;
}
.toast {
    padding: 12px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
}
.toast-error { border-left: 4px solid var(--accent); }
.toast-ok { border-left: 4px solid var(--accent-2); }
