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

:root {
    --bg: #f4f1ea;
    --panel: #fffdf8;
    --panel-strong: #f7efe2;
    --ink: #1e2528;
    --muted: #667076;
    --line: #ded5c7;
    --accent: #0f766e;
    --accent-dark: #0b5d57;
    --danger: #b42318;
    --warn: #b7791f;
    --blue: #2356a3;
    --shadow: 0 18px 50px rgba(34, 28, 18, 0.12);
}

body {
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0)),
        var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 16px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button:hover {
    background: var(--accent-dark);
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

input,
select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 10px 12px;
}

input:focus,
select:focus,
button:focus-visible {
    outline: 3px solid rgba(15, 118, 110, 0.22);
    outline-offset: 2px;
}

#app {
    width: 100%;
    min-height: 100vh;
    padding: 24px;
}

.screen {
    display: none;
    width: 100%;
    max-width: 1380px;
    margin: 0 auto;
}

.screen.active {
    display: block;
}

#lobby,
#game,
#replay {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

#lobby {
    padding: 28px;
}

.lobby-header,
.game-header,
.replay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 18px;
}

.eyebrow {
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

#lobby h1 {
    margin-top: 4px;
    font-size: 36px;
    line-height: 1.15;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    border: 1px solid rgba(15, 118, 110, 0.24);
    border-radius: 999px;
    background: rgba(15, 118, 110, 0.08);
    color: var(--accent-dark);
    padding: 5px 10px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.status-pill.muted {
    border-color: var(--line);
    background: #fff;
    color: var(--muted);
}

.status-pill.error {
    border-color: rgba(180, 35, 24, 0.26);
    background: rgba(180, 35, 24, 0.08);
    color: var(--danger);
}

.game-type-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 22px 0;
}

.game-type-card {
    position: relative;
    display: grid;
    gap: 6px;
    min-height: 92px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 16px;
    cursor: pointer;
}

.game-type-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.game-type-card strong {
    font-size: 20px;
}

.game-type-card span {
    color: var(--muted);
    font-size: 14px;
}

.game-type-card.active {
    border-color: var(--accent);
    background: rgba(15, 118, 110, 0.08);
}

.lobby-container {
    display: grid;
    grid-template-columns: 1.15fr 1fr 1fr;
    gap: 16px;
}

.lobby-section {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 18px;
}

.lobby-section.primary-action {
    background: var(--panel-strong);
}

.lobby-section h2,
.move-history h3 {
    margin-bottom: 14px;
    font-size: 18px;
}

.lobby-section form {
    display: grid;
    gap: 12px;
}

.lobby-section label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

#game,
#replay {
    padding: 18px;
}

.game-info,
.game-controls,
.replay-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.game-info > span {
    min-height: 34px;
}

#game-type-display,
#game-id-display {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 7px 10px;
    font-weight: 800;
}

#copy-invite-btn,
#copy-spectate-btn,
#replay-btn {
    border-color: var(--line);
    background: #fff;
    color: var(--ink);
}

#copy-invite-btn:hover,
#copy-spectate-btn:hover,
#replay-btn:hover {
    border-color: var(--accent);
    color: var(--accent-dark);
}

#draw-propose-btn {
    background: var(--warn);
}

#resign-btn {
    background: var(--danger);
}

#leave-btn {
    background: #4b5563;
}

.room-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 14px 0 18px;
}

.room-panel > div {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 10px 12px;
}

.room-label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.room-panel code {
    display: block;
    overflow: hidden;
    color: var(--blue);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
}

.player-info {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-strong);
    padding: 12px;
}

.player {
    display: grid;
    gap: 4px;
    min-height: 78px;
    border: 1px solid rgba(222, 213, 199, 0.72);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.7);
    padding: 10px;
}

.player-name {
    font-size: 17px;
    font-weight: 800;
}

.player-color {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.timer {
    color: var(--accent-dark);
    font-size: 20px;
    font-weight: 900;
}

.turn-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.turn-indicator::before {
    content: "等待";
}

.turn-indicator.active {
    background: var(--accent);
    color: #fff;
}

.turn-indicator.active::before {
    content: "落子";
}

#board-container,
#replay-board-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 420px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #efe4d2;
    padding: 16px;
}

#game-board,
#replay-board {
    display: block;
    max-width: 100%;
    max-height: min(72vh, 760px);
    border: 2px solid #3c2f24;
    background: #f5deb3;
    box-shadow: 0 10px 24px rgba(34, 28, 18, 0.18);
}

.game-sidebar {
    display: grid;
    align-content: start;
    gap: 14px;
}

.move-history,
.game-status,
.replay-info {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 14px;
}

.move-history {
    max-height: 460px;
    overflow-y: auto;
}

#moves-list {
    display: grid;
    gap: 6px;
}

.move-item,
.empty-moves {
    border-radius: 6px;
    background: #f7f3ec;
    padding: 8px 10px;
    color: var(--muted);
    font-size: 14px;
}

.move-item {
    color: var(--ink);
}

#status-message {
    display: grid;
    gap: 10px;
    color: var(--ink);
    font-weight: 800;
    line-height: 1.45;
}

.export-btn {
    width: fit-content;
    background: var(--blue);
}

.replay-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
    margin-top: 18px;
}

.replay-info {
    max-height: 620px;
    overflow-y: auto;
}

#replay-moves ul {
    display: grid;
    gap: 6px;
    list-style: none;
}

#replay-moves li {
    border-radius: 6px;
    padding: 7px 8px;
}

#replay-moves li.active {
    background: rgba(15, 118, 110, 0.12);
    color: var(--accent-dark);
    font-weight: 800;
}

@media (max-width: 1060px) {
    .lobby-container,
    .game-content,
    .replay-content {
        grid-template-columns: 1fr;
    }

    .game-sidebar {
        grid-row: auto;
    }
}

@media (max-width: 760px) {
    #app {
        padding: 12px;
    }

    #lobby,
    #game,
    #replay {
        padding: 14px;
    }

    .lobby-header,
    .game-header,
    .replay-header {
        align-items: stretch;
        flex-direction: column;
    }

    #lobby h1 {
        font-size: 30px;
    }

    .game-type-grid,
    .room-panel,
    .player-info {
        grid-template-columns: 1fr;
    }

    .turn-indicator {
        width: 100%;
        height: 34px;
        border-radius: 8px;
    }

    .game-controls button,
    .replay-controls button {
        flex: 1 1 130px;
    }

    #board-container,
    #replay-board-container {
        min-height: 300px;
        padding: 8px;
    }
}
