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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    min-height: 100vh;
}

.app {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

header h1 {
    font-size: 1.6rem;
    color: #e8d5b5;
    letter-spacing: 1px;
}

.status {
    font-size: 1rem;
    padding: 6px 16px;
    border-radius: 6px;
    background: #2a2a4a;
    font-weight: 600;
}

.sync-status {
    font-size: 0.8rem;
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 600;
}

.sync-status.online { background: #27ae60; color: #fff; }
.sync-status.offline { background: #e74c3c; color: #fff; }

.status.white-turn { color: #fff; border: 2px solid #e8d5b5; }
.status.black-turn { color: #333; background: #e8d5b5; border: 2px solid #e8d5b5; }
.status.check { background: #c0392b; color: #fff; border-color: #e74c3c; }
.status.checkmate {
    background: #e74c3c; color: #fff; border-color: #e74c3c;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.main {
    display: grid;
    grid-template-columns: 360px auto 1fr;
    gap: 24px;
    align-items: flex-start;
}

.bottom {
    margin-top: 32px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 24px;
    align-items: stretch;
}

.right-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 460px;
}
.right-col .theory-panel { flex: 0 0 auto; }
.right-col .evaluation-panel {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.eval-scores {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    background: #0e1530;
    border: 1px solid #23305a;
    border-radius: 6px;
}
.eval-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}
.eval-score.white .eval-value { color: #f0d9b5; }
.eval-score.black .eval-value { color: #cfd4e0; }
.eval-side {
    font-size: 0.72rem; color: #888;
    text-transform: uppercase; letter-spacing: 1px;
}
.eval-value {
    font-size: 1.8rem; font-weight: 700;
    line-height: 1.1;
}
.eval-unit { font-size: 0.7rem; color: #666; }
.eval-vs { color: #555; font-size: 0.85rem; }
.eval-diff {
    text-align: center;
    font-size: 0.9rem;
    color: #aaa;
    padding: 4px 0;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}
.eval-diff.white-adv { color: #f0d9b5; }
.eval-diff.black-adv { color: #8aa8d8; }
.eval-text {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    background: #1a2342;
    border: 1px solid #23305a;
    border-radius: 6px;
    flex: 1;
}
.eval-line {
    color: #ccc;
    font-size: 0.88rem;
    line-height: 1.45;
}
.eval-line:first-child { color: #e8d5b5; font-weight: 600; }

.eval-engine {
    margin-top: 4px;
    padding: 10px 12px;
    background: #0e1530;
    border: 1px solid #23305a;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.eval-engine-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.eval-engine-title {
    font-size: 0.75rem; color: #888;
    text-transform: uppercase; letter-spacing: 1px;
}
.eval-engine-btns { display: flex; gap: 6px; }
.eval-engine-btns button {
    padding: 5px 10px;
    background: #e8d5b5; color: #1a1a2e;
    border: none; border-radius: 4px;
    font-size: 0.78rem; font-weight: 700;
    cursor: pointer; font-family: inherit;
    transition: background 0.15s;
}
.eval-engine-btns button.sec {
    background: #3a3a5a; color: #ddd;
}
.eval-engine-btns button:hover { background: #d4c1a0; }
.eval-engine-btns button.sec:hover { background: #4a4a6a; }
.eval-engine-btns button:disabled {
    opacity: 0.6; cursor: wait;
}
.eval-engine-row {
    display: flex; align-items: center;
    gap: 10px; flex-wrap: wrap;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}
.eval-score-pill {
    background: #2a2a4a;
    color: #e8d5b5;
    padding: 3px 10px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.95rem;
    min-width: 60px;
    text-align: center;
}
.eval-score-pill.good { background: #204a32; color: #8ee9a8; }
.eval-score-pill.bad { background: #4a1e1e; color: #f08a82; }
.eval-score-pill.mate { background: #b93c2f; color: #fff; }
.eval-source { color: #888; font-size: 0.78rem; }
.eval-depth { color: #666; font-size: 0.78rem; margin-left: auto; }
.eval-pv {
    color: #bbb;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    word-break: break-word;
    min-height: 1.2em;
}

/* Left column: clocks */
.left-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.clock-panel .berlin-clock {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}

.berlin-date { font-size: 0.85rem; color: #aaa; }
.berlin-time { font-size: 1.5rem; color: #e8d5b5; font-weight: 700; }
.berlin-tz { font-size: 0.75rem; color: #888; }
.utc-time { font-size: 0.75rem; color: #666; margin-top: 6px; }

.chessclock-panel .clock-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid #2a2a4a;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}
.chessclock-panel .clock-row:last-child { border-bottom: 0; }
.chessclock-panel .clock-label { font-size: 0.75rem; color: #888; text-transform: uppercase; letter-spacing: 0.5px; }
.chessclock-panel .clock-value { font-size: 0.85rem; color: #ddd; }

.clock-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #2a2a4a;
}
.clock-grid.top { padding-top: 10px; }
.clock-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}
.clock-cell .clock-label {
    font-size: 0.7rem; color: #888;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.clock-cell .clock-value { font-size: 0.9rem; color: #ddd; }
.clock-cell.big .clock-value.countdown {
    font-size: 1.3rem; font-weight: 700; color: #e8d5b5;
}
.countdown.expired { color: #e74c3c !important; }
.countdown.urgent { color: #f39c12 !important; }

.analog-clocks {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 12px;
}
.analog-dial {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.analog-dial svg {
    width: 100px;
    height: 100px;
    background: radial-gradient(circle at 30% 25%, #fff1d0, #d8be8a 70%, #a88a52);
    border-radius: 50%;
    border: 3px solid #6b4e1e;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4), inset 0 0 8px rgba(0,0,0,0.15);
}
.analog-dial.urgent svg { border-color: #f39c12; }
.analog-dial.expired svg {
    border-color: #e74c3c;
    background: radial-gradient(circle at 30% 25%, #ffe0dc, #e78a80 70%, #c0392b);
}
.dial-caption {
    font-size: 0.7rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.dial-tick { stroke: #2a1a08; }
.dial-tick.minor { stroke-width: 0.8; }
.dial-tick.major { stroke-width: 1.8; }
.dial-label {
    fill: #2a1a08;
    font-size: 9px;
    font-weight: 700;
    text-anchor: middle;
    dominant-baseline: central;
    font-family: Georgia, 'Times New Roman', serif;
}
.dial-hand { stroke-linecap: round; }
.dial-hand.hour { stroke: #1a1208; stroke-width: 3.5; }
.dial-hand.minute { stroke: #2a1a08; stroke-width: 2; }
.dial-hand.day { stroke: #8b0000; stroke-width: 3; }
.dial-center { fill: #1a1208; }
.dial-center-ring { fill: none; stroke: #8b0000; stroke-width: 0.6; }

#move-duration {
    background: #1a1a2e; color: #ddd;
    border: 1px solid #3a3a5a; border-radius: 4px;
    padding: 3px 6px; font-family: inherit; font-size: 0.8rem;
}

/* Board */
.board-container {
    position: relative;
    flex-shrink: 0;
}

/* 3D Board Flip */
.board-container {
    perspective: 1200px;
}
.flip-3d-scene {
    position: absolute;
    top: 0; left: 0;
    width: 520px; height: 520px;
    z-index: 15;
    pointer-events: none;
}
.flip-3d-rotator {
    width: 100%; height: 100%;
    transform-style: preserve-3d;
    position: relative;
}
.flip-3d-face {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    backface-visibility: hidden;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 3px solid #e8d5b5;
    border-radius: 4px;
    overflow: hidden;
}
.flip-3d-face.back {
    transform: rotateY(180deg);
}
.flip-3d-face .sq {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 46px;
    font-family: 'DejaVu Sans', 'Noto Sans Symbols 2', 'Segoe UI Symbol', 'Arial Unicode MS', sans-serif;
    font-variant-emoji: text;
    user-select: none;
}
.flip-3d-face .sq.light { background: #f0d9b5; }
.flip-3d-face .sq.dark { background: #b58863; }
.flip-3d-face .sq.last-from { background: rgba(255,255,100,0.4) !important; }
.flip-3d-face .sq.last-to { background: rgba(255,255,100,0.5) !important; }
.flip-3d-face .sq.piece-white { -webkit-text-fill-color: #fff; -webkit-text-stroke: 0.5px #333; color: #fff; }
.flip-3d-face .sq.piece-black { -webkit-text-fill-color: #111; -webkit-text-stroke: 1px #111; color: #111; }

/* Z-Achse: Glyph-Gegen-Rotation via CSS Custom Property */
.flip-3d-face { --crot: 0deg; }
.flip-3d-face .sq .glyph { display: inline-block; transform: rotate(var(--crot)); }

/* Flip settings panel */
.flip-panel .flip-settings {
    display: flex; gap: 12px;
}
.flip-panel .flip-settings label {
    display: flex; flex-direction: column; gap: 4px; flex: 1;
}
.flip-panel .flip-label {
    font-size: 0.7rem; color: #888;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.flip-panel .flip-settings select {
    background: #1a1a2e; color: #ddd;
    border: 1px solid #3a3a5a; border-radius: 4px;
    padding: 4px 8px; font-family: inherit; font-size: 0.8rem;
}

@media (max-width: 700px) {
    .flip-3d-scene { width: min(520px, 95vw); height: min(520px, 95vw); }
    .flip-3d-face .sq { font-size: min(46px, 10vw); }
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 520px;
    height: 520px;
    border: 3px solid #e8d5b5;
    border-radius: 4px;
    overflow: hidden;
}

.analysis-board { width: 440px; height: 440px; border-color: #7a9ec0; }
.analysis-board-container { margin-top: 10px; }
.analysis-board-container .coords-bottom { width: 440px; }
.analysis-board-container .coords-left { height: 440px; }

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 46px;
    font-family: 'DejaVu Sans', 'Noto Sans Symbols 2', 'Segoe UI Symbol', 'Arial Unicode MS', sans-serif;
    font-variant-emoji: text;
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: background-color 0.15s;
}

.analysis-board .square { font-size: 38px; }

.square.light { background: #f0d9b5; }
.square.dark { background: #b58863; }
.square.selected { background: #7fc97f !important; }
.square.highlight { background: #aad576 !important; }
.square.last-from { background: rgba(255, 255, 100, 0.4) !important; }
.square.last-to { background: rgba(255, 255, 100, 0.5) !important; }
.square.valid-move::after {
    content: '';
    position: absolute;
    width: 14px; height: 14px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
}
.square.valid-capture { box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.25); }
.square.piece-black { -webkit-text-fill-color: #111; -webkit-text-stroke: 1px #111; color: #111; }
.square.piece-white { -webkit-text-fill-color: #fff; -webkit-text-stroke: 0.5px #333; color: #fff; }
.square:hover { filter: brightness(1.1); }

.coords-bottom {
    display: flex;
    justify-content: space-around;
    padding: 4px 0;
    color: #e8d5b5;
    font-size: 13px;
    font-weight: 600;
    width: 520px;
}

.coords-left {
    position: absolute;
    top: 0;
    left: -20px;
    height: 520px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    color: #e8d5b5;
    font-size: 13px;
    font-weight: 600;
}

/* Sidebar */
.sidebar {
    min-width: 260px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel {
    background: #16213e;
    border-radius: 8px;
    padding: 16px;
    border: 1px solid #2a2a4a;
}

.panel h2 {
    font-size: 0.95rem;
    color: #e8d5b5;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.moves-list {
    max-height: 280px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.9rem;
}
.moves-list::-webkit-scrollbar { width: 6px; }
.moves-list::-webkit-scrollbar-track { background: #1a1a2e; }
.moves-list::-webkit-scrollbar-thumb { background: #4a4a6a; border-radius: 3px; }
.moves-placeholder { color: #666; font-style: italic; }

.move-row {
    display: flex;
    gap: 8px;
    padding: 3px 6px;
    border-radius: 3px;
}
.move-row:hover { background: #2a2a4a; }
.move-number { color: #888; min-width: 30px; text-align: right; }
.move-white, .move-black {
    min-width: 70px; cursor: pointer;
    padding: 1px 4px; border-radius: 3px;
}
.move-white:hover, .move-black:hover { background: #3a3a5a; }
.move-white.current, .move-black.current { background: #e8d5b5; color: #1a1a2e; font-weight: 600; }

/* Input */
.input-group { display: flex; gap: 8px; }
#move-input {
    flex: 1; padding: 10px 14px;
    border: 2px solid #2a2a4a; border-radius: 6px;
    background: #1a1a2e; color: #e0e0e0;
    font-size: 1rem; font-family: 'SF Mono', 'Fira Code', monospace;
    outline: none; transition: border-color 0.2s;
}
#move-input:focus { border-color: #e8d5b5; }

#move-btn {
    padding: 10px 20px; background: #e8d5b5; color: #1a1a2e;
    border: none; border-radius: 6px;
    font-size: 0.95rem; font-weight: 700;
    cursor: pointer; transition: background 0.2s;
}
#move-btn:hover { background: #d4c1a0; }

.input-help { margin-top: 8px; font-size: 0.78rem; color: #666; }
.error { margin-top: 8px; color: #e74c3c; font-size: 0.85rem; min-height: 20px; }

/* Action buttons */
.actions-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions-panel h2 { display: none; }
.actions-panel button {
    padding: 8px 12px; background: #2a2a4a; color: #ccc;
    border: 1px solid #3a3a5a; border-radius: 6px;
    font-size: 0.82rem; cursor: pointer; transition: all 0.2s;
}
.actions-panel button:hover { background: #3a3a5a; color: #fff; }

/* Analysis */
.analysis-head {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; flex-wrap: wrap;
}
.analysis-head h2 { margin-bottom: 0; }
.analysis-actions { display: flex; gap: 6px; align-items: center; }
.analysis-turn { font-size: 0.8rem; color: #aaa; margin-right: 8px; }
.analysis-head button {
    padding: 6px 10px; background: #2a2a4a; color: #ccc;
    border: 1px solid #3a3a5a; border-radius: 6px;
    font-size: 0.8rem; cursor: pointer;
}
.analysis-head button:hover { background: #3a3a5a; color: #fff; }

/* Theory */
.theory-panel { min-width: 460px; }
.theory-sub { color: #888; font-size: 0.78rem; margin-bottom: 10px; }
.theory-opening {
    margin-top: 10px; padding-top: 10px;
    border-top: 1px solid #2a2a4a;
    font-size: 0.82rem; color: #aaa; font-style: italic;
}

.theory-list { display: flex; flex-direction: column; gap: 6px; }
.theory-row {
    display: grid;
    grid-template-columns: 1fr 90px 90px;
    gap: 14px;
    align-items: center;
    padding: 10px 12px;
    background: #1a2342;
    border-radius: 6px;
    border: 1px solid #23305a;
    border-left: 5px solid #7a7a8a;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    transition: background 0.15s;
}
.theory-row:hover { background: #253463; }
.theory-san { color: #e8d5b5; font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.theory-sym { color: #aaa; font-weight: 400; margin-left: 4px; }

/* Rank color accents on the left border */
.theory-row.rank-best { border-left-color: #27ae60; }
.theory-row.rank-ok { border-left-color: #7a7a8a; }
.theory-row.rank-neutral { border-left-color: #5a5a7a; }
.theory-row.rank-weak { border-left-color: #e67e22; }
.theory-row.rank-bad { border-left-color: #c0392b; }

.theory-cp { font-size: 0.88rem; font-weight: 700; text-align: right; }
.theory-cp.cp-good { color: #2ecc71; }
.theory-cp.cp-zero { color: #bbb; }
.theory-cp.cp-bad { color: #e74c3c; }

.theory-check {
    padding: 6px 10px;
    background: #e8d5b5;
    color: #1a1a2e;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 700;
    font-family: inherit;
    transition: background 0.15s;
}
.theory-check:hover { background: #d4c1a0; }
.theory-check:active { background: #b8a487; }

/* Responsive */
@media (max-width: 1200px) {
    .main { grid-template-columns: 1fr; }
    .bottom { grid-template-columns: 1fr; }
    .left-col { flex-direction: row; flex-wrap: wrap; }
    .left-col .panel { flex: 1; min-width: 240px; }
}

@media (max-width: 700px) {
    .board { width: min(520px, 95vw); height: min(520px, 95vw); }
    .coords-bottom { width: min(520px, 95vw); }
    .coords-left { height: min(520px, 95vw); }
    .analysis-board { width: min(440px, 90vw); height: min(440px, 90vw); }
    .analysis-board-container .coords-bottom { width: min(440px, 90vw); }
    .analysis-board-container .coords-left { height: min(440px, 90vw); }
    .square { font-size: min(46px, 10vw); }
    .sidebar { width: 100%; }
}
