/* ==========================================================================
   SILICON PLACEMENT WORKBENCH — Strict Engineering EDA Theme (Scaled Up)
   Reference: Cadence Innovus / Synopsys ICC2 / KiCad / VS Code
   Clean text-only interface (Readable Monolithic Monospace)
   ========================================================================== */

:root {
    /* --- Workbench Theme Surfaces --- */
    --bg-app:           #0d1117;   /* 워크스페이스 최하단 */
    --bg-inset:         #080b0f;   /* 캔버스 및 인셋 리드아웃 */
    --bg-panel:         #161b22;   /* 도킹 사이드바 및 인스펙터 */
    --bg-raised:        #1c2128;   /* 리스트 호버 */
    --bg-control:       #21262d;   /* 툴바 버튼 / 헤더 */
    --bg-control-hover: #292e36;
    --bg-selected:      #1a2532;   /* 선택된 스텝 */

    /* --- Structural Borders (Strict 1px Grid) --- */
    --border:           #2a313d;
    --border-strong:    #3a424f;
    --border-hover:     #4a5361;
    --divider:          #1f252e;

    /* --- Typography Colors --- */
    --text-strong:      #e6edf3;
    --text:             #c9d1d9;
    --text-dim:         #8b949e;
    --text-mute:        #6e7681;

    /* --- Instrumentation Status Accents (Desaturated Matte) --- */
    --accent-cyan:      #4fb3bf;
    --accent-amber:     #d4a23a;
    --accent-green:     #5fae6a;
    --accent-red:       #d9625b;

    /* --- Dimensions --- */
    --font-mono: "JetBrains Mono", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ==========================================================================
   Base Layout
   ========================================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    font-family: var(--font-mono);
    background-color: var(--bg-app);
    color: var(--text);
    display: flex;
    height: 100vh;
    overflow: hidden;
    font-size: 13px; /* 🚨 11px -> 13px 상향 조정 */
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

::selection { background: #264f78; color: var(--text-strong); }
:focus-visible { outline: 1px solid var(--accent-cyan); outline-offset: 1px; }

/* Custom EDA Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-panel); }
::-webkit-scrollbar-thumb { background: var(--bg-control); border: 1px solid var(--border); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ==========================================================================
   Left Panel: Execution Pipeline & Layers (Docked)
   ========================================================================== */
#sidebar {
    width: 420px; min-width: 420px; /* 🚨 폰트 확대에 맞춰 380px -> 420px 살짝 확장 */
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 14px; gap: 12px;
    z-index: 10;
    overflow-y: auto;
}

.header {
    padding: 2px 2px 10px;
    border-bottom: 1px solid var(--border);
}
.header h1 {
    font-size: 14px; font-weight: 700; /* 🚨 12px -> 14px */
    color: var(--text-strong);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.header p {
    font-size: 11.5px; color: var(--text-mute); /* 🚨 10px -> 11.5px */
    margin-top: 3px; letter-spacing: 0.02em;
}

/* --- Execution Steps Tree --- */
.step-list {
    display: flex; flex-direction: column;
    background: var(--bg-inset);
    border: 1px solid var(--border);
}
.step-card {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-left: 3px solid transparent; /* 🚨 가시성 위해 2px -> 3px */
    padding: 9px 12px; /* 🚨 여백 살짝 증가 */
    cursor: pointer;
    transition: background-color 0.06s linear, border-left-color 0.06s linear;
}
.step-card:last-child { border-bottom: none; }
.step-card:hover {
    background: var(--bg-raised);
    border-left-color: var(--border-hover);
}
.step-card.active {
    background: var(--bg-selected);
    border-left-color: var(--accent-cyan);
}
.step-card-title {
    font-size: 12.5px; font-weight: 700; color: var(--text); /* 🚨 11px -> 12.5px */
    letter-spacing: 0.02em;
}
.step-card.active .step-card-title { color: var(--text-strong); }
.step-card-hpwl {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 13px; font-weight: 700; color: var(--accent-cyan); /* 🚨 11px -> 13px 볼드화 */
    margin-top: 3px;
}
.step-card-hpwl span { color: var(--accent-green); font-size: 11.5px; font-weight: 600; } /* 🚨 10px -> 11.5px */
.step-card-desc {
    font-size: 11px; color: var(--text-mute); /* 🚨 9.5px -> 11px 가독성 확보 */
    margin-top: 3px; line-height: 1.4;
}

/* --- Layer Visibility (Property Box) --- */
.options-box {
    background: var(--bg-inset);
    border: 1px solid var(--border);
    display: flex; flex-direction: column;
}
.toggle-label {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; /* 🚨 터치/클릭 편의성 증가 */
    border-bottom: 1px solid var(--divider);
    font-size: 12px; font-weight: 500; /* 🚨 10.5px -> 12px */
    color: var(--text);
    cursor: pointer;
}
.toggle-label:last-child { border-bottom: none; }
.toggle-label:hover { background: var(--bg-raised); }
.toggle-label-left { display: flex; align-items: center; gap: 10px; }

/* Flat CAD Checkbox */
.toggle-label input {
    -webkit-appearance: none; appearance: none;
    width: 14px; height: 14px; margin: 0; /* 🚨 12px -> 14px */
    background: var(--bg-app);
    border: 1px solid var(--border-strong);
    border-radius: 0;
    cursor: pointer;
}
.toggle-label input:hover { border-color: var(--text-dim); }
.toggle-label input:checked {
    background: var(--accent-amber);
    border-color: var(--accent-amber);
    box-shadow: inset 0 0 0 2px var(--bg-app);
}

.badge {
    background: var(--bg-control);
    color: var(--accent-amber);
    border: 1px solid var(--border);
    font-size: 10.5px; font-weight: 600; /* 🚨 9px -> 10.5px */
    line-height: 18px; padding: 0 6px;
    letter-spacing: 0.04em; text-transform: uppercase;
}

/* --- Metric Readout --- */
.metric-card {
    background: var(--bg-inset);
    border: 1px solid var(--border);
    padding: 10px 12px;
}
.metric-title {
    font-size: 10.5px; font-weight: 700; /* 🚨 9px -> 10.5px */
    color: var(--text-mute);
    text-transform: uppercase; letter-spacing: 0.06em;
}
.metric-val {
    font-size: 19px; font-weight: 700; /* 🚨 16px -> 19px 핵심 수치 강조 */
    color: var(--accent-cyan);
    margin-top: 4px; letter-spacing: -0.01em;
}
.metric-meters {
    font-size: 12px; font-weight: 600; /* 🚨 10.5px -> 12px */
    color: var(--text-dim);
    margin-top: 2px;
}

/* ==========================================================================
   Viewport (Silicon Core Area)
   ========================================================================== */
#viewport {
    flex: 1; position: relative;
    width: 100%; height: 100%;
    background-color: var(--bg-inset);
    overflow: hidden;
}
canvas#siliconCanvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
canvas#siliconCanvas:active { cursor: grabbing; }

/* ==========================================================================
   QA & Legality Panel (Docked Inspector Frame)
   ========================================================================== */
#qa-container {
    position: absolute; top: 12px; right: 12px; width: 370px; /* 🚨 330px -> 370px */
    z-index: 25; font-size: 12px;
    display: none;
}

#btn-run-qa {
    width: 100%; height: 32px; padding: 0 12px; /* 🚨 28px -> 32px */
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-control);
    border: 1px solid var(--border-strong);
    color: var(--text-strong);
    font-size: 12px; font-weight: 700; /* 🚨 10.5px -> 12px */
    letter-spacing: 0.05em; text-transform: uppercase;
    cursor: pointer;
    transition: background-color 0.06s linear, border-color 0.06s linear;
}
#btn-run-qa:hover {
    background: var(--bg-control-hover);
    border-color: var(--border-hover);
}
#btn-run-qa:active { background: var(--bg-app); }

#qa-progress-box {
    display: none;
    flex-direction: column; gap: 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 12px;
}
.progress-bar-bg {
    width: 100%; height: 6px;
    background: var(--bg-inset);
    border: 1px solid var(--border);
    overflow: hidden;
}
.progress-bar-fill {
    width: 0%; height: 100%;
    background: repeating-linear-gradient(90deg, var(--accent-cyan) 0 6px, transparent 6px 8px);
    transition: width 0.38s ease-out;
}

#qa-report-box {
    display: none;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 0;
}
.qa-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-control);
    border-bottom: 1px solid var(--border);
}
.qa-title {
    font-size: 12px; font-weight: 700; /* 🚨 10.5px -> 12px */
    color: var(--text-strong);
    letter-spacing: 0.05em; text-transform: uppercase;
}
.qa-grid {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    border-bottom: 1px solid var(--border);
}
.qa-item {
    background: var(--bg-inset);
    padding: 8px 10px;
}
.qa-item-title {
    font-size: 10px; font-weight: 600; /* 🚨 9px -> 10px */
    color: var(--text-mute);
    text-transform: uppercase; letter-spacing: 0.04em;
}
.qa-item-value {
    font-size: 13.5px; font-weight: 700; /* 🚨 12px -> 13.5px 수치 명확화 */
    color: var(--text-strong);
    margin-top: 2px;
}
.qa-item-value.highlight-green  { color: var(--accent-green); }
.qa-item-value.highlight-yellow { color: var(--accent-amber); }

.qa-footer {
    font-size: 10.5px; line-height: 1.45; /* 🚨 9px -> 10.5px 주석 가독성 확보 */
    color: var(--text-mute);
    padding: 10px 12px;
}

.btn-recheck {
    width: calc(100% - 24px); height: 26px; margin: 0 12px 12px; /* 🚨 22px -> 26px */
    background: var(--bg-control);
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
    font-size: 11px; font-weight: 600; /* 🚨 9.5px -> 11px */
    letter-spacing: 0.04em; text-transform: uppercase;
    cursor: pointer;
}
.btn-recheck:hover {
    background: var(--bg-control-hover);
    border-color: var(--border-hover);
    color: var(--text-strong);
}

/* ==========================================================================
   Wire HUD (Telemetry Inspector Frame)
   ========================================================================== */
#wire-hud-panel {
    position: absolute; top: 12px; left: 12px; width: 340px; /* 🚨 300px -> 340px */
    display: none; flex-direction: column;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-top: 2px solid var(--accent-amber);
    padding: 0;
    z-index: 20;
}
.hud-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-control);
    border-bottom: 1px solid var(--border);
}
.hud-title {
    font-size: 11.5px; font-weight: 700; /* 🚨 10px -> 11.5px */
    color: var(--text-strong);
    letter-spacing: 0.05em; text-transform: uppercase;
}
.hud-body {
    padding: 8px 12px;
    display: flex; flex-direction: column; gap: 4px;
}
.hud-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 3px 0;
    border-bottom: 1px solid var(--divider);
    font-size: 11.5px; /* 🚨 10px -> 11.5px */
}
.hud-row:last-child { border-bottom: none; }
.hud-label { color: var(--text-dim); }
.hud-value {
    color: var(--text-strong); font-weight: 600;
    text-align: right;
}
.hud-value-cyan { color: var(--accent-cyan); font-weight: 600; }

/* ==========================================================================
   Bottom View Controls (Status Widget)
   ========================================================================== */
#nav-controls {
    position: absolute; bottom: 10px; right: 10px;
    display: flex; gap: 10px; align-items: center;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 4px 8px;
    font-size: 11px; color: var(--text-dim); /* 🚨 10px -> 11px */
    z-index: 20;
}
#btn-reset-view {
    height: 22px; padding: 0 8px; /* 🚨 18px -> 22px */
    background: var(--bg-control);
    border: 1px solid var(--border-strong);
    color: var(--text);
    font-size: 10.5px; font-weight: 600; /* 🚨 9.5px -> 10.5px */
    letter-spacing: 0.04em; text-transform: uppercase;
    cursor: pointer;
}
#btn-reset-view:hover {
    background: var(--bg-control-hover);
    color: var(--text-strong);
}

/* ==========================================================================
   샌드박스 모바일 & 태블릿 최적화 (상하 스플릿 레이아웃)
   ========================================================================== */
@media (max-width: 840px) {
  body {
    flex-direction: column !important; /* 가로 배치를 세로 배치로 전환 */
    height: 100vh !important;
    overflow: hidden !important;
  }

  /* 상단: 칩 캔버스 영역 */
  #viewport {
    height: 52vh !important;
    min-height: 52vh !important;
    order: 1 !important; /* 화면 위쪽에 캔버스 배치 */
    border-bottom: 1px solid var(--border) !important;
  }

  /* 하단: 컨트롤러 사이드바 영역 */
  #sidebar {
    width: 100% !important;
    min-width: 100% !important;
    height: 48vh !important;
    order: 2 !important; /* 화면 아래쪽에 컨트롤러 배치 */
    border-right: none !important;
    padding: 12px 14px !important;
    overflow-y: auto !important;
    gap: 8px !important;
  }

  /* 모바일용 패널 크기 축소 */
  #qa-container {
    top: 6px !important;
    right: 6px !important;
    width: 280px !important;
  }
  #wire-hud-panel {
    top: 6px !important;
    left: 6px !important;
    width: 240px !important;
  }
  #nav-controls {
    bottom: 6px !important;
    right: 6px !important;
    font-size: 9px !important;
    padding: 2px 6px !important;
  }
  #nav-controls span:first-child {
    display: none !important; /* 공간 절약을 위해 안내문구 숨김 */
  }

  .step-card {
    padding: 6px 8px !important;
  }
  .step-card-title {
    font-size: 10.5px !important;
  }
}