:root {
    --bg: #0a0e1a;
    --bg-soft: #111830;
    --panel: rgba(20, 27, 48, 0.72);
    --panel-border: rgba(148, 163, 184, 0.16);
    --text: #e8eefc;
    --text-dim: #93a0bd;
    --accent: #22d3ee;
    --accent-2: #a855f7;
    --radius: 16px;
    --font: "SF Pro Display", -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
    --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

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

html,
body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 22px 18px 18px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

/* 背景光晕 */
.aurora {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
            radial-gradient(900px 520px at 18% -8%, rgba(34, 211, 238, 0.16), transparent 62%),
            radial-gradient(760px 480px at 88% 8%, rgba(168, 85, 247, 0.16), transparent 60%),
            radial-gradient(760px 620px at 50% 108%, rgba(59, 130, 246, 0.14), transparent 62%);
    z-index: 0;
}

.aurora::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: linear-gradient(rgba(148, 163, 184, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.055) 1px, transparent 1px);
    background-size: 46px 46px;
    mask-image: radial-gradient(circle at 50% 40%, #000 30%, transparent 78%);
    -webkit-mask-image: radial-gradient(circle at 50% 40%, #000 30%, transparent 78%);
}

.app {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1060px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ------------- 顶栏 ------------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 3px;
    transform: rotate(-8deg);
}

.brand-mark i {
    border-radius: 4px;
    background: linear-gradient(150deg, #67e8f9, #0891b2);
    box-shadow: 0 0 14px rgba(34, 211, 238, 0.45);
}

.brand-mark i:nth-child(2) {
    background: linear-gradient(150deg, #d8b4fe, #9333ea);
    box-shadow: 0 0 14px rgba(168, 85, 247, 0.45);
}

.brand-mark i:nth-child(3) {
    background: linear-gradient(150deg, #fde68a, #f59e0b);
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.4);
}

.brand-mark i:nth-child(4) {
    background: linear-gradient(150deg, #86efac, #16a34a);
    box-shadow: 0 0 14px rgba(34, 197, 94, 0.4);
}

.brand-text h1 {
    font-size: 22px;
    letter-spacing: 0.34em;
    font-weight: 800;
    line-height: 1.1;
    background: linear-gradient(96deg, #e0f2fe, #a5b4fc 55%, #e9d5ff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand-text p {
    font-size: 11.5px;
    color: var(--text-dim);
    letter-spacing: 0.12em;
    margin-top: 3px;
}

.tools {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: var(--panel);
    color: var(--text-dim);
    font-size: 14px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.18s ease;
    display: grid;
    place-items: center;
    font-family: var(--font);
}

.icon-btn:hover {
    color: var(--text);
    border-color: rgba(34, 211, 238, 0.45);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.08);
}

.icon-btn.off {
    opacity: 0.4;
}

/* ------------- 主舞台 ------------- */
.stage {
    display: grid;
    grid-template-columns: 178px minmax(0, 1fr) 204px;
    gap: 16px;
    align-items: start;
}

.side {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 12px;
    backdrop-filter: blur(12px);
    box-shadow: 0 16px 38px rgba(2, 6, 23, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.045);
}

.card-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--text-dim);
    margin-bottom: 10px;
    text-transform: uppercase;
}

.card-title em {
    font-style: normal;
    font-size: 9.5px;
    letter-spacing: 0.06em;
    color: rgba(148, 163, 184, 0.68);
}

.preview {
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(9, 14, 28, 0.9), rgba(12, 18, 34, 0.72));
    border: 1px solid rgba(148, 163, 184, 0.1);
    display: grid;
    place-items: center;
    overflow: hidden;
}

.preview-hold {
    height: 92px;
}

.preview-next {
    height: 262px;
}

.preview canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* 统计 */
.card-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat span {
    font-size: 10.5px;
    letter-spacing: 0.1em;
    color: var(--text-dim);
}

.stat b {
    font-family: var(--mono);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.stat-main b {
    font-size: 32px;
    line-height: 1.05;
    letter-spacing: -0.02em;
    background: linear-gradient(100deg, #a5f3fc, #c4b5fd);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-variant-numeric: tabular-nums;
}

.stat-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    padding-top: 10px;
    border-top: 1px dashed rgba(148, 163, 184, 0.16);
}

.stat b.bump {
    animation: bump 0.32s ease;
}

@keyframes bump {
    0% { transform: scale(1); }
    40% { transform: scale(1.16); color: #fff; }
    100% { transform: scale(1); }
}

/* 棋盘 */
.board-area {
    display: flex;
    justify-content: center;
}

.board-frame {
    position: relative;
    /* 老浏览器兜底：显式宽高，不依赖 aspect-ratio / min() */
    height: 620px;
    width: 310px;
    height: min(70vh, 620px);
    width: min(35vh, 310px);
    max-width: 100%;
    border-radius: 18px;
    padding: 8px;
    background: linear-gradient(180deg, rgba(148, 163, 184, 0.2), rgba(148, 163, 184, 0.05));
    box-shadow:
            0 30px 70px rgba(2, 6, 23, 0.65),
            0 0 0 1px rgba(148, 163, 184, 0.12),
            inset 0 1px 0 rgba(255, 255, 255, 0.09);
}

#boardCanvas {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    background: radial-gradient(120% 90% at 50% 0%, #101a30 0%, #080d18 70%);
}

/* 遮罩层 */
.overlay {
    position: absolute;
    /* 老浏览器不支持 inset，补上四向定位 */
    top: 8px;
    right: 8px;
    bottom: 8px;
    left: 8px;
    inset: 8px;
    border-radius: 12px;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    padding: 22px 18px;
    background: rgba(6, 11, 22, 0.78);
    backdrop-filter: blur(7px);
    animation: fade 0.22s ease;
}

.overlay.show {
    display: flex;
}

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

.overlay h2 {
    font-size: 25px;
    letter-spacing: 0.12em;
    font-weight: 800;
    background: linear-gradient(100deg, #a5f3fc, #d8b4fe);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.overlay p {
    font-size: 12.5px;
    line-height: 1.75;
    color: var(--text-dim);
    max-width: 240px;
}

.overlay .big-score {
    font-family: var(--mono);
    font-size: 40px;
    font-weight: 700;
    color: #f0f9ff;
    line-height: 1;
    letter-spacing: -0.02em;
}

.overlay .sub-score {
    font-size: 11.5px;
    color: var(--text-dim);
    letter-spacing: 0.06em;
}

.btn {
    border: 0;
    cursor: pointer;
    font-family: var(--font);
    font-size: 13.5px;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 12px 26px;
    border-radius: 12px;
    color: #04121a;
    background: linear-gradient(120deg, #67e8f9, #22d3ee 55%, #38bdf8);
    box-shadow: 0 10px 26px rgba(34, 211, 238, 0.3);
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 30px rgba(34, 211, 238, 0.4);
}

.btn:active {
    transform: translateY(0) scale(0.985);
}

.btn-ghost {
    background: rgba(148, 163, 184, 0.12);
    color: var(--text);
    box-shadow: none;
    border: 1px solid var(--panel-border);
    padding: 10px 18px;
    font-size: 12px;
}

.btn-ghost:hover {
    box-shadow: none;
    border-color: rgba(148, 163, 184, 0.4);
}

.name-input {
    width: 100%;
    max-width: 210px;
    background: rgba(8, 13, 24, 0.9);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    padding: 10px 12px;
    text-align: center;
    outline: none;
    transition: border-color 0.18s ease;
}

.name-input:focus {
    border-color: rgba(34, 211, 238, 0.6);
}

.overlay-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.rank-tag {
    font-size: 11.5px;
    color: #67e8f9;
    letter-spacing: 0.05em;
    min-height: 16px;
}

/* 等级提示浮字 */
.flash-note {
    position: absolute;
    left: 50%;
    top: 38%;
    transform: translate(-50%, -50%);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.28em;
    color: #a5f3fc;
    text-shadow: 0 0 18px rgba(34, 211, 238, 0.85);
    pointer-events: none;
    animation: levelPop 0.9s ease forwards;
    z-index: 3;
}

@keyframes levelPop {
    0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
    25% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
    100% { opacity: 0; transform: translate(-50%, -95%) scale(1); }
}

/* 排行榜 */
.card-rank {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 180px;
}

.rank-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow-y: auto;
    max-height: 214px;
    padding-right: 2px;
    font-size: 12px;
}

.rank-list::-webkit-scrollbar {
    width: 4px;
}

.rank-list::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 3px;
}

.rank-list li {
    display: grid;
    grid-template-columns: 18px 1fr auto;
    gap: 7px;
    align-items: center;
    padding: 6px 7px;
    border-radius: 8px;
    background: rgba(148, 163, 184, 0.055);
    border: 1px solid transparent;
}

.rank-list li .idx {
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--text-dim);
}

.rank-list li .who {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #dbeafe;
}

.rank-list li .val {
    font-family: var(--mono);
    font-size: 11.5px;
    color: #a5f3fc;
    font-variant-numeric: tabular-nums;
}

.rank-list li.top1 {
    background: rgba(250, 204, 21, 0.1);
    border-color: rgba(250, 204, 21, 0.28);
}

.rank-list li.top1 .val {
    color: #fde68a;
}

.rank-list li.me {
    border-color: rgba(34, 211, 238, 0.45);
    background: rgba(34, 211, 238, 0.09);
}

.rank-empty {
    display: block !important;
    text-align: center;
    color: var(--text-dim);
    font-size: 11.5px;
    background: none !important;
    padding: 14px 0 !important;
}

/* 触屏 */
.touchpad {
    display: none;
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
}

.touchpad button {
    border: 1px solid var(--panel-border);
    background: var(--panel);
    color: var(--text);
    font-size: 17px;
    font-family: var(--font);
    border-radius: 13px;
    padding: 13px 0;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.touchpad button:active {
    background: rgba(34, 211, 238, 0.18);
    border-color: rgba(34, 211, 238, 0.5);
}

.touchpad button.wide {
    grid-column: span 3;
    font-size: 13px;
    letter-spacing: 0.14em;
    color: #a5f3fc;
}

.hint {
    text-align: center;
    font-size: 11px;
    color: rgba(148, 163, 184, 0.75);
    letter-spacing: 0.04em;
    line-height: 2;
}

.hint kbd {
    font-family: var(--mono);
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 5px;
    background: rgba(148, 163, 184, 0.13);
    border: 1px solid rgba(148, 163, 184, 0.2);
    margin: 0 1px;
}

/* ------------- 响应式 ------------- */
@media (max-width: 900px) {
    body {
        padding: 14px 12px 16px;
    }

    .stage {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
                "board board"
                "left right";
        gap: 12px;
    }

    .side-left {
        grid-area: left;
    }

    .side-right {
        grid-area: right;
    }

    .board-area {
        grid-area: board;
    }

    .board-frame {
        height: 520px;
        width: 260px;
        height: min(58vh, 520px);
        width: min(29vh, 260px);
    }

    .preview-next {
        height: 110px;
    }

    .card-rank {
        min-height: 0;
    }

    .rank-list {
        max-height: 132px;
    }

    .touchpad {
        display: grid;
    }

    .hint {
        display: none;
    }
}

@media (max-width: 560px) {
    .brand-text h1 {
        font-size: 18px;
    }

    .brand-text p {
        display: none;
    }

    .board-frame {
        height: 460px;
        width: 230px;
        height: min(54vh, 460px);
        width: min(27vh, 230px);
    }

    .stat-main b {
        font-size: 26px;
    }

    .preview-hold {
        height: 74px;
    }

    .preview-next {
        height: 92px;
    }

    .card {
        padding: 10px;
    }

    .rank-list {
        max-height: 112px;
    }
}

@media (max-height: 720px) and (min-width: 901px) {
    .board-frame {
        height: 560px;
        width: 280px;
        height: min(74vh, 560px);
        width: min(37vh, 280px);
    }

    .preview-next {
        height: 214px;
    }
}
