/* style.css - Quoridor Online */
:root {
    --bg: #0f0d0a;
    --bg-2: #1a1410;
    --bg-3: #241c17;
    --panel: #2d231c;
    --panel-2: #3a2d24;
    --board-frame: #b85c3c;
    --board-frame-dark: #8c4329;
    --cell: #2a2520;
    --cell-light: #38302a;
    --wall: #d4a05c;
    --wall-shadow: #8b6432;
    --p1: #4ecdc4;
    --p2: #ff6b6b;
    --text: #f4ebe0;
    --text-dim: #a89685;
    --accent: #e8a838;
    --error: #e74c3c;
    --success: #27ae60;
    --border: #3a2d24;
}

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

html, body { width: 100%; height: 100%; }

body {
    font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--board-frame); }

/* === Lobby === */
.lobby-body {
    background: linear-gradient(180deg, var(--bg-3) 0%, var(--bg) 50%);
    padding: 2rem 1rem;
    min-height: 100vh;
}

.lobby {
    max-width: 900px;
    margin: 0 auto;
}

.logo {
    text-align: center;
    margin-bottom: 3rem;
}

.logo h1 {
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: -0.03em;
    margin-bottom: 0.3rem;
    background: linear-gradient(135deg, var(--accent), var(--board-frame));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo .subtitle {
    color: var(--text-dim);
    font-size: 1.1rem;
    letter-spacing: 0.05em;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.8rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(232, 168, 56, 0.1);
}

.card h2 {
    font-size: 1.1rem;
    margin-bottom: 1.2rem;
    color: var(--accent);
    font-weight: 700;
    letter-spacing: 0.05em;
}

.card h3 {
    font-size: 1rem;
    margin-bottom: 0.8rem;
    color: var(--text);
    font-weight: 600;
}

.card-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.card-link {
    text-align: center;
    padding: 2rem 1.5rem;
    cursor: pointer;
}

.card-link h2 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.card-link p {
    color: var(--text-dim);
    margin-bottom: 1rem;
}

.card-full {
    grid-column: 1 / -1;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 0.8rem 1rem;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 0.8rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(232, 168, 56, 0.1);
}

.btn,
.btn-primary,
.btn-secondary,
.btn-link,
.btn-small {
    display: inline-block;
    padding: 0.8rem 1.4rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    font-family: inherit;
    text-align: center;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #c8862a);
    color: #1a1410;
    width: 100%;
    box-shadow: 0 4px 12px rgba(232, 168, 56, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(232, 168, 56, 0.3);
}

.btn-secondary {
    background: var(--board-frame);
    color: #fff;
    width: 100%;
    box-shadow: 0 4px 12px rgba(184, 92, 60, 0.2);
}

.btn-secondary:hover {
    background: var(--board-frame-dark);
    transform: translateY(-2px);
}

.btn-link {
    color: var(--accent);
    background: transparent;
    padding: 0.4rem 0;
    width: auto;
}

.btn-link:hover { color: var(--board-frame); }

.btn-small {
    padding: 0.5rem 0.8rem;
    font-size: 0.85rem;
}

.button-group {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

.button-group .btn {
    flex: 1;
    min-width: 150px;
}

.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    border-left: 4px solid;
}

.alert-error {
    background: rgba(231, 76, 60, 0.1);
    border-left-color: var(--error);
    color: #ff9999;
}

.alert-success {
    background: rgba(39, 174, 96, 0.1);
    border-left-color: var(--success);
    color: #99ff99;
}

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

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.ranking-table th,
.ranking-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.ranking-table th {
    color: var(--text-dim);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-2);
}

.ranking-table tbody tr {
    transition: background 0.15s;
}

.ranking-table tbody tr:hover {
    background: var(--panel-2);
}

.ranking-table .rank { color: var(--accent); font-weight: 700; min-width: 50px; }
.ranking-table .name a { color: var(--text); text-decoration: none; }
.ranking-table .name a:hover { color: var(--accent); }
.ranking-table .wins { color: var(--success); font-weight: 600; }
.ranking-table .winrate { color: var(--accent); }
.ranking-table .fastest { color: var(--text-dim); }

.rank-top { background: rgba(232, 168, 56, 0.08); }

.table-responsive { overflow-x: auto; }

.stat-card {
    text-align: center;
    padding: 2rem !important;
}

.stat-number {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.stat-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.stat-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem;
    background: var(--bg-2);
    border-radius: 6px;
    border-left: 3px solid var(--accent);
}

.stat-list-item .name a {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}

.stat-list-item .name a:hover { color: var(--accent); }
.stat-list-item .value { color: var(--text-dim); font-size: 0.9rem; }

.games-list,
.matchups-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.game-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-2);
    border-radius: 8px;
    border-left: 4px solid;
}

.game-item.win { border-left-color: var(--success); }
.game-item.loss { border-left-color: var(--error); }

.game-result {
    font-size: 1.5rem;
    font-weight: 900;
    min-width: 40px;
}

.game-item.win .game-result { color: var(--success); }
.game-item.loss .game-result { color: var(--error); }

.game-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.game-details .vs { color: var(--text); font-weight: 600; }
.game-details .moves { color: var(--text-dim); font-size: 0.85rem; }
.game-details .date { color: var(--text-dim); font-size: 0.8rem; }

.matchup-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem;
    background: var(--bg-2);
    border-radius: 6px;
}

.matchup-item .opponent { font-weight: 600; color: var(--text); }
.matchup-item .record { color: var(--accent); font-weight: 700; margin: 0 1rem; }
.matchup-item .total { color: var(--text-dim); font-size: 0.9rem; }

.lobby-footer {
    text-align: center;
    margin-top: 3rem;
    padding: 2rem 0;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.85rem;
}

/* === Game === */
.game-body {
    background: var(--bg);
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

.game-wrap {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--panel);
    padding: 0.6rem 1rem;
    border-radius: 12px;
    margin-bottom: 0.6rem;
    border: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.header-left { flex: 0.5; }
.header-center { flex: 1; text-align: center; }
.header-right { flex: 0.5; text-align: right; }

.game-code {
    font-size: 0.9rem;
    color: var(--text-dim);
}

.game-code strong {
    color: var(--accent);
    font-family: monospace;
    letter-spacing: 0.15em;
    font-weight: 700;
}

.players-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.player {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.8rem;
    background: var(--bg-2);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.player .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.player.p1 .dot { background: var(--p1); }
.player.p2 .dot { background: var(--p2); }

.player.active {
    box-shadow: 0 0 0 3px var(--accent);
    transform: scale(1.05);
}

.player .name { font-weight: 600; }

.walls-left {
    background: var(--wall);
    color: #2d231c;
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 800;
    margin-left: 0.3rem;
}

.vs {
    color: var(--text-dim);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.game-main {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1rem;
    flex: 1;
    min-width: 0;
}

@media (max-width: 1000px) {
    .game-main { grid-template-columns: 1fr; }
    .sidebar { grid-column: 1; }
}

.board-section {
    background: var(--panel);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    min-width: 0;
    width: 100%;
}

.status-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg-2);
    border-radius: 8px;
    flex-wrap: wrap;
}

.status-left { flex: 1; }
.status-right { flex: 0; white-space: nowrap; }

.status-text {
    font-weight: 700;
    color: var(--accent);
    font-size: 0.9rem;
}

.mode-toggle {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.mode-toggle button {
    background: var(--bg-3);
    color: var(--text-dim);
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 600;
    white-space: nowrap;
}

.mode-toggle button.active {
    background: var(--accent);
    color: #1a1410;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(232, 168, 56, 0.3);
}

#moveCounter {
    color: var(--text-dim);
    font-size: 0.85rem;
    font-weight: 600;
}

/* ===== BOARD =====
   Board füllt 100% des Container-Parents (board-section),
   genau wie die Header-Box. Grid-Templates nutzen fr-Units
   damit 9 Zellen + 8 Gaps die volle Breite einnehmen.

   Gap = 25% einer Zelle → Zelle ist 4 Einheiten, Gap ist 1 Einheit.
   Gesamt = 9*4 + 8*1 = 44 Einheiten Breite.
   Padding = 1.5 Gap-Einheiten = 1.5 Einheiten.

   aspect-ratio: 1 hält das Board quadratisch.
*/
.board {
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(8, 4fr 1fr) 4fr;
    grid-template-rows:    repeat(8, 4fr 1fr) 4fr;
    background: var(--board-frame);
    padding: 1.5%;
    gap: 0;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.1);
    margin: 0 auto 0.8rem;
    position: relative;
}

.board > * { user-select: none; }

.cell {
    background: var(--cell);
    border-radius: 4px;
    position: relative;
    cursor: default;
    transition: all 0.15s;
    box-shadow: inset 0 1px 2px rgba(255,255,255,0.05);
    min-width: 0;
    min-height: 0;
}

.cell.legal {
    background: rgba(232, 168, 56, 0.7);
    cursor: pointer;
    box-shadow: inset 0 0 0 3px var(--accent), 0 0 20px rgba(232, 168, 56, 0.8);
    border-radius: 6px;
}

.cell.legal:hover {
    background: rgba(232, 168, 56, 0.9);
    transform: scale(1.1);
    box-shadow: inset 0 0 0 3px var(--accent), 0 0 30px rgba(232, 168, 56, 1);
}

.pawn {
    position: absolute;
    inset: 8%;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.8), inset 0 -4px 8px rgba(0,0,0,0.5), inset 0 2px 5px rgba(255,255,255,0.2);
    pointer-events: none;
    z-index: 2;
}

.pawn.p1 {
    background: radial-gradient(circle at 35% 35%, #80f0e8, #2a8c84);
}

.pawn.p2 {
    background: radial-gradient(circle at 35% 35%, #ff9090, #aa3434);
}

.wall-slot {
    background: transparent;
    cursor: default;
    border-radius: 3px;
    transition: all 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: 1px solid rgba(212, 160, 92, 0.1);
    min-width: 0;
    min-height: 0;
}

.wall-slot.placeable {
    background: rgba(232, 168, 56, 0.2) !important;
    cursor: pointer;
    border: 1px solid rgba(232, 168, 56, 0.3) !important;
}

.wall-slot.preview {
    background: rgba(255, 200, 50, 0.95) !important;
    cursor: pointer;
    border: 3px solid rgba(255, 200, 50, 1) !important;
    box-shadow: 0 0 20px rgba(255, 200, 50, 1), inset 0 0 10px rgba(255, 255, 200, 0.6);
}

.wall-slot.preview:active {
    background: rgba(255, 220, 80, 1) !important;
    box-shadow: 0 0 25px rgba(255, 200, 50, 1), inset 0 0 12px rgba(255, 255, 255, 0.8);
}

.wall-slot.filled {
    background: linear-gradient(135deg, #e8c25f, #c8934f);
    box-shadow: 0 3px 6px rgba(0,0,0,0.6), inset 0 1px 2px rgba(255,255,255,0.2);
    border: none;
}

.board-legend {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
    margin-top: 0.3rem;
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.panel {
    background: var(--panel);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-bottom: 0.8rem;
    font-weight: 700;
}

.panel-history { flex: 1; }
.panel-chat { flex: 1; }

.history {
    max-height: 250px;
    overflow-y: auto;
    font-size: 0.85rem;
    flex: 1;
}

.history-entry {
    padding: 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.3rem;
    background: var(--bg-2);
    border-left: 3px solid var(--accent);
}

.history-entry .num {
    color: var(--text-dim);
    font-family: monospace;
    margin-right: 0.4rem;
    font-size: 0.75rem;
}

.history-entry .p1 { color: var(--p1); font-weight: 600; }
.history-entry .p2 { color: var(--p2); font-weight: 600; }

.chat {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 0.8rem;
    font-size: 0.9rem;
    flex: 1;
}

.chat-entry {
    padding: 0.5rem;
    margin-bottom: 0.3rem;
    border-radius: 4px;
    background: var(--bg-2);
}

.chat-entry .author {
    font-weight: 700;
    margin-right: 0.4rem;
}

.chat-entry.p1 .author { color: var(--p1); }
.chat-entry.p2 .author { color: var(--p2); }

.chat-input {
    display: flex;
    gap: 0.4rem;
}

.chat-input input {
    flex: 1;
    margin-bottom: 0;
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
}

.chat-input button {
    background: var(--accent);
    color: #1a1410;
    padding: 0.6rem 1rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Winner Overlay */
.winner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.winner-card {
    background: var(--panel);
    padding: 3rem;
    border-radius: 16px;
    text-align: center;
    border: 2px solid var(--accent);
    box-shadow: 0 10px 40px rgba(232, 168, 56, 0.3);
    animation: slideIn 0.4s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: scale(0.8); }
    to   { opacity: 1; transform: scale(1); }
}

.winner-card h2 {
    font-size: 3rem;
    background: linear-gradient(135deg, var(--accent), var(--board-frame));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.winner-card p {
    color: var(--text-dim);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.game-footer {
    text-align: center;
    margin-top: 1rem;
    padding: 0.8rem;
    color: var(--text-dim);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}

.game-footer a {
    color: var(--accent);
    text-decoration: none;
}

.game-footer a:hover { color: var(--board-frame); }

/* === Responsive === */
@media (max-width: 1000px) {
    .game-main {
        grid-template-columns: 1fr !important;
    }
    .sidebar {
        grid-column: 1;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
    .panel-history,
    .panel-chat {
        min-height: auto;
    }
}

@media (max-width: 768px) {
    .logo h1 { font-size: 2.5rem; }

    .sidebar {
        grid-template-columns: 1fr !important;
    }

    .game-header {
        flex-direction: column;
        text-align: center;
        padding: 0.5rem 0.8rem;
        gap: 0.4rem;
    }

    .header-left,
    .header-center,
    .header-right {
        flex: 1;
        width: 100%;
        text-align: center;
    }

    .players-row {
        gap: 0.5rem;
        justify-content: center;
    }

    .player {
        font-size: 0.8rem;
        padding: 0.35rem 0.6rem;
    }

    .mode-toggle {
        flex-wrap: wrap;
        justify-content: center;
    }

    .mode-toggle button {
        flex: 1;
        min-width: 70px;
    }

    .history { max-height: 200px; }
    .chat    { max-height: 200px; }
}

@media (max-width: 480px) {
    .game-wrap { padding: 0.4rem; }

    .game-header {
        padding: 0.4rem 0.6rem;
        gap: 0.3rem;
    }

    .game-code { font-size: 0.75rem; }

    .players-row { gap: 0.3rem; }

    .player {
        font-size: 0.72rem;
        padding: 0.25rem 0.45rem;
    }

    .walls-left {
        font-size: 0.62rem;
        padding: 0.1rem 0.3rem;
    }

    .vs { font-size: 0.72rem; }

    .board-section {
        padding: 0.5rem;
    }

    .board {
        margin-bottom: 0.5rem;
    }

    .status-bar {
        padding: 0.4rem 0.6rem;
        gap: 0.4rem;
        margin-bottom: 0.5rem;
    }

    .status-text { font-size: 0.8rem; }
    #moveCounter  { font-size: 0.75rem; }

    .mode-toggle button {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }

    .panel { padding: 0.6rem; }
    .panel h3 { font-size: 0.75rem; margin-bottom: 0.4rem; }
    .history { max-height: 160px; font-size: 0.75rem; }
    .chat    { max-height: 160px; font-size: 0.75rem; }

    .chat-input input  { font-size: 0.8rem; padding: 0.4rem; }
    .chat-input button { padding: 0.4rem 0.6rem; font-size: 0.7rem; }

    .board-legend { font-size: 0.7rem; }
    .game-footer  { padding: 0.5rem; font-size: 0.7rem; }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}