/* ================= 1. 色彩与材质 ================= */
:root {
    --bg-color: #f4ebd8;
    --panel-bg: rgba(252, 249, 242, 0.95);
    --text-main: #3e3228;
    --text-muted: #8b7355;
    --border-color: #d8c3a5;
    --board-bg: #e0b986;
    --btn-bg: #7a634b;
    --btn-hover: #634f3b;
    --btn-active: #4a3b2b;
    --danger-color: #a84232;
}

body {
    background-color: var(--bg-color);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.06'/%3E%3C/svg%3E");
    color: var(--text-main);
    font-family: 'KaiTi', 'STKaiti', 'SimSun', serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 15px;
    box-sizing: border-box;
    overflow-x: hidden;
}

.container {
    width: 100%;
    max-width: 720px;
}

.container:has(#panel-game.active) {
    max-width: 920px;
}

.panel {
    display: none;
    opacity: 0;
}

.panel.active {
    display: flex;
    flex-direction: column;
    animation: slideInFromLeft 0.4s ease forwards;
}

.panel.slide-out-right {
    display: flex;
    flex-direction: column;
    animation: slideOutToRight 0.35s ease forwards;
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutToRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(50px);
    }
}

h1 {
    text-align: center;
    font-size: 30px;
    font-weight: normal;
    margin: 0 0 30px 0;
    letter-spacing: 6px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
    color: #2c231c;
    position: relative;
}

h1::after {
    content: "弈";
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-bg);
    padding: 0 10px;
    color: var(--danger-color);
    font-size: 16px;
    border-radius: 50%;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-title {
    font-size: 18px;
    margin-bottom: 12px;
    font-weight: bold;
    color: #3a2e25;
}

.radio-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.radio-label input {
    display: none;
}

.radio-btn {
    display: inline-block;
    padding: 8px 20px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 16px;
    color: var(--text-muted);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.radio-btn:hover {
    border-color: var(--btn-bg);
    color: var(--text-main);
}

.radio-label input:checked+.radio-btn {
    background: var(--btn-bg);
    color: #fff;
    border-color: var(--btn-active);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
}

.custom-input {
    width: 120px;
    padding: 10px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.7);
    color: var(--text-main);
    border-radius: 6px;
    text-align: center;
    font-size: 18px;
    font-family: inherit;
    transition: all 0.3s;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.custom-input:focus {
    outline: none;
    border-color: var(--btn-bg);
    background: #fff;
}

button {
    background-color: var(--btn-bg);
    color: #fcf9f2;
    border: none;
    padding: 12px 28px;
    font-size: 18px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 2px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(74, 60, 49, 0.15);
}

button:hover {
    background-color: var(--btn-hover);
    box-shadow: 0 0 0 2px var(--border-color), 0 6px 12px rgba(74, 60, 49, 0.2);
}

button:active {
    background-color: var(--btn-active);
    box-shadow: 0 0 0 2px var(--btn-active), 0 2px 4px rgba(74, 60, 49, 0.15);
}

.btn-center {
    margin: 10px auto;
    width: 60%;
    min-width: 200px;
    padding: 14px 0;
    font-size: 20px;
}

.room-code {
    font-size: 36px;
    font-weight: bold;
    letter-spacing: 8px;
    color: var(--danger-color);
    background: #fff;
    padding: 15px 40px;
    border-radius: 8px;
    border: 2px dashed var(--border-color);
    margin: 20px 0;
    text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.05);
}

.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;
}

.info-box {
    font-size: 22px;
    font-weight: bold;
}

.score-box {
    font-size: 16px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.6);
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.game-layout {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 30px;
    width: 100%;
    margin-top: 10px;
}

canvas {
    background-color: var(--board-bg);
    box-shadow:
        inset 0 0 40px rgba(115, 80, 50, 0.15),
        0 8px 0 #b38b6d,
        0 16px 30px rgba(50, 30, 20, 0.3);
    border-radius: 4px;
    border: 1px solid #8c6239;
    cursor: crosshair;
    width: 100%;
    max-width: 720px;
    height: auto;
    aspect-ratio: 1 / 1;
    margin-bottom: 15px;
}

.game-footer {
    display: flex;
    gap: 20px;
    justify-content: center;
    width: 100%;
    margin-top: 10px;
}

.win-text {
    color: var(--danger-color);
    animation: fadeInText 0.6s ease-in forwards;
}

@keyframes fadeInText {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ================= 悬浮聊天组件 ================= */
#chat-widget {
    position: fixed;
    right: 30px;
    bottom: 30px;
    z-index: 1000;
}

.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: var(--danger-color);
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    padding: 0 5px;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}

.chat-panel {
    display: flex;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8) translateY(20px);
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 340px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition:
        opacity 0.25s ease,
        transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
        visibility 0.3s;
}

.chat-panel.active {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
}

.chat-header {
    background: var(--btn-bg);
    color: #fff;
    padding: 12px 16px;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    letter-spacing: 1px;
}

.close-chat-btn {
    background: transparent !important;
    border: none;
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    box-shadow: none !important;
    margin: 0;
}

.close-chat-btn:hover {
    color: #ffd0c0;
    transform: scale(1.1);
}

.chat-messages {
    height: 260px;
    overflow-y: auto;
    padding: 12px;
    background: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-main);
    scroll-behavior: smooth;
}

.chat-messages .msg {
    margin: 4px 0 8px;
    padding: 2px 0;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.08);
}

.chat-messages .msg.self {
    color: var(--btn-bg);
    font-weight: bold;
}

.chat-messages .msg.opponent {
    color: var(--danger-color);
}

.chat-messages .msg.self::before {
    content: '我';
    display: inline-block;
    background: var(--btn-bg);
    color: #fff;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 8px;
    font-weight: normal;
}

.chat-messages .msg.opponent::before {
    content: '对';
    display: inline-block;
    background: var(--danger-color);
    color: #fff;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 8px;
}

.chat-messages .msg .time {
    color: var(--text-muted);
    font-size: 11px;
    margin-right: 8px;
    font-weight: normal;
}

.chat-input-area {
    display: flex;
    padding: 12px;
    gap: 10px;
    background: rgba(255, 255, 255, 0.8);
    border-top: 1px solid var(--border-color);
}

.chat-input-area input {
    flex: 1;
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-family: inherit;
    font-size: 15px;
    outline: none;
    background: #fff;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
    min-width: 0;
}

.chat-input-area input:focus {
    border-color: var(--btn-bg);
}

.chat-input-area button {
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 15px;
    margin: 0;
}

/* ================= 分享按钮样式 ================= */
.share-hint {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    margin-top: 15px;
}

.share-hint button {
    padding: 8px 20px;
    font-size: 15px;
    letter-spacing: 1px;
}

/* ================= 移动端适配 ================= */
@media (max-width: 900px) and (orientation: portrait) {
    .bowl-container {
        display: none !important;
    }

    .game-layout {
        flex-direction: column;
        gap: 0;
    }
}

@media (orientation: landscape) and (max-height: 600px) {
    .wood-bowl {
        width: 70px;
        height: 70px;
    }

    .stone-pile {
        width: 75px;
        height: 75px;
        transform: scale(0.62);
        transform-origin: center;
    }

    .bowl-label {
        font-size: 13px;
    }

    #bowl-black {
        margin-bottom: 15px;
        margin-top: 0;
    }

    #bowl-white {
        margin-top: 15px;
        margin-bottom: 0;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 25px 20px;
        border-radius: 8px;
    }

    h1 {
        font-size: 24px;
    }

    .info-box {
        font-size: 18px;
    }

    .radio-btn {
        padding: 8px 14px;
        font-size: 15px;
    }

    #chat-widget {
        right: 15px;
        bottom: 15px;
    }

    .chat-panel {
        width: 280px;
        bottom: 70px;
    }

    .chat-messages {
        height: 200px;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .chat-panel {
        bottom: 60px;
    }

    .chat-messages {
        height: 150px;
    }

    .chat-toggle-btn {
        width: 50px;
        height: 50px;
    }
}