/* --- 基础变量与主题 --- */
:root {
    --green: #6aaa64;
    --yellow: #c9b458;
    --gray: #787c7e;
    --border-empty: #d3d6da;
    --border-filled: #878a8c;
    --bg: #ffffff;
    --text: #000000;
    --text-muted: #787c7e;
    --key-bg: #d3d6da;
    --key-text: #000000;
    --tile-text: #ffffff;
    --header-border: #d3d6da;
    --tile-size: 62px;
}

body.dark-mode {
    --green: #538d4e;
    --yellow: #b59f3b;
    --gray: #3a3a3c;
    --border-empty: #3a3a3c;
    --border-filled: #565758;
    --bg: #121213;
    --text: #ffffff;
    --text-muted: #818384;
    --key-bg: #818384;
    --key-text: #ffffff;
    --header-border: #3a3a3c;
}

body.high-contrast {
    --green: #f5793a;
    --yellow: #85c0f9;
}

/* --- 基础布局 --- */
body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Libre Franklin', sans-serif;
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

header {
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid var(--header-border);
    font-family: 'Roboto Slab', serif;
    font-size: 32px;
    font-weight: 700;
    position: relative;
    z-index: 30;
    flex-shrink: 0;
}

.header-controls {
    position: absolute;
    left: 10px;
    display: flex;
    gap: 5px;
}

.header-logo {
    width: 32px;
    height: 32px;
    margin: 0 5px 0 12px;
}

.header-title {
    margin: 0 12px 0 0;
}

@media (max-width: 600px) {
    .header-title {
        display: none;
    }
}

.header-settings {
    position: absolute;
    right: 10px;
    display: flex;
}

#loading {
    position: absolute;
    margin: 0;
    line-height: 100vh;
    place-self: center;
    font-weight: 700;
}

/* --- 通用组件 --- */
.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    border-radius: 4px;
    transition: background-color 0.2s;
    outline: none;
    fill: var(--text);
}

.icon-btn:hover {
    background-color: rgba(120, 120, 120, 0.1);
}

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

/* 键盘 */
.key {
    background-color: var(--key-bg);
    border: 0;
    border-radius: 4px;
    height: 58px;
    width: 43px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 20px;
    cursor: pointer;
    color: var(--key-text);
    text-transform: uppercase;
}

.key.wide {
    width: 65px;
    font-size: 12px;
}

/* 弹窗/模态框 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
    animation: fadeIn 0.2s ease-out;
    opacity: 1;
    transition: opacity 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#settings-modal .modal-content {
    max-width: 400px;
}

.modal-content {
    background-color: var(--bg);
    color: var(--text);
    padding: 32px;
    border-radius: 8px;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 4px 23px rgba(0, 0, 0, 0.2);
    animation: modalPop 0.2s ease-out;
    text-align: center;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

@keyframes modalPop {
    from {
        transform: scale(0.85);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-overlay.closing {
    opacity: 0;
    pointer-events: none;
    /* 动画时禁止点击 */
}

.modal-overlay.closing .modal-content {
    transform: scale(0.9);
    /* 消失时轻微缩小 */
    opacity: 0;
}



/* 设置面板专用样式 */
.settings-content {
    max-width: 480px;
    padding: 16px 32px;
    text-align: left;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.settings-header h2 {
    margin: 0;
    font-size: 16px;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid var(--header-border);
}

.setting-text {
    display: flex;
    flex-direction: column;
}

.setting-label {
    font-size: 18px;
}

.setting-desc {
    font-size: 12px;
    color: var(--text-muted);
}

/* Switch 开关样式 */
.switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gray);
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--green);
}

input:checked+.slider:before {
    transform: translateX(12px);
}

/* Toast */
#toast-container {
    position: fixed;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

.toast {
    background-color: var(--text);
    color: var(--bg);
    padding: 12px 18px;
    border-radius: 4px;
    font-weight: 700;
    margin-bottom: 10px;
    transition: opacity 0.4s;
    overflow: hidden;
}

.toast.hide {
    opacity: 0;
    transform: translateY(-20px);
    max-height: 0;
    margin-bottom: 0;
    padding: 0;
}

.toast-green {
    color: var(--green);
    /* 增加亮度，防止在黑色背景下看不清 */
    filter: brightness(1.2);
    font-weight: 900;
}

.toast-yellow {
    color: var(--yellow);
    filter: brightness(1.2);
    font-weight: 900;
}

/* 高对比度模式适配 */
body.high-contrast .toast-green {
    color: var(--green);
}

body.high-contrast .toast-yellow {
    color: var(--yellow);
}

/* --- 每一行的基础容器 --- */
.board-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    position: relative;
    /* 必须：作为 X 按钮的定位基准 */
    width: fit-content;
    margin: 0 auto 5px;
}

/* --- 清除整行按钮：公共样式 --- */
/* 清除按钮相对于 .board-row 定位 */
.clear-row-btn {
    position: absolute;
    /* 核心逻辑：无论行多宽，按钮都固定在行末尾右侧 50px 处 */
    right: -55px;
    left: auto !important;

    display: flex !important;
    /* 确保不是 display:none */
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    fill: var(--text-muted);
    border-radius: 4px;

    /* 初始状态 */
    opacity: 0 !important;
    pointer-events: none;
    transition: opacity 0.2s ease, fill 0.2s ease;
    z-index: 100;
    /* 确保在最上层 */
}

/* 强制显示类 */
.clear-row-btn.visible {
    opacity: 1 !important;
    pointer-events: auto !important;
}

.clear-row-btn:hover {
    fill: var(--text);
    background-color: rgba(120, 120, 120, 0.1);
}

/* --- 核心动画 --- */
.pop {
    animation: pop 0.1s ease-in-out;
}

@keyframes pop {
    50% {
        transform: scale(1.1);
    }
}

.flip {
    animation: flip 0.5s ease-in forwards;
}

@keyframes flip {
    50% {
        transform: rotateX(90deg);
    }
}

.bounce {
    animation: bounce 1000ms ease-in-out;
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-30px);
    }

    60% {
        transform: translateY(-15px);
    }
}

.shake {
    animation: shake 600ms ease-in-out;
}

@keyframes shake {

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-4px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(4px);
    }
}