:root {
    --bg-primary: #0a0e17;
    --bg-panel: #111827;
    --bg-panel-header: #1e293b;
    --border: #334155;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --accent-delta: #ef4444;
    --accent-cas: #3b82f6;
    --accent-lru: #22c55e;
    --accent-fsm: #3b82f6;
    --accent-observer: #f59e0b;
    --accent-domain: #06b6d4;
    --bit-on: #3b82f6;
    --bit-off: #1e293b;
    --hot: #ef4444;
    --warm: #f59e0b;
    --cold: #8ca0ff;
}

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

html, body {
    background: #000000;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

/* 전체 레이아웃 */
#app {
    display: grid;
    grid-template-rows: 48px 1fr;
    height: 100vh;
    height: 100dvh;
    gap: 1px;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* 상단 컨트롤 바 */
#toolbar {
    background: var(--bg-panel-header);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

#toolbar h1 {
    font-size: 15px;
    font-weight: 600;
    color: var(--accent-domain);
    margin-right: auto;
    white-space: nowrap;
}

#toolbar .tick-display {
    color: var(--text-secondary);
    font-size: 12px;
    min-width: 80px;
}

.btn {
    background: var(--bg-panel);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    transition: background 0.15s;
}

.btn:hover {
    background: var(--bg-panel-header);
}

.btn.active {
    background: var(--accent-cas);
    border-color: var(--accent-cas);
    color: #fff;
}

.btn.delta-fire {
    border-color: var(--accent-delta);
    color: var(--accent-delta);
}

.btn.delta-fire.active {
    background: var(--accent-delta);
    color: #fff;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-dim);
    font-size: 11px;
}

.speed-control input[type="range"] {
    width: 80px;
    accent-color: var(--accent-cas);
}

/* 메인 그리드 */
#panels {
    display: grid;
    grid-template-columns: 1fr 1fr 1.2fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 1px;
    background: var(--border);
    overflow: hidden;
}

/* 패널 공통 */
.panel {
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    background: var(--bg-panel-header);
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.panel-header .indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
}

.panel-header .indicator.active {
    background: var(--accent-delta);
    box-shadow: 0 0 6px var(--accent-delta);
}

.panel-body {
    padding: 10px 12px;
    flex: 1;
    overflow: auto;
    min-height: 0;
}

/* d-ring 패널 */
#panel-dring {
    grid-column: 1;
    grid-row: 1;
}

.dring-visual {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dring-ring {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.dring-bit {
    width: 44px;
    height: 44px;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.dring-bit.on {
    background: var(--bit-on);
    color: #000;
    border-color: var(--bit-on);
    box-shadow: 0 0 8px rgba(34, 211, 238, 0.3);
}

.dring-bit.off {
    background: var(--bit-off);
    color: var(--text-dim);
}

.dring-bit .bit-label {
    font-size: 8px;
    font-weight: 600;
}

.dring-bit .bit-value {
    font-size: 16px;
    font-weight: 700;
}

.dring-nibble-label {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 4px;
}

.dring-seam {
    font-size: 11px;
    color: var(--accent-delta);
    margin-top: 4px;
    padding: 4px 8px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 4px;
}

/* FSM 패널 */
#panel-fsm {
    grid-column: 2;
    grid-row: 1;
}

.fsm-states {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.fsm-state {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border);
    font-size: 12px;
    transition: all 0.3s;
}

.fsm-state.current {
    border-color: var(--accent-fsm);
    background: rgba(168, 85, 247, 0.15);
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.3);
}

.fsm-state .state-label {
    font-size: 9px;
    color: var(--text-dim);
}

.fsm-state .state-binary {
    font-size: 14px;
    font-weight: 700;
}

.fsm-arrow {
    color: var(--text-dim);
    font-size: 16px;
}

.fsm-info {
    margin-top: 10px;
    font-size: 11px;
    color: var(--text-secondary);
}

.fsm-info span {
    color: var(--accent-fsm);
}

/* 파이프라인 패널 */
#panel-pipeline {
    grid-column: 3;
    grid-row: 1;
}

.pipeline-stages {
    display: flex;
    gap: 4px;
    align-items: center;
}

.pipeline-stage {
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 10px;
    border: 1px solid var(--border);
    text-align: center;
    min-width: 60px;
    transition: all 0.2s;
}

.pipeline-stage.current {
    background: var(--accent-cas);
    border-color: var(--accent-cas);
    color: #fff;
}

.pipeline-stage.done {
    background: rgba(34, 197, 94, 0.15);
    border-color: var(--accent-lru);
    color: var(--accent-lru);
}

.pipeline-arrow {
    color: var(--text-dim);
    font-size: 12px;
}

/* 도메인 패널 */
#panel-domain {
    grid-column: 1;
    grid-row: 2;
}

.domain-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.domain-axis {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
}

.domain-axis.on {
    border-color: var(--accent-domain);
    background: rgba(6, 182, 212, 0.1);
}

.domain-axis .axis-name {
    font-size: 11px;
    font-weight: 600;
    width: 80px;
}

.domain-axis .axis-value {
    font-size: 16px;
    font-weight: 700;
}

.domain-pattern {
    margin-top: 8px;
    padding: 6px 8px;
    background: rgba(6, 182, 212, 0.05);
    border-radius: 4px;
    font-size: 11px;
}

/* 엔티티 패널 */
#panel-entity {
    grid-column: 2 / 4;
    grid-row: 2;
}

.entity-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 100%;
    overflow-y: auto;
}

.entity-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    font-size: 11px;
}

.entity-item .entity-id {
    font-weight: 700;
    width: 40px;
}

.entity-item .entity-observer {
    color: var(--accent-observer);
    width: 50px;
}

.entity-item .entity-status {
    font-weight: 600;
    width: 50px;
    text-align: center;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
}

.entity-item .entity-status.HOT  { background: var(--hot); color: #fff; }
.entity-item .entity-status.WARM { background: var(--warm); color: #000; }
.entity-item .entity-status.COLD { background: var(--cold); color: #fff; }

.entity-item .entity-pos {
    color: var(--text-secondary);
    font-family: inherit;
    flex: 1;
}

.entity-item .entity-cost {
    color: var(--accent-delta);
    width: 60px;
    text-align: right;
}

.entity-summary {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-dim);
    display: flex;
    gap: 16px;
}

/* 비용 패널 */
#panel-cost {
    grid-column: 1;
    grid-row: 3;
}

.cost-bars {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cost-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cost-bar .cost-label {
    width: 50px;
    font-size: 11px;
    color: var(--text-secondary);
}

.cost-bar .cost-track {
    flex: 1;
    height: 14px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
}

.cost-bar .cost-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

.cost-bar .cost-fill.read    { background: var(--accent-cas); }
.cost-bar .cost-fill.write   { background: var(--accent-delta); }
.cost-bar .cost-fill.maintain { background: var(--accent-lru); }
.cost-bar .cost-fill.residual { background: var(--accent-fsm); }

.cost-bar .cost-value {
    width: 30px;
    text-align: right;
    font-size: 12px;
    font-weight: 600;
}

.cost-total {
    margin-top: 8px;
    padding: 6px 8px;
    background: rgba(59, 130, 246, 0.05);
    border-radius: 4px;
    font-size: 11px;
    display: flex;
    justify-content: space-between;
}

/* 로그 패널 */
#panel-log {
    grid-column: 2 / 4;
    grid-row: 3;
}

.log-entries {
    display: flex;
    flex-direction: column;
    gap: 1px;
    font-size: 11px;
    font-family: inherit;
    max-height: 100%;
    overflow-y: auto;
}

.log-entry {
    padding: 2px 6px;
    border-radius: 2px;
}

.log-entry.delta  { color: var(--accent-delta); }
.log-entry.cas    { color: var(--accent-cas); }
.log-entry.lru    { color: var(--accent-lru); }
.log-entry.filter { color: var(--accent-observer); }
.log-entry.idle   { color: var(--text-dim); }
.log-entry.system { color: var(--accent-domain); }

/* 스크롤바 */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: var(--bg-panel);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* 반응형 */
@media (max-width: 1200px) {
    #panels {
        grid-template-columns: 1fr 1fr;
    }
    #panel-pipeline { grid-column: 1 / 3; }
    #panel-entity   { grid-column: 1 / 3; }
    #panel-log      { grid-column: 1 / 3; }
}
