:root {
    --db-font: Inter, "SF Pro Text", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --db-bg: #edf4f7;
    --db-surface: #ffffff;
    --db-panel: #f8fbfc;
    --db-border: #cad8dd;
    --db-text: #1c2b31;
    --db-muted: #687b83;
    --db-primary: #0f7f75;
    --db-primary-hover: #0b655e;
    --db-secondary: #286c9c;
    --db-warning: #b66b18;
    --db-danger: #b33b46;
    --db-success: #278253;
    --db-canvas: #071018;
}

html.i18n-pending body {
    visibility: hidden;
}

html.i18n-pending::before {
    content: "Loading...";
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--db-bg);
    color: var(--db-muted);
    font: 700 14px var(--db-font);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    min-height: 0;
    margin: 0;
}

body {
    overflow: hidden;
    background: var(--db-bg);
    color: var(--db-text);
    font-family: var(--db-font);
}

button,
input {
    font: inherit;
}

button {
    touch-action: manipulation;
}

[hidden] {
    display: none !important;
}

.db-page {
    height: var(--db-viewport-height, 100dvh);
    max-height: var(--db-viewport-height, 100dvh);
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.db-disclaimer {
    position: relative;
    flex: 0 0 auto;
    min-height: 34px;
    padding: 7px 48px 7px 18px;
    background: #fff4dc;
    border-bottom: 1px solid #e8c980;
    color: #704d13;
    font-size: 12px;
    line-height: 1.5;
    text-align: center;
}

.db-disclaimer-close {
    position: absolute;
    top: 50%;
    right: 12px;
    width: 28px;
    height: 28px;
    padding: 0;
    transform: translateY(-50%);
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 19px;
    line-height: 1;
}

.db-disclaimer-close:hover {
    background: rgba(112, 77, 19, 0.12);
}

.db-disclaimer-close:focus-visible {
    outline: 3px solid rgba(112, 77, 19, 0.22);
    outline-offset: 1px;
}

.db-header {
    flex: 0 0 auto;
    min-height: 74px;
    padding: 10px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: var(--db-surface);
    border-bottom: 1px solid var(--db-border);
}

.db-brand {
    min-width: 230px;
}

.db-title {
    margin: 0;
    font-size: 17px;
    line-height: 1.25;
    font-weight: 760;
    letter-spacing: 0;
}

.db-title-mark {
    display: inline-flex;
    width: 18px;
    height: 10px;
    margin-right: 8px;
    vertical-align: 2px;
}

.db-title-mark::before,
.db-title-mark::after {
    content: "";
    flex: 1;
}

.db-title-mark::before {
    background: #e64045;
}

.db-title-mark::after {
    background: #16a6b6;
}

.db-phase {
    margin-top: 5px;
    color: var(--db-muted);
    font-size: 12px;
    line-height: 1.4;
}

.db-status {
    display: grid;
    grid-template-columns: repeat(5, minmax(74px, auto));
    gap: 8px;
}

.db-status-free {
    grid-template-columns: repeat(4, minmax(74px, auto));
}

.db-stat {
    min-width: 74px;
    padding: 6px 9px;
    border-left: 2px solid var(--db-border);
}

.db-stat-label {
    display: block;
    color: var(--db-muted);
    font-size: 10px;
    line-height: 1.2;
}

.db-stat-value {
    display: block;
    margin-top: 2px;
    font-size: 14px;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.db-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.db-mode-menu {
    position: relative;
}

.db-toolbar-btn {
    min-height: 44px;
    padding: 9px 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--db-border);
    border-radius: 5px;
    background: var(--db-surface);
    color: var(--db-text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.db-toolbar-icon-btn {
    width: 44px;
    min-width: 44px;
    padding: 8px;
}

.db-toolbar-btn:hover,
.db-toolbar-btn.active {
    border-color: #8ca8b2;
    background: #f2f8fa;
    color: var(--db-primary);
}

.db-toolbar-btn:focus-visible {
    outline: 3px solid rgba(40, 108, 156, 0.25);
    outline-offset: 2px;
}

.db-toolbar-icon {
    width: 20px;
    flex: 0 0 20px;
    font-size: 20px;
    font-weight: 500;
    line-height: 1;
    text-align: center;
}

.db-mode-caret {
    color: var(--db-muted);
    font-size: 11px;
}

.db-mode-dropdown {
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    z-index: 80;
    width: 250px;
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    background: var(--db-surface);
    border: 1px solid var(--db-border);
    border-radius: 6px;
    box-shadow: 0 12px 30px rgba(5, 20, 28, 0.18);
}

.db-mode-dropdown.show {
    display: flex;
}

.db-mode-dropdown a,
.db-mode-dropdown button {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--db-text);
    cursor: pointer;
    font-size: 12px;
    font-weight: 650;
    line-height: 1.4;
    text-align: left;
    text-decoration: none;
}

.db-mode-dropdown a:hover {
    background: #edf5f7;
    color: var(--db-primary);
}

.db-mode-dropdown .active-mode {
    background: #e5f2f0;
    color: var(--db-primary);
    cursor: default;
}

.db-main {
    min-height: 0;
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(230px, 25vw, 300px);
    gap: 14px;
    padding: 14px;
    overflow: hidden;
}

.db-stage-shell {
    min-width: 0;
    min-height: 0;
    height: 100%;
    background: #dfe9ed;
    border: 1px solid var(--db-border);
    border-radius: 6px;
    overflow: hidden;
}

.db-canvas-wrap {
    position: relative;
    min-height: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    overflow: hidden;
}

.db-stage-layout {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.db-board-slot {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.db-board-frame {
    position: relative;
    flex: 0 0 auto;
    width: 520px;
    height: 780px;
}

.db-game-canvas {
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    width: 520px;
    height: 780px;
    max-width: none;
    max-height: none;
    aspect-ratio: 2 / 3;
    transform: scale(var(--db-canvas-scale, 1));
    transform-origin: top left;
    background: var(--db-canvas);
    border: 1px solid #233944;
    will-change: transform;
}

.db-stage-message-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.db-stage-message {
    width: min(78%, 380px);
    padding: 12px 14px;
    background: rgba(5, 15, 22, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #f5fbfd;
    text-align: center;
    font-size: 14px;
    line-height: 1.55;
}

.db-board-hint {
    position: absolute;
    z-index: 5;
    max-width: 220px;
    padding: 7px 30px 7px 12px;
    background: rgba(5, 15, 22, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    color: #e8f1f5;
    font-size: 12px;
    line-height: 1.5;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.db-board-hint-text {
    display: block;
}

.db-board-hint-close {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

.db-board-hint-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.db-board-hint-close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.4);
    outline-offset: 1px;
}

.db-action-btn,
.db-segment button,
.db-choice-btn {
    border: 1px solid var(--db-border);
    border-radius: 5px;
    background: var(--db-surface);
    color: var(--db-text);
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.db-action-btn:hover,
.db-segment button:hover,
.db-choice-btn:hover {
    border-color: #8ca8b2;
    background: #f2f8fa;
}

.db-action-btn:focus-visible,
.db-segment button:focus-visible,
.db-choice-btn:focus-visible,
input:focus-visible {
    outline: 3px solid rgba(40, 108, 156, 0.25);
    outline-offset: 2px;
}

.db-action-btn:disabled,
.db-choice-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.db-control-panel {
    min-width: 0;
    overflow-y: auto;
    padding: 14px;
    background: var(--db-panel);
    border: 1px solid var(--db-border);
    border-radius: 6px;
}

.db-control-group + .db-control-group {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--db-border);
}

.db-control-title {
    margin: 0 0 10px;
    color: var(--db-muted);
    font-size: 11px;
    font-weight: 750;
    text-transform: uppercase;
}

.db-field {
    margin-top: 11px;
}

.db-field:first-child {
    margin-top: 0;
}

.db-field-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 7px;
    color: var(--db-muted);
    font-size: 12px;
}

.db-segment {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 3px;
    background: #e8f0f3;
    border-radius: 6px;
}

.db-segment button {
    min-height: 34px;
    padding: 6px 8px;
    background: transparent;
    border-color: transparent;
    font-size: 12px;
}

.db-segment button.active {
    background: var(--db-surface);
    border-color: #9eb4bc;
    color: var(--db-primary);
    font-weight: 750;
}

.db-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 38px;
    padding: 7px 0;
    color: var(--db-muted);
    font-size: 12px;
}

.db-toggle input {
    width: 18px;
    height: 18px;
    accent-color: var(--db-primary);
}

.db-progress {
    width: 100%;
    height: 8px;
    overflow: hidden;
    background: #dfe9ed;
    border-radius: 4px;
}

.db-progress > span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--db-primary);
    transition: width 0.2s linear;
}

.db-action-stack {
    display: grid;
    gap: 8px;
}

.db-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 680;
    text-align: center;
    text-decoration: none;
}

.db-action-btn.primary {
    background: var(--db-primary);
    border-color: var(--db-primary);
    color: #fff;
}

.db-action-btn.primary:hover {
    background: var(--db-primary-hover);
    border-color: var(--db-primary-hover);
}

.db-action-btn.secondary {
    color: var(--db-secondary);
}

.db-action-btn.warning {
    color: var(--db-warning);
}

.db-quota {
    margin: 0 0 10px;
    color: var(--db-muted);
    font-size: 12px;
    line-height: 1.5;
}

.db-quota strong {
    color: var(--db-primary);
    font-size: 16px;
}

.db-inline-note {
    min-height: 18px;
    margin-top: 9px;
    color: var(--db-muted);
    font-size: 11px;
    line-height: 1.5;
}

.db-inline-note.ok {
    color: var(--db-success);
}

.db-inline-note.err {
    color: var(--db-danger);
}

.db-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(8, 21, 28, 0.72);
}

.db-dialog {
    width: min(100%, 620px);
    max-height: calc(100vh - 36px);
    overflow-y: auto;
    padding: 20px;
    background: var(--db-surface);
    border: 1px solid var(--db-border);
    border-radius: 7px;
    box-shadow: 0 20px 50px rgba(5, 20, 28, 0.25);
}

.db-dialog.narrow {
    width: min(100%, 480px);
}

.db-dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.db-dialog h2 {
    margin: 0;
    font-size: 20px;
    line-height: 1.3;
}

.db-dialog-close {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    margin: -7px -7px 0 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: var(--db-muted);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}

.db-dialog-close:hover {
    border-color: var(--db-border);
    background: #f2f8fa;
    color: var(--db-text);
}

.db-dialog-close:focus-visible {
    outline: 3px solid rgba(40, 108, 156, 0.25);
    outline-offset: 1px;
}

.db-dialog-copy {
    margin: 8px 0 16px;
    color: var(--db-muted);
    font-size: 13px;
    line-height: 1.65;
}

.db-calibration-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--db-canvas);
    border: 1px solid #233944;
}

.db-calibration-panel {
    margin-top: 15px;
}

.db-range {
    width: 100%;
    accent-color: var(--db-primary);
}

.db-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

.db-check-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 14px;
}

.db-choice-btn {
    min-height: 48px;
    padding: 8px;
    font-size: 18px;
    font-weight: 760;
}

.db-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.db-metric {
    min-width: 0;
    padding: 12px;
    background: #f1f6f8;
    border: 1px solid var(--db-border);
    border-radius: 5px;
}

.db-metric-label {
    color: var(--db-muted);
    font-size: 11px;
}

.db-metric-value {
    margin-top: 5px;
    font-size: 19px;
    font-weight: 760;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.db-gate-badge {
    display: inline-block;
    margin-bottom: 10px;
    padding: 4px 8px;
    color: var(--db-secondary);
    background: #e7f2f8;
    border: 1px solid #b6d4e5;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 750;
}

.db-gate-note {
    margin-top: 12px;
    padding: 10px 12px;
    background: #f5f8f9;
    border-left: 3px solid var(--db-secondary);
    color: var(--db-muted);
    font-size: 12px;
    line-height: 1.55;
}

@media (max-width: 1023.98px), (pointer: coarse) {
    .mobile-hidden-mode {
        display: none !important;
    }
}

@media (max-width: 1180px) {
    .db-status {
        grid-template-columns: repeat(3, minmax(74px, auto));
    }

    .db-stat:nth-child(n + 4) {
        display: none;
    }
}

@media (max-width: 980px) and (hover: hover), (max-width: 980px) and (any-hover: hover) {
    .db-header {
        gap: 8px;
        padding-inline: 10px;
    }

    .db-brand {
        min-width: 185px;
    }

    .db-status {
        gap: 4px;
    }

    .db-stat:nth-child(n + 3) {
        display: none;
    }

    .db-header-actions {
        gap: 4px;
    }

    .db-toolbar-btn {
        width: 42px;
        min-width: 42px;
        padding-inline: 8px;
    }

    .db-toolbar-btn > span:not(.db-toolbar-icon) {
        display: none;
    }
}

.db-compact-height .db-disclaimer {
    min-height: 28px;
    padding-block: 4px;
    font-size: 11px;
}

.db-compact-height .db-header {
    min-height: 56px;
    padding: 6px 10px;
    gap: 10px;
}

.db-compact-height .db-brand {
    min-width: 205px;
}

.db-compact-height .db-title {
    font-size: 15px;
}

.db-compact-height .db-phase {
    margin-top: 2px;
    font-size: 11px;
}

.db-compact-height .db-status {
    gap: 4px;
}

.db-compact-height .db-stat {
    min-width: 68px;
    padding: 3px 6px;
}

.db-compact-height .db-toolbar-btn {
    min-height: 38px;
    padding-block: 6px;
}

.db-compact-height .db-toolbar-icon-btn {
    width: 38px;
    min-width: 38px;
    padding: 6px;
}

.db-compact-height .db-main {
    gap: 7px;
    padding: 7px;
}

.db-compact-height .db-canvas-wrap {
    padding: 6px;
}

.db-compact-height .db-control-panel {
    padding: 9px;
}

.db-compact-height .db-control-group + .db-control-group {
    margin-top: 13px;
    padding-top: 13px;
}

.db-compact-height .db-action-stack {
    gap: 6px;
}

.db-compact-height .db-action-btn {
    min-height: 36px;
    padding-block: 7px;
}

@media (max-width: 900px) and (hover: none) and (pointer: coarse) {
    body {
        overflow: auto;
    }

    .db-page {
        height: auto;
        max-height: none;
        min-height: 100%;
        overflow: visible;
    }

    .db-header {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .db-status {
        order: 3;
        width: 100%;
        grid-template-columns: repeat(3, 1fr);
    }

    .db-header-actions {
        margin-left: auto;
    }

    .db-main {
        grid-template-columns: 1fr;
        min-height: 0;
        overflow: visible;
    }

    .db-stage-shell {
        min-height: min(620px, calc(100dvh - 180px));
    }

    .db-control-panel {
        overflow: visible;
    }
}

@media (max-width: 560px) {
    .db-disclaimer {
        padding: 7px 42px 7px 10px;
    }

    .db-header {
        padding: 10px 12px;
    }

    .db-brand {
        min-width: 0;
        flex: 1;
    }

    .db-title {
        font-size: 15px;
    }

    .db-header-actions {
        gap: 4px;
    }

    .db-toolbar-btn {
        min-height: 42px;
        padding-inline: 10px;
    }

    .db-toolbar-btn > span:not(.db-toolbar-icon):not(.db-mode-caret) {
        display: none;
    }

    .db-mode-dropdown {
        right: auto;
        left: 0;
        width: min(250px, calc(100vw - 24px));
    }

    .db-status {
        gap: 4px;
    }

    .db-stat {
        min-width: 0;
        padding-inline: 6px;
    }

    .db-main {
        padding: 8px;
        gap: 8px;
    }

    .db-stage-shell {
        min-height: 560px;
    }

    .db-canvas-wrap {
        padding: 8px;
    }

    .db-game-canvas {
        max-height: 690px;
    }

    .db-board-hint {
        max-width: 160px;
        font-size: 11px;
        padding: 6px 26px 6px 10px;
    }

    .db-dialog {
        padding: 16px;
    }

    .db-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
