/* 基础重置 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f4f7f9;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    text-align: center;
}

h1, h2, h3 {
    color: #1a365d;
    margin-bottom: 20px;
}

.ui-credit {
    font-size: 14px;
    color: #718096;
    margin-bottom: 20px;
}

.ui-credit a {
    color: #2d8cf0;
    text-decoration: none;
}

.ui-credit a:hover {
    text-decoration: underline;
}

/* 卡片样式 */
.card {
    background: #fff;
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.centered-card {
    max-width: 400px;
    margin: 40px auto;
}

/* 翻转卡片登录样式 */
.wrapper {
    --input-focus: #2d8cf0;
    --font-color: #323232;
    --font-color-sub: #666;
    --bg-color: #fff;
    --bg-color-alt: #666;
    --main-color: #323232;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.switch {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 30px;
    margin-bottom: 20px;
}

.switch-label {
    display: flex;
    align-items: center;
    gap: 20px;
    font-weight: 600;
    color: var(--font-color);
}

.switch-label span {
    transition: all 0.3s;
}

#toggle:checked ~ .switch-label .login-text {
    text-decoration: underline;
}

#toggle:checked ~ .switch-label .register-text {
    text-decoration: none;
}

#toggle:not(:checked) ~ .switch-label .login-text {
    text-decoration: none;
}

#toggle:not(:checked) ~ .switch-label .register-text {
    text-decoration: underline;
}

.toggle-label {
    height: 60px;
    width: 120px;
    background-color: #ffffff;
    border-radius: 30px;
    -webkit-box-shadow: inset 0 0 5px 4px rgba(255, 255, 255, 1),
        inset 0 0 20px 1px rgba(0, 0, 0, 0.488), 10px 20px 30px rgba(0, 0, 0, 0.096),
        inset 0 0 0 3px rgba(0, 0, 0, 0.3);
    box-shadow: inset 0 0 5px 4px rgba(255, 255, 255, 1),
        inset 0 0 20px 1px rgba(0, 0, 0, 0.488), 10px 20px 30px rgba(0, 0, 0, 0.096),
        inset 0 0 0 3px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: transform 0.4s;
}

.toggle-label:hover {
    transform: perspective(100px) rotateX(5deg) rotateY(-5deg);
}

#toggle:checked ~ .toggle-label:hover {
    transform: perspective(100px) rotateX(-5deg) rotateY(5deg);
}

#toggle {
    display: none;
}

#toggle:checked ~ .toggle-label::before {
    left: 70px;
    background-color: #000000;
    background-image: linear-gradient(315deg, #000000 0%, #414141 70%);
    transition: 0.4s;
}

.toggle-label::before {
    position: absolute;
    content: "";
    height: 40px;
    width: 40px;
    border-radius: 50%;
    background-color: #000000;
    background-image: linear-gradient(
        130deg,
        #757272 10%,
        #ffffff 11%,
        #726f6f 62%
    );
    left: 10px;
    -webkit-box-shadow: 0 2px 1px rgba(0, 0, 0, 0.3),
        10px 10px 10px rgba(0, 0, 0, 0.3);
    box-shadow: 0 2px 1px rgba(0, 0, 0, 0.3), 10px 10px 10px rgba(0, 0, 0, 0.3);
    transition: 0.4s;
}

.flip-card__inner {
    width: 300px;
    height: 350px;
    position: relative;
    background-color: transparent;
    perspective: 1000px;
    text-align: center;
    transition: transform 0.8s;
    transform-style: preserve-3d;
}

#toggle:checked ~ .flip-card__inner {
    transform: rotateY(180deg);
}

#toggle:checked ~ .flip-card__front {
    box-shadow: none;
}

.flip-card__front, .flip-card__back {
    padding: 20px;
    position: absolute;
    display: flex;
    flex-direction: column;
    justify-content: center;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    background: lightgrey;
    gap: 20px;
    border-radius: 5px;
    border: 2px solid var(--main-color);
    box-shadow: 4px 4px var(--main-color);
}

.flip-card__front {
    width: 100%;
}

.flip-card__back {
    width: 100%;
    transform: rotateY(180deg);
}

.flip-card__form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.flip-card__title {
    margin: 20px 0 20px 0;
    font-size: 25px;
    font-weight: 900;
    text-align: center;
    color: var(--main-color);
}

.flip-card__input {
    width: 250px;
    height: 40px;
    border-radius: 5px;
    border: 2px solid var(--main-color);
    background-color: var(--bg-color);
    box-shadow: 4px 4px var(--main-color);
    font-size: 15px;
    font-weight: 600;
    color: var(--font-color);
    padding: 5px 10px;
    outline: none;
}

.flip-card__input::placeholder {
    color: var(--font-color-sub);
    opacity: 0.8;
}

.flip-card__input:focus {
    border: 2px solid var(--input-focus);
}

.flip-card__btn {
    margin: 20px 0 20px 0;
    width: 120px;
    height: 40px;
    border-radius: 5px;
    border: 2px solid var(--main-color);
    background-color: var(--bg-color);
    box-shadow: 4px 4px var(--main-color);
    font-size: 17px;
    font-weight: 600;
    color: var(--font-color);
    cursor: pointer;
    transition: all 0.1s;
}

.flip-card__btn:active {
    box-shadow: 0px 0px var(--main-color);
    transform: translate(3px, 3px);
}

/* 表单与输入框 */
.form-group {
    margin-bottom: 15px;
}

input[type="text"], input[type="password"] {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
    transition: border-color 0.3s;
}

input[type="text"]:focus, input[type="password"]:focus {
    border-color: #3182ce;
    outline: none;
}

/* 按钮样式 */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.1s;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn.primary {
    background-color: #3182ce;
    color: #fff;
}

.btn.primary:hover:not(:disabled) {
    background-color: #2b6cb0;
}

.btn.secondary {
    background-color: #e2e8f0;
    color: #2d3748;
}

.btn.secondary:hover:not(:disabled) {
    background-color: #cbd5e0;
}

.btn.danger {
    background-color: #e53e3e;
    color: #fff;
}

.btn.danger:hover:not(:disabled) {
    background-color: #c53030;
}

.btn.warning {
    background-color: #ed8936;
    color: #fff;
}

.btn.warning:hover:not(:disabled) {
    background-color: #dd6b20;
}

.btn.small {
    padding: 6px 12px;
    font-size: 14px;
}

.btn.large {
    padding: 15px 30px;
    font-size: 18px;
}

.button-group {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.button-with-icon {
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #0f988e;
    font-family: "Istok Web", sans-serif;
    letter-spacing: 1px;
    padding: 0 12px;
    text-align: center;
    width: 120px;
    height: 40px;
    font-size: 14px;
    text-transform: uppercase;
    font-weight: normal;
    border-radius: 3px;
    outline: none;
    user-select: none;
    cursor: pointer;
    transform: translateY(0px);
    position: relative;
    box-shadow:
        inset 0 30px 30px -15px rgba(255, 255, 255, 0.1),
        inset 0 0 0 1px rgba(255, 255, 255, 0.3),
        inset 0 1px 20px rgba(0, 0, 0, 0),
        0 3px 0 #0f988e,
        0 3px 2px rgba(0, 0, 0, 0.2),
        0 5px 10px rgba(0, 0, 0, 0.1),
        0 10px 20px rgba(0, 0, 0, 0.1);
    background: #15ccbe;
    color: white;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
    transition: 150ms all ease-in-out;
}

.button-with-icon .icon {
    margin-right: 8px;
    width: 24px;
    height: 24px;
    transition: all 0.5s ease-in-out;
}

.button-with-icon:active {
    transform: translateY(3px);
    box-shadow:
        inset 0 16px 2px -15px rgba(0, 0, 0, 0),
        inset 0 0 0 1px rgba(255, 255, 255, 0.15),
        inset 0 1px 20px rgba(0, 0, 0, 0.1),
        0 0 0 #0f988e,
        0 0 0 2px rgba(255, 255, 255, 0.5),
        0 0 0 rgba(0, 0, 0, 0),
        0 0 0 rgba(0, 0, 0, 0);
}

.button-with-icon:hover .text {
    transform: translateX(80px);
}

.button-with-icon:hover .icon {
    transform: translate(23px);
}

.button-with-icon .text {
    transition: all 0.5s ease-in-out;
}

.button-with-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.button-with-icon:disabled:hover .text {
    transform: none;
}

.button-with-icon:disabled:hover .icon {
    transform: none;
}

/* 消息提示 */
.message {
    margin-top: 15px;
    font-size: 14px;
    min-height: 20px;
}

.text-success { color: #38a169; }
.text-error { color: #e53e3e; }
.text-info { color: #3182ce; }

/* 隐藏元素 */
.hidden {
    display: none !important;
}

/* 主菜单布局 */
.user-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid #edf2f7;
}

.user-profile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.user-stats {
    font-size: 12px;
    color: #718096;
    margin-top: 4px;
    background: #edf2f7;
    padding: 2px 8px;
    border-radius: 12px;
}

.menu-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    margin-bottom: 30px;
}

.action-card {
    flex: 1;
    min-width: 200px;
    background: #f7fafc;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.join-input-group {
    display: flex;
    gap: 10px;
}

.leaderboard-entry {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #edf2f7;
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    padding: 30px;
    border-radius: 8px;
    text-align: center;
    min-width: 300px;
    box-shadow: 0 10px 15px rgba(0,0,0,0.1);
}

.modal-content p {
    margin-bottom: 20px;
    font-size: 18px;
}

/* 排行榜样式 */
.ranking-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.ranking-table th, .ranking-table td {
    padding: 12px;
    border-bottom: 1px solid #e2e8f0;
    text-align: center;
}

.ranking-table th {
    background-color: #f7fafc;
    color: #4a5568;
    font-weight: 600;
}

.ranking-table tr:nth-child(even) {
    background-color: #fafbfc;
}

/* 社交与聊天样式 (Social & Chat Styles) */
.lobby-social {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #edf2f7;
    text-align: left;
}

.online-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: bold;
    color: #2b6cb0;
    margin-bottom: 15px;
    background: #ebf8ff;
    padding: 5px 15px;
    border-radius: 20px;
}

.status-dot {
    width: 10px;
    height: 10px;
    background-color: #48bb78;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(72, 187, 120, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(72, 187, 120, 0); }
}

.chat-container {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.room-chat-container {
    margin-top: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.room-chat-container h3 {
    margin-top: 0;
    font-size: 16px;
    border-bottom: 1px solid #cbd5e0;
    padding-bottom: 5px;
}

.chat-messages {
    height: 200px;
    overflow-y: auto;
    padding: 15px;
    background: #f7fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg {
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}

.chat-msg .time {
    font-size: 12px;
    color: #a0aec0;
    margin-right: 5px;
}

.chat-msg .user {
    font-weight: bold;
    color: #2b6cb0;
    margin-right: 5px;
}

.chat-msg.self .user {
    color: #38a169;
}

.chat-input-group {
    display: flex;
    border-top: 1px solid #e2e8f0;
}

.chat-input-group input {
    flex: 1;
    border: none;
    border-radius: 0;
    padding: 10px 15px;
}

.chat-input-group input:focus {
    box-shadow: none;
}

.chat-input-group button {
    border-radius: 0;
}

/* 好友系统样式 */
.social-layout {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.friends-panel {
    flex: 1;
    min-width: 250px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.chat-panel {
    flex: 2;
    min-width: 300px;
}

.friends-panel h3 {
    margin-top: 0;
    font-size: 16px;
    border-bottom: 1px solid #cbd5e0;
    padding-bottom: 5px;
    margin-bottom: 15px;
}

.add-friend-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.add-friend-group input {
    flex: 1;
    padding: 8px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
}

.friend-requests {
    background: #fffaf0;
    border: 1px solid #fbd38d;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 15px;
}

.friend-requests h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #dd6b20;
}

.friend-requests ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.friend-requests li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px dashed #fbd38d;
}

.friend-requests li:last-child {
    border-bottom: none;
}

.request-actions button {
    margin-left: 5px;
}

.friends-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
}

.friends-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #edf2f7;
}

.friends-list li:last-child {
    border-bottom: none;
}

.friend-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.friend-name {
    font-weight: bold;
}

.friend-stats {
    font-size: 12px;
    color: #718096;
}

.status-dot.offline {
    background-color: #a0aec0;
    animation: none;
}

.empty-text {
    color: #a0aec0;
    font-size: 14px;
    text-align: center;
    padding: 20px 0;
}

/* 游戏界面特有样式 */
.game-body {
    background-color: #e2e8f0;
}

.game-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

.game-header {
    background: #fff;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.player-info {
    display: flex;
    justify-content: space-around;
    width: 100%;
    max-width: 500px;
    margin: 10px 0;
    align-items: center;
}

.player-card {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    font-size: 18px;
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 14px;
}

.red-avatar { background-color: #e53e3e; }
.black-avatar { background-color: #1a202c; }
.vs { font-weight: bold; color: #a0aec0; }

.status-badge {
    display: inline-block;
    padding: 5px 10px;
    background-color: #ebf8ff;
    color: #2b6cb0;
    border-radius: 4px;
    font-weight: bold;
}

/* Toast 消息提示样式 */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background-color: #333;
    color: #fff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    transform: translateY(-20px);
    animation: toastFadeIn 0.3s forwards;
}

.toast.success {
    background-color: #48bb78;
}

.toast.error {
    background-color: #f56565;
}

.toast.info {
    background-color: #4299e1;
}

.toast.fade-out {
    animation: toastFadeOut 0.3s forwards;
}

@keyframes toastFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastFadeOut {
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

/* Modal 确认框样式 (用于悔棋等需要确认的操作) */
.custom-confirm-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.custom-confirm-modal.hidden {
    display: none;
}

.custom-confirm-content {
    background-color: white;
    padding: 20px 30px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.custom-confirm-buttons {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 15px;
}

.custom-confirm-buttons button {
    width: auto;
    padding: 8px 20px;
}

.game-main {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.chessboard-wrapper {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    background-color: #f6d699; /* 棋盘木纹底色 */
    border: 2px solid #5c3a21;
    border-radius: 4px;
    cursor: pointer;
}

.game-sidebar {
    flex: 1;
    min-width: 250px;
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.move-history {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 10px;
    overflow-y: auto;
    max-height: 350px;
    background: #f7fafc;
    text-align: left;
}

.move-history h3 {
    margin-top: 0;
    font-size: 16px;
    border-bottom: 1px solid #cbd5e0;
    padding-bottom: 5px;
}

#history-list {
    list-style: none;
    padding: 0;
}

#history-list li {
    padding: 5px 0;
    border-bottom: 1px dashed #e2e8f0;
    font-size: 14px;
}

/* 响应式适配 */
@media (max-width: 768px) {
    .game-main {
        flex-direction: column;
    }
    .chessboard-wrapper {
        padding: 10px;
    }
    canvas {
        width: 100%;
        max-width: 450px;
        height: auto;
    }
}