:root {
    --bg-color: #121212;
    /* 玄黑 */
    --text-color: #E8E8E8;
    /* 月白 */
    --accent-color: #5d7063;
    /* 竹青 */
    --accent-glow: rgba(93, 112, 99, 0.4);
    --btn-bg: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(30, 30, 30, 0.6);
    --danger-color: #c95c5c;
    /* 丹绛 */
    --wood-color: #dcab6b;
    --border-radius: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body,
html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Helvetica Neue', 'PingFang SC', 'Source Han Serif CN', serif;
    overflow: hidden;
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
}

body.audio-active::after {
    content: '🔊';
    position: fixed;
    top: 10px;
    right: 10px;
    font-size: 1rem;
    pointer-events: none;
    opacity: 0.5;
    z-index: 9999;
}

.app-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.view.active {
    opacity: 1;
    pointer-events: all;
    z-index: 10;
}

.hidden {
    display: none !important;
}

/* Landing View */
#view-landing {
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #262626 0%, #121212 100%);
}

.landing-content {
    text-align: center;
}

.title {
    font-size: 3rem;
    font-weight: normal;
    letter-spacing: 4px;
    margin-bottom: 10px;
    text-shadow: 0 4px 20px rgba(255, 255, 255, 0.1);
}

.subtitle {
    font-size: 1rem;
    color: #888;
    margin-bottom: 60px;
    letter-spacing: 2px;
}

.btn-hero {
    background: var(--glass-bg);
    color: var(--text-color);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 16px 48px;
    font-size: 1.2rem;
    border-radius: 30px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    letter-spacing: 2px;
}

.btn-hero:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2);
}

/* Camera View & Board View */
.camera-wrapper,
.board-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    overflow: hidden;
}

video,
#camera-overlay {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    /* Let touches fall through unless intended */
}

#camera-overlay,
#board-canvas {
    pointer-events: auto;
}

/* Power Saving Mode */
#power-saving-mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    /* Darken heavily */
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
    color: rgba(255, 255, 255, 0.3);
    font-size: 1.2rem;
    text-align: center;
    line-height: 1.6;
    pointer-events: all;
    /* Catch touches */
    opacity: 0;
    transition: opacity 1s ease;
}

#power-saving-mask.active {
    display: flex;
    opacity: 1;
}

/* Controls */
.controls-area {
    padding: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 20;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.status-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
}

#detect-status {
    font-size: 0.9rem;
    color: var(--accent-color);
    position: relative;
}

#detect-status[data-debug]::after {
    content: attr(data-debug);
    position: absolute;
    right: 0;
    top: 100%;
    font-size: 0.7rem;
    color: #666;
    white-space: nowrap;
}

/* Debug Status Display */
.debug-status {
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.debug-status.active {
    background: rgba(93, 112, 99, 0.3);
    border-color: var(--accent-color);
}

.debug-status.detecting {
    background: rgba(200, 150, 50, 0.3);
    border-color: #c89632;
}

.debug-status.error {
    background: rgba(201, 92, 92, 0.3);
    border-color: var(--danger-color);
}

#debug-text {
    color: #aaa;
}

.debug-status.active #debug-text {
    color: #8fbc8f;
}

.debug-status.detecting #debug-text {
    color: #e8c170;
}

.debug-status.error #debug-text {
    color: #e87070;
}

/* Arbiter Status Style (v2.0) */
.arbiter-status {
    background: rgba(18, 18, 18, 0.85);
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.arbiter-status .dot {
    width: 8px;
    height: 8px;
    background: #27ae60;
    border-radius: 50%;
    box-shadow: 0 0 10px #27ae60;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        opacity: 0.7;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
        box-shadow: 0 0 15px #27ae60;
    }

    100% {
        transform: scale(0.95);
        opacity: 0.7;
    }
}

#arbiter-text {
    color: #e0e0e0;
    letter-spacing: 0.5px;
}

/* Classifier Debug Display */
.classifier-debug {
    background: rgba(0, 0, 0, 0.7);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    text-align: center;
    margin-bottom: 8px;
    font-family: monospace;
    color: #888;
}

.classifier-debug.visible {
    display: block;
}

#classifier-debug-text {
    color: #c89632;
}

.action-buttons {
    display: flex;
    gap: 15px;
}

button {
    font-family: inherit;
    border: none;
    outline: none;
    padding: 14px;
    border-radius: var(--border-radius);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent-color);
    color: #fff;
    flex: 1;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.5;
    filter: grayscale(1);
    pointer-events: none;
}

.btn-glass {
    background: var(--btn-bg);
    color: var(--text-color);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-glass:active {
    background: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: #7d3c3c;
    color: var(--text-color);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-danger:active {
    background: #9d4c4c;
}

.btn-secondary {
    background: #5d7a6c;
    color: #fff;
    border: 2px solid #8fbc8f;
    padding: 10px 16px;
    font-size: 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:active {
    background: #4d6a5c;
}

/* Alarm Overlay */
#alarm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.alarm-box {
    background: #1a1a1a;
    border: 1px solid var(--danger-color);
    padding: 30px;
    border-radius: var(--border-radius);
    width: 85%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(201, 92, 92, 0.2);
}

/* Magnifier for Virtual Board edits */
#magnifier {
    position: absolute;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    border: 4px solid #dcab6b;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.8), inset 0 0 10px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    background: #dcab6b;
    overflow: hidden;
    z-index: 100;
    /* Center transform handles alignment via left/top JS */
    transform: translate(-50%, -50%);
}

#magnifier canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform: none;
}