:root {
    --paper: #f3f2e9;
    --paper-deep: #e9ebe0;
    --ink: #26312b;
    --ink-soft: #627168;
    --line: #cbd2c6;
    --green: #496b57;
    --green-dark: #355443;
    --green-pale: #dce8dd;
    --wood: #d1b778;
    --wood-dark: #8d7547;
    --danger: #a64e43;
    --white: #fffef8;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
    margin: 0;
    color: var(--ink);
    background: var(--paper) url('/static/images/rice-paper-texture.png') center / 720px repeat fixed;
    font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    letter-spacing: 0;
}
body.dark-mode {
    --paper: #202923;
    --paper-deep: #29342c;
    --ink: #e2ebe2;
    --ink-soft: #adbcaf;
    --line: #46564a;
    --green: #709a7a;
    --green-dark: #9dc1a4;
    --green-pale: #314337;
    --wood: #ad8e59;
    --wood-dark: #725c38;
    --danger: #d28074;
    --white: #f4f6ef;
    background: #1b231e;
}
body.dark-mode .login-page { background: #1b231e; }
body.dark-mode .login-scene,
body.dark-mode .lobby-hero { background-color: #19211b; background-blend-mode: multiply; }
body.dark-mode .app-header { border-color: #3d4b40; background: rgba(27,36,30,.96); }
body.dark-mode .login-panel,
body.dark-mode .mode-list,
body.dark-mode .game-table { background: rgba(34,45,38,.88); }
body.dark-mode .form-control,
body.dark-mode .secondary-command,
body.dark-mode .segmented button,
body.dark-mode .replay-controls button { border-color: #536357; color: var(--ink); background: rgba(47,61,51,.88); }
body.dark-mode .secondary-command:hover { background: #394b3e; }
body.dark-mode .main-nav a,
body.dark-mode .form-label { color: #c9d5ca; }
body.dark-mode .game-table td { border-color: #46564a; }

button, input { letter-spacing: 0; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.brand-kicker {
    margin: 0 0 8px;
    color: var(--green);
    font-size: 13px;
    font-weight: 700;
}

.primary-command,
.secondary-command,
.danger-command {
    min-height: 44px;
    border-radius: 5px;
    padding: 10px 20px;
    font-weight: 700;
}

.primary-command {
    border: 1px solid var(--green);
    color: #fff;
    background: var(--green);
}
.primary-command:hover,
.primary-command:focus { color: #fff; background: var(--green-dark); border-color: var(--green-dark); }
.primary-command:disabled { background: #91a296; border-color: #91a296; }

.secondary-command { border: 1px solid #9eaa9f; color: var(--ink); background: rgba(255,255,255,.72); }
.secondary-command:hover { border-color: var(--green); color: var(--green-dark); background: #fff; }
.danger-command { border: 1px solid #c6a09b; color: var(--danger); background: transparent; }
.danger-command:hover { color: #fff; background: var(--danger); border-color: var(--danger); }

.form-control {
    min-height: 44px;
    border-radius: 4px;
    border-color: #bcc7bd;
    color: var(--ink);
    background: rgba(255,255,255,.82);
}
.form-control:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(73,107,87,.14); }

/* Login */
.login-page { min-height: 100vh; background: #edefe6; }
.login-scene {
    position: relative;
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: space-between;
    gap: 48px;
    padding: 7vh max(6vw, 32px);
    background: url('/static/images/ink-gobang-hero.png') center / cover no-repeat fixed;
}
.login-copy { max-width: 600px; align-self: flex-start; margin-top: 12vh; }
.login-copy h1 { margin: 0; font-family: "STKaiti", "KaiTi", serif; font-size: 54px; font-weight: 600; }
.login-copy > p:last-child { max-width: 460px; margin: 18px 0 0; color: #59665e; font-size: 17px; line-height: 1.8; }
.login-panel {
    width: min(100%, 380px);
    margin-right: 6vw;
    padding: 32px;
    border: 1px solid rgba(93,112,99,.32);
    border-radius: 7px;
    background: rgba(250,250,244,.9);
    box-shadow: 0 16px 48px rgba(37,51,43,.12);
    backdrop-filter: blur(7px);
}
.login-mark { width: 52px; height: 52px; margin-bottom: 18px; border-radius: 50%; background: url('/static/images/ink-stones-mark.png') center 48% / 185% no-repeat; }
.login-panel h2 { margin: 0; font: 600 26px/1.3 "STKaiti", "KaiTi", serif; }
.login-subtitle { margin: 7px 0 24px; color: var(--ink-soft); font-size: 14px; }
.form-label { color: #46534b; font-size: 14px; font-weight: 600; }
.form-error { margin: -2px 0 14px; color: var(--danger); font-size: 13px; }

/* Shell */
.app-header {
    position: sticky;
    z-index: 50;
    top: 0;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
    min-height: 68px;
    align-items: center;
    padding: 0 max(3vw, 20px);
    border-bottom: 1px solid rgba(79,100,86,.2);
    background: rgba(246,246,239,.94);
    backdrop-filter: blur(10px);
}
.brand { display: inline-flex; width: max-content; align-items: center; gap: 11px; }
.brand-stones { position: relative; display: block; width: 36px; height: 28px; }
.brand-stones i, .brand-stones b { position: absolute; width: 23px; height: 23px; border-radius: 50%; box-shadow: 0 2px 4px rgba(20,25,22,.24); }
.brand-stones i { left: 0; top: 0; background: #202522; }
.brand-stones b { right: 0; bottom: 0; border: 1px solid #d8d8cf; background: #fffef7; }
.brand > span:last-child { display: flex; flex-direction: column; }
.brand strong { font: 600 20px/1.1 "STKaiti", "KaiTi", serif; }
.brand small { margin-top: 3px; color: var(--ink-soft); font-size: 10px; }
.main-nav { display: flex; height: 68px; align-items: stretch; gap: 4px; }
.main-nav a { position: relative; display: grid; min-width: 78px; place-items: center; padding: 0 14px; color: #56645b; font-size: 14px; font-weight: 600; }
.main-nav a::after { position: absolute; right: 14px; bottom: 0; left: 14px; height: 2px; content: ''; background: transparent; }
.main-nav a:hover, .main-nav a.active { color: var(--green-dark); }
.main-nav a.active::after { background: var(--green); }
.account-menu { display: flex; min-width: 0; align-items: center; justify-content: flex-end; gap: 9px; }
.account-menu img { width: 38px; height: 38px; flex: 0 0 auto; border: 1px solid #c7cec7; border-radius: 50%; object-fit: cover; background: #e6e8df; }
.account-menu > span { display: flex; min-width: 0; flex-direction: column; }
.account-menu strong { max-width: 110px; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.account-menu small { color: var(--green); font-size: 11px; }
.icon-command { width: 34px; height: 34px; border: 0; color: #68756d; background: transparent; font-size: 22px; line-height: 1; }
.icon-command:hover { color: var(--danger); }
.settings-command { border: 1px solid #aeb9b0; border-radius: 4px; font-size: 19px; }
.settings-command:hover { border-color: var(--green); color: var(--green-dark); background: rgba(73,107,87,.08); }
.logout-command { border: 1px solid #aeb9b0; border-radius: 4px; font-size: 18px; }
.logout-command:hover { border-color: #b3736c; background: rgba(166,78,67,.08); }
.page-width { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }

/* Lobby */
.lobby-hero {
    position: relative;
    display: flex;
    min-height: 410px;
    align-items: center;
    background: url('/static/images/ink-gobang-hero.png') center 52% / cover no-repeat fixed;
}
.hero-content { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 40px 54% 40px 4%; }
.hero-content h1 { margin: 0; font: 600 42px/1.25 "STKaiti", "KaiTi", serif; }
.hero-content > p:not(.brand-kicker) { max-width: 480px; margin: 17px 0 24px; color: #526159; line-height: 1.8; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.lobby-summary { padding: 34px 0 60px; }
.mode-list { display: grid; grid-template-columns: repeat(2, 1fr); border: 1px solid var(--line); background: rgba(248,248,242,.72); }
.mode-card { display: grid; grid-template-columns: 48px 1fr 40px; min-height: 144px; align-items: center; gap: 16px; padding: 24px; }
.mode-card + .mode-card { border-left: 1px solid var(--line); }
.mode-index { align-self: start; color: #8c9c91; font: 500 12px/1.2 ui-monospace, monospace; }
.mode-card h2 { margin: 0 0 8px; font: 600 22px/1.3 "STKaiti", "KaiTi", serif; }
.mode-card p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.7; }
.mode-card > a { display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid #abb7ae; border-radius: 50%; color: var(--green); font-size: 19px; }
.mode-card > a:hover { color: #fff; background: var(--green); border-color: var(--green); }
.stats-strip { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 22px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stats-strip div { padding: 20px 24px; }
.stats-strip div + div { border-left: 1px solid var(--line); }
.stats-strip span { display: block; color: var(--ink-soft); font-size: 12px; }
.stats-strip strong { display: block; margin-top: 5px; font: 600 26px/1.2 Georgia, serif; }

/* Game */
.game-page, .data-page, .replay-page { padding: 36px 0 60px; }
.section-heading { display: flex; min-height: 66px; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.section-heading > div { min-width: 0; }
.section-heading h1 { margin: 0; font: 600 30px/1.25 "STKaiti", "KaiTi", serif; }
#replay-title { overflow-wrap: anywhere; }
.connection-state, .rank-rule { color: var(--ink-soft); font-size: 13px; }
.connection-state::before { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; content: ''; background: #9ca8a0; }
.connection-state.connected::before { background: #4f8a61; }
.match-stage { display: grid; grid-template-columns: minmax(260px, 44%) 1fr; min-height: 470px; align-items: center; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.match-art {
    position: relative;
    width: min(100%, 430px);
    aspect-ratio: 1;
    margin: 0 auto;
}
.match-art::before {
    position: absolute;
    inset: 0;
    content: '';
    pointer-events: none;
    background: url('/static/images/ink-stones-mark.png') center / contain no-repeat;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent), linear-gradient(transparent, #000 22%, #000 78%, transparent);
    -webkit-mask-composite: source-in;
    mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent), linear-gradient(transparent, #000 22%, #000 78%, transparent);
    mask-composite: intersect;
}
.match-copy { padding: 40px min(7vw, 80px); text-align: center; }
.match-copy h2 { margin: 0; font: 600 27px/1.4 "STKaiti", "KaiTi", serif; }
.match-copy p { margin: 12px 0 24px; color: var(--ink-soft); line-height: 1.7; }
.match-current-user { display: flex; width: max-content; max-width: 100%; align-items: center; gap: 9px; margin: -8px auto 22px; text-align: left; }
.match-current-user img { width: 34px; height: 34px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 50%; object-fit: cover; background: var(--paper-deep); }
.match-current-user span { display: flex; min-width: 0; flex-direction: column; }
.match-current-user strong { max-width: 180px; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.match-current-user small { color: var(--ink-soft); font-size: 10px; }
.match-copy .btn { min-width: 150px; }
.match-timer { margin: 12px 0 22px; color: var(--green); }
.match-timer strong { font: 600 54px/1 Georgia, serif; }
.match-timer span { margin-left: 5px; font-size: 13px; }
.game-layout { display: grid; grid-template-columns: minmax(0, 760px) minmax(250px, 1fr); align-items: start; gap: 32px; }
.board-column { min-width: 0; }
.board-shell { display: flex; justify-content: center; }
.gomoku-board {
    position: relative;
    display: grid;
    width: min(100%, 680px);
    aspect-ratio: 1;
    grid-template-columns: repeat(15, 1fr);
    grid-template-rows: repeat(15, 1fr);
    padding: 4.8%;
    border: 1px solid #9d844f;
    border-radius: 4px;
    background: var(--wood);
    box-shadow: 0 9px 24px rgba(55,52,38,.15), inset 0 0 40px rgba(255,249,213,.25);
}
.board-cell { position: relative; z-index: 1; min-width: 0; padding: 0; border: 0; outline-offset: -2px; background: transparent; }
.board-cell::before, .board-cell::after { position: absolute; z-index: -1; content: ''; background: rgba(60,50,31,.72); pointer-events: none; }
.board-cell::before { top: 50%; left: 0; width: 100%; height: 1px; }
.board-cell::after { top: 0; left: 50%; width: 1px; height: 100%; }
.board-cell[data-x="0"]::before { left: 50%; width: 50%; }
.board-cell[data-x="14"]::before { width: 50%; }
.board-cell[data-y="0"]::after { top: 50%; height: 50%; }
.board-cell[data-y="14"]::after { height: 50%; }
.stone { position: absolute; z-index: 2; inset: 8%; display: block; border-radius: 50%; transform: scale(.2); opacity: 0; transition: transform 150ms ease, opacity 150ms ease; }
.board-cell.occupied .stone { transform: scale(1); opacity: 1; }
.board-cell.black .stone { background: #202522; box-shadow: inset 4px 5px 8px rgba(255,255,255,.17), 0 3px 5px rgba(32,30,22,.32); }
.board-cell.white .stone { border: 1px solid #d8d5c8; background: #fffef5; box-shadow: inset -4px -5px 8px rgba(120,115,95,.14), 0 3px 5px rgba(32,30,22,.25); }
.board-cell.star:not(.occupied) .stone { inset: calc(50% - 3px); width: 6px; height: 6px; transform: none; opacity: 1; background: #55482d; }
.board-cell.last .stone::after { position: absolute; top: 50%; left: 50%; width: 7px; height: 7px; border-radius: 50%; content: ''; transform: translate(-50%,-50%); background: #b34e43; }
.board-cell.winning .stone { outline: 3px solid #b34e43; outline-offset: 2px; animation: winning-stone-flash .5s ease-in-out 4; }
@keyframes winning-stone-flash { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.86); opacity: .18; } }
.gomoku-board.disabled .board-cell:not(.occupied) { cursor: default; }
.gomoku-board:not(.disabled) .board-cell:not(.occupied):hover .stone { transform: scale(.55); opacity: .35; background: #26312b; }
.gomoku-board:not(.disabled) .board-cell.star:not(.occupied):hover .stone { inset: 8%; width: auto; height: auto; }
.player-bar { display: flex; min-height: 58px; align-items: center; gap: 10px; padding: 8px 2px; }
.player-bar:last-child { justify-content: flex-end; }
.player-bar img { width: 38px; height: 38px; border: 1px solid #c5cbc3; border-radius: 50%; object-fit: cover; background: #e2e5dc; }
.player-bar .player-copy { display: flex; min-width: 0; flex-direction: column; }
.player-bar strong { max-width: 220px; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.player-bar small { color: var(--ink-soft); font-size: 11px; }
.player-uid { color: var(--ink-soft); font-family: Georgia, serif; }
.player-bar .piece-swatch { margin-left: auto; }
.online-player-row { display: grid; grid-template-columns: minmax(0, 1fr) 56px minmax(0, 1fr); align-items: center; }
.online-player-row .player-bar { min-width: 0; }
.online-player-row #online-self-player { justify-content: flex-start; flex-direction: row-reverse; text-align: right; }
.online-player-row .player-bar .piece-swatch { margin: 0; }
.piece-swatch { display: inline-block; width: 15px; height: 15px; flex: 0 0 auto; margin-right: 6px; border-radius: 50%; vertical-align: -2px; }
.piece-swatch.black { background: #242925; }
.piece-swatch.white { border: 1px solid #bfc2b7; background: #fffef7; }
.game-sidebar { position: sticky; top: 92px; display: flex; min-height: 300px; flex-direction: column; gap: 18px; padding-left: 28px; border-left: 1px solid var(--line); }
.turn-panel { padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.turn-panel > span { display: block; color: var(--ink-soft); font-size: 13px; }
.turn-panel > span.my-turn { color: #07854a; font-weight: 700; }
.turn-panel > span.opponent-turn { color: #c56a00; font-weight: 700; }
.dark-mode .turn-panel > span.my-turn { color: #72e39a; }
.dark-mode .turn-panel > span.opponent-turn { color: #ffc05a; }
.turn-clock { display: block; margin: 6px 0; font: 600 42px/1 Georgia, serif; }
.turn-clock.warning { color: var(--danger); }
.turn-panel small { color: #7c877f; font-size: 11px; }
.chat-panel { display: flex; min-height: 320px; flex: 1; flex-direction: column; }
.chat-panel h2 { margin: 0 0 12px; font-size: 14px; font-weight: 700; }
.chat-messages { height: 245px; overflow-y: auto; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.chat-message { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 12px; animation: chat-in 160ms ease-out; }
.chat-message.mine { flex-direction: row-reverse; }
.chat-avatar { width: 30px; height: 30px; flex: 0 0 auto; border: 1px solid #c5cbc3; border-radius: 50%; object-fit: cover; background: #e2e5dc; }
.chat-message-body { min-width: 0; max-width: calc(100% - 38px); }
.chat-meta { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.chat-message.mine .chat-meta { flex-direction: row-reverse; }
.chat-message strong { overflow: hidden; color: var(--green-dark); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.chat-status { flex: 0 0 auto; color: var(--ink-soft); font-size: 10px; }
.chat-bubble { margin: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 5px; background: rgba(255,255,255,.66); overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; }
.chat-message.mine .chat-bubble { background: var(--green-pale); }
.chat-message.pending .chat-bubble { opacity: .7; }
.chat-message.failed .chat-bubble { border-color: var(--danger); }
.chat-message.failed .chat-status { color: var(--danger); }
.dark-mode .chat-bubble { background: rgba(46,59,50,.92); }
.dark-mode .chat-message.mine .chat-bubble { background: var(--green-pale); }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 12px; }
.chat-form .btn { min-height: 44px; padding-right: 15px; padding-left: 15px; }

@keyframes chat-in { from { opacity: 0; transform: translateY(5px); } }

.online-result { display: flex; min-height: 610px; flex-direction: column; align-items: center; justify-content: center; padding: 42px 20px 54px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); animation: settlement-in 260ms ease-out; }
.settlement-heading { text-align: center; }
.settlement-heading h2 { margin: 0; font: 600 36px/1.25 "STKaiti", "KaiTi", serif; }
.online-result.win .settlement-heading h2 { color: var(--green-dark); }
.online-result.loss .settlement-heading h2 { color: var(--danger); }
.settlement-heading > p:last-child { margin: 9px 0 0; color: var(--ink-soft); font-size: 13px; }
.settlement-versus { display: grid; width: min(100%, 680px); min-height: 180px; grid-template-columns: minmax(0, 1fr) 90px minmax(0, 1fr); align-items: center; margin: 30px 0 24px; }
.settlement-player { display: flex; min-width: 0; align-items: center; flex-direction: column; text-align: center; }
.settlement-player img { width: 112px; height: 112px; border: 3px solid rgba(73,107,87,.28); border-radius: 50%; object-fit: cover; background: var(--paper-deep); box-shadow: 0 10px 28px rgba(34,45,38,.14); transition: filter 220ms ease, opacity 220ms ease; }
.settlement-player.loser img { filter: grayscale(1); opacity: .58; }
.settlement-player strong { max-width: 180px; margin-top: 12px; overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.settlement-player small { margin-top: 4px; color: var(--ink-soft); font-size: 11px; }
.settlement-pk { position: relative; color: var(--ink-soft); font: 700 27px/1 Georgia, serif; text-align: center; }
.settlement-pk::before,
.settlement-pk::after { position: absolute; top: 50%; width: 20px; height: 1px; content: ''; background: var(--line); }
.settlement-pk::before { right: calc(100% + 8px); }
.settlement-pk::after { left: calc(100% + 8px); }
.settlement-stats { display: grid; width: min(100%, 680px); grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.settlement-stats div { padding: 18px 20px; text-align: center; }
.settlement-stats div + div { border-left: 1px solid var(--line); }
.settlement-stats span { display: block; color: var(--ink-soft); font-size: 11px; }
.settlement-stats strong { display: block; margin-top: 6px; font: 600 21px/1.2 Georgia, serif; }
.settlement-actions { display: flex; gap: 10px; margin-top: 28px; }
.settlement-actions .btn { min-width: 132px; }

@keyframes settlement-in { from { opacity: 0; transform: translateY(8px); } }

/* AI, data and replay */
.control-label { display: block; margin-bottom: 8px; color: var(--ink-soft); font-size: 12px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; overflow: hidden; border: 1px solid #aeb9b0; border-radius: 5px; }
.segmented button { min-height: 42px; border: 0; color: #56635b; background: rgba(255,255,255,.5); font-size: 13px; }
.segmented button + button { border-left: 1px solid #aeb9b0; }
.segmented button.active { color: #fff; background: var(--green); }
.ai-status { display: flex; justify-content: space-between; gap: 12px; padding: 15px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 13px; }
.ai-status span { color: var(--ink-soft); }
.table-wrap { overflow-x: auto; border-top: 1px solid #9daaa0; }
.game-table { width: 100%; min-width: 760px; border-collapse: collapse; background: rgba(250,250,245,.55); }
.game-table th { padding: 14px 16px; border-bottom: 1px solid var(--line); color: #748078; font-size: 11px; font-weight: 600; text-align: left; }
.game-table td { padding: 17px 16px; border-bottom: 1px solid #d8ddd5; font-size: 13px; }
.game-table tbody tr:hover { background: rgba(220,232,221,.45); }
.result-win { color: var(--green-dark); font-weight: 700; }
.result-loss { color: var(--danger); font-weight: 700; }
.result-draw { color: #766f58; font-weight: 700; }
.player-cell { display: flex; align-items: center; gap: 9px; }
.player-cell img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.rank-player-copy { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.rank-player-name { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.rank-player-uid { color: var(--ink-soft); font-size: 10px; line-height: 1.2; }
.svip-tag { display: inline-block; margin-left: 6px; padding: 1px 5px; border: 1px solid #9a8251; border-radius: 3px; color: #79632f; font-size: 9px; vertical-align: 1px; }
.text-command { border: 0; color: var(--green); background: transparent; font-size: 13px; font-weight: 700; }
.empty-state { padding: 70px 20px; color: var(--ink-soft); text-align: center; }
.list-pagination { display: flex; min-height: 54px; align-items: center; justify-content: flex-end; gap: 10px; border-bottom: 1px solid var(--line); }
.list-pagination button { display: grid; width: 34px; height: 34px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: rgba(255,255,255,.48); font-size: 22px; line-height: 1; }
.list-pagination button:hover:not(:disabled) { border-color: var(--green); color: #fff; background: var(--green); }
.list-pagination button:disabled { cursor: not-allowed; opacity: .38; }
.list-pagination span { min-width: 150px; color: var(--ink-soft); font-size: 12px; text-align: center; }
.dark-mode .list-pagination button { background: rgba(47,61,51,.88); }
.rank-table tbody tr:first-child td { background: rgba(209,183,120,.16); }
.rank-number { font: 600 18px/1 Georgia, serif; }
.replay-player-row { display: grid; grid-template-columns: minmax(0, 1fr) 56px minmax(0, 1fr); align-items: center; margin-bottom: 12px; }
.replay-player-row .player-bar { min-width: 0; }
.replay-player-row .player-bar .piece-swatch { margin: 0; }
.replay-player-row #replay-white-player { justify-content: flex-start; flex-direction: row-reverse; text-align: right; }
.replay-versus { position: relative; color: var(--ink-soft); font: 600 13px/1 Georgia, serif; text-align: center; }
.replay-versus::before, .replay-versus::after { position: absolute; top: 50%; width: 11px; height: 1px; content: ''; background: var(--line); }
.replay-versus::before { right: calc(100% + 7px); }
.replay-versus::after { left: calc(100% + 7px); }
.replay-board { border-color: var(--wood-dark); box-shadow: 0 12px 30px rgba(55,52,38,.18), inset 0 0 40px rgba(255,249,213,.25); }
.replay-board .board-cell.occupied .stone::before { position: absolute; inset: 0; display: grid; place-items: center; content: attr(data-move-no); color: rgba(255,255,255,.82); font: 700 12px/1 Georgia, serif; }
.replay-board .board-cell.white .stone::before { color: #526059; }
.replay-board .board-cell.last .stone { outline: 2px solid var(--danger); outline-offset: 2px; }
.replay-board .board-cell.last .stone::after { display: none; }
.replay-sidebar { min-height: 0; gap: 24px; }
.replay-summary { display: grid; gap: 7px; padding: 17px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.replay-summary > span, .replay-timeline-heading > span, .replay-timeline-scale { color: var(--ink-soft); font-size: 11px; }
.replay-result { color: var(--green-dark); font: 600 22px/1.35 "STKaiti", "KaiTi", serif; }
.replay-timeline { --replay-position: 0%; }
.replay-timeline-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.replay-timeline-heading strong { color: var(--ink); font: 600 16px/1 Georgia, serif; }
.replay-sidebar input[type="range"] { width: 100%; height: 6px; margin: 14px 0 8px; -webkit-appearance: none; appearance: none; border: 0; border-radius: 999px; outline-offset: 6px; background: linear-gradient(to right, var(--green) 0 var(--replay-position), var(--line) var(--replay-position) 100%); cursor: pointer; }
.replay-sidebar input[type="range"]::-webkit-slider-thumb { width: 16px; height: 16px; -webkit-appearance: none; appearance: none; border: 3px solid var(--paper); border-radius: 50%; background: var(--green); box-shadow: 0 1px 4px rgba(31,44,36,.3); }
.replay-sidebar input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border: 3px solid var(--paper); border-radius: 50%; background: var(--green); box-shadow: 0 1px 4px rgba(31,44,36,.3); }
.replay-timeline-scale { display: flex; justify-content: space-between; }
.replay-controls { display: grid; grid-template-columns: repeat(5, 44px); justify-content: space-between; gap: 8px; }
.replay-controls button { width: 44px; height: 44px; padding: 0; border: 1px solid #aeb9b0; border-radius: 5px; color: var(--ink); background: rgba(255,255,255,.6); font: 700 21px/1 Georgia, serif; transition: color 150ms ease, border-color 150ms ease, background 150ms ease, transform 150ms ease; }
.replay-controls button:hover:not(:disabled) { border-color: var(--green); color: var(--green-dark); background: var(--green-pale); transform: translateY(-1px); }
.replay-controls button:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
.replay-controls button:disabled { cursor: not-allowed; opacity: .4; }
.replay-controls #replay-play { border-color: var(--green); border-radius: 50%; color: #fff; background: var(--green); }
.replay-controls #replay-play:hover:not(:disabled), .replay-controls #replay-play.is-playing { border-color: var(--green-dark); color: #fff; background: var(--green-dark); }

.toast-message { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: min(380px, calc(100% - 40px)); padding: 12px 16px; border: 1px solid #8da193; border-radius: 5px; color: #fff; background: #40574a; box-shadow: 0 8px 26px rgba(25,35,29,.22); font-size: 13px; }
.toast-message.error { background: #884a43; border-color: #a66c65; }
.result-dialog { position: fixed; z-index: 110; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(29,37,32,.45); }
.result-dialog > div { width: min(100%, 360px); padding: 30px; border: 1px solid #aeb9b0; border-radius: 7px; background: var(--paper); text-align: center; box-shadow: 0 20px 70px rgba(23,31,26,.24); }
.confirm-dialog > div { width: min(100%, 380px); }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.settings-dialog > div { width: min(100%, 420px); text-align: left; }
.settings-dialog h2 { text-align: center; }
.settings-list { margin: 20px 0 24px; border-top: 1px solid var(--line); }
.setting-row { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); font-size: 14px; font-weight: 700; }
.setting-switch { position: relative; width: 44px; height: 24px; flex: 0 0 auto; padding: 0; border: 1px solid #9daaa0; border-radius: 12px; background: #d9dfd8; transition: background 150ms ease, border-color 150ms ease; }
.setting-switch::after { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; content: ''; background: #fff; box-shadow: 0 1px 3px rgba(25,35,29,.25); transition: transform 150ms ease; }
.setting-switch.active { border-color: var(--green); background: var(--green); }
.setting-switch.active::after { transform: translateX(20px); }
.setting-switch:disabled { cursor: not-allowed; opacity: .45; }
.result-dialog h2 { margin: 12px 0 8px; font: 600 25px/1.3 "STKaiti", "KaiTi", serif; }
.result-dialog p { margin: 0 0 22px; color: var(--ink-soft); line-height: 1.7; }
.result-stone { display: inline-block; width: 48px; height: 48px; border-radius: 50%; background: #222824; box-shadow: inset 6px 7px 10px rgba(255,255,255,.16), 0 4px 7px rgba(20,25,22,.25); }

@media (max-width: 900px) {
    .app-header { grid-template-columns: 1fr auto; min-height: 62px; }
    .main-nav { grid-column: 1 / -1; grid-row: 2; height: 48px; overflow-x: auto; border-top: 1px solid var(--line); }
    .main-nav a { min-width: max-content; padding: 0 16px; }
    .account-menu > span { display: none; }
    .hero-content { padding-right: 38%; }
    .game-layout { grid-template-columns: minmax(0, 1fr); }
    .game-sidebar { position: static; padding: 24px 0 0; border-top: 1px solid var(--line); border-left: 0; }
    .chat-messages { height: 220px; }
}

@media (max-width: 680px) {
    .page-width, .hero-content { width: min(100% - 24px, 1180px); }
    .login-scene { justify-content: center; padding: 28px 18px; background-position: 35% center; }
    .login-copy { position: absolute; top: 24px; left: 24px; margin: 0; }
    .login-copy h1 { font-size: 34px; }
    .login-copy > p:last-child { display: none; }
    .login-panel { margin: 120px 0 0; padding: 26px 22px; }
    .app-header { padding: 0 12px; }
    .brand small { display: none; }
    .account-menu img { width: 34px; height: 34px; }
    .lobby-hero { min-height: 360px; background-position: 43% center; }
    .hero-content { padding: 34px 18% 34px 2%; }
    .hero-content h1 { max-width: 320px; font-size: 32px; }
    .hero-content > p:not(.brand-kicker) { max-width: 300px; font-size: 13px; }
    .mode-list { grid-template-columns: 1fr; }
    .mode-card + .mode-card { border-top: 1px solid var(--line); border-left: 0; }
    .stats-strip { grid-template-columns: repeat(2, 1fr); }
    .stats-strip div:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
    .stats-strip div:nth-child(4) { border-top: 1px solid var(--line); }
    .stats-strip div { padding: 15px; }
    .section-heading { align-items: flex-start; flex-direction: column; margin-bottom: 18px; }
    .game-page, .data-page, .replay-page { padding-top: 24px; }
    .match-stage { grid-template-columns: 1fr; min-height: 0; }
    .match-art { width: min(100%, 260px); }
    .match-copy { padding: 20px 18px 34px; }
    .gomoku-board { width: calc(100vw - 24px); padding: 4.2%; }
    .online-player-row { grid-template-columns: minmax(0, 1fr) 36px minmax(0, 1fr); }
    .online-player-row .player-bar { gap: 6px; }
    .online-player-row .player-bar img { width: 32px; height: 32px; }
    .online-player-row .player-bar strong { max-width: 100%; font-size: 12px; }
    .player-bar strong { max-width: 165px; }
    .replay-player-row { grid-template-columns: minmax(0, 1fr) 36px minmax(0, 1fr); margin-bottom: 8px; }
    .replay-player-row .player-bar { gap: 6px; }
    .replay-player-row .player-bar img { width: 32px; height: 32px; }
    .replay-player-row .player-bar strong { max-width: 100%; font-size: 12px; }
    .replay-board .board-cell.occupied .stone::before { font-size: 10px; }
    .online-result { min-height: 520px; padding: 30px 8px 40px; }
    .settlement-heading h2 { font-size: 30px; }
    .settlement-versus { min-height: 150px; grid-template-columns: minmax(0, 1fr) 58px minmax(0, 1fr); margin: 22px 0 18px; }
    .settlement-player img { width: 82px; height: 82px; }
    .settlement-player strong { max-width: 110px; font-size: 13px; }
    .settlement-pk { font-size: 22px; }
    .settlement-pk::before, .settlement-pk::after { width: 10px; }
    .settlement-stats div { padding: 14px 8px; }
    .settlement-stats strong { font-size: 16px; }
    .settlement-actions { width: 100%; }
    .settlement-actions .btn { min-width: 0; flex: 1; }
    .turn-clock { font-size: 36px; }
    .toast-message { right: 12px; bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
    .board-cell.winning .stone { animation: none !important; }
}
