/* Gateway 그래픽 계층 · site.css 토큰만 사용 · 외부 자원 없음 · CSP 준수 */

@view-transition {
  navigation: auto;
}

@property --gw-progress {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}

/* ── WebGL 배경 호스트 및 CSS 격자 대체 ── */
.gw-scan-host {
  position: relative;
  isolation: isolate;
}
.gw-scan-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  display: block;
}
.gw-scan-fallback {
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--line) 55%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--line) 55%, transparent) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* ── 공통 캔버스 스테이지 & 도면 프레임 ── */
.gw-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}
.gw-aperture,
.gw-flow,
.gw-tree,
.gw-bench {
  container-type: inline-size;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

/* 코너 십자 표식 (광학 도면 언어) */
.gw-aperture::before,
.gw-flow::before,
.gw-tree::before {
  content: "+";
  position: absolute;
  top: 4px;
  right: 8px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-3);
  pointer-events: none;
  z-index: 2;
}

.gw-aperture-stage {
  width: 100%;
  aspect-ratio: 6 / 5;
  min-height: 300px;
  max-height: 460px;
}
.gw-flow-stage {
  width: 100%;
  height: 360px;
}
.gw-tree-stage {
  width: 100%;
  height: 400px;
}

/* ── 공통 컨트롤 바 & 키보드 버튼 ── */
.gw-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.gw-btn,
.gw-chip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 4px 11px;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}
.gw-btn:hover,
.gw-chip-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.gw-chip-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.gw-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.gw-range-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--ink-2);
  margin-left: auto;
}
.gw-range-wrap input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
}
.gw-mono-readout {
  font-size: 0.82rem;
  color: var(--ink-3);
}
.gw-readout {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--ground-2);
  color: var(--ink-2);
  font-size: 0.86rem;
  min-height: 42px;
}

/* ── 라이브 워크벤치 (preview-bench.js) ── */
.gw-bench-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 0.82rem;
  color: var(--ink-3);
}
.gw-seg {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--ground-2);
}
.gw-seg-item {
  position: relative;
  cursor: pointer;
}
.gw-seg-item input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}
.gw-seg-item span {
  display: block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-2);
}
.gw-seg-item input:checked + span {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.gw-seg-item input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.gw-bench-body {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.15fr);
}
.gw-bench-list {
  border-right: 1px solid var(--line);
  display: grid;
  align-content: start;
}
.gw-bench-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.87rem;
  cursor: pointer;
}
.gw-bench-row:last-child {
  border-bottom: 0;
}
.gw-bench-row:hover {
  background: var(--surface-2);
}
.gw-bench-row.is-sel {
  background: var(--accent-soft);
}
.gw-bench-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gw-bench-detail {
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
  position: relative;
}
.gw-detail-head {
  display: grid;
  gap: 8px;
}
.gw-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.gw-stream {
  display: grid;
  gap: 8px;
}
.gw-msg {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.87rem;
  background: var(--surface);
}
.gw-msg small {
  display: block;
  color: var(--ink-3);
  margin-bottom: 3px;
}
.gw-msg.is-internal {
  background: var(--surface-2);
  border-style: dashed;
}
.gw-msg-pending {
  border-color: var(--coral);
  background: var(--coral-soft);
}

/* :has()로 외부 시점 선택 시 내부 메모 마스킹 해칭 강조 */
.gw-bench:has(input[value="external"]:checked) .gw-msg.is-internal {
  background: repeating-linear-gradient(
    -45deg,
    var(--ground-2),
    var(--ground-2) 6px,
    var(--surface-2) 6px,
    var(--surface-2) 12px
  );
  border-color: var(--line-strong);
}
.gw-redacted {
  color: var(--ink-3);
  font-size: 0.82rem;
}
.gw-watermark {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 0.72rem;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}

/* 네이티브 Popover 스타일 */
.gw-popover {
  max-width: min(360px, calc(100vw - 32px));
  padding: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.gw-popover::backdrop {
  background: rgba(10, 14, 28, 0.35);
}
.gw-popover h4 {
  margin: 0 0 8px;
  font-size: 1rem;
}
.gw-popover p {
  font-size: 0.88rem;
  color: var(--ink-2);
}
.gw-pop-meta {
  margin: 10px 0 14px;
  padding: 8px 10px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--ink);
}

/* ── Container Queries: 컴포넌트 폭 기준 반응형 (375px 안전) ── */
@container (max-width: 620px) {
  .gw-bench-body {
    grid-template-columns: 1fr;
  }
  .gw-bench-list {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .gw-flow-stage {
    height: 410px;
  }
  .gw-tree-stage {
    height: 360px;
  }
  .gw-range-wrap {
    margin-left: 0;
  }
}

/* ── CSS Scroll-Driven Animations (점진적 향상 + reduced-motion 보호) ── */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    @keyframes gw-stage-enter {
      from {
        opacity: 0.25;
        transform: translateY(10px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }
    .stages li {
      animation: gw-stage-enter linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 28%;
    }
  }
}

/* ── 아이콘 스프라이트 공용 크기 ── */
.gw-icon {
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--accent);
}

/* ── @property 호버 진행선 (약속 카드) ── */
.promise {
  border-radius: 6px;
  transition: --gw-progress 0.35s ease;
  background-image: linear-gradient(
    to right,
    var(--accent-soft) 0%,
    var(--accent-soft) var(--gw-progress),
    transparent var(--gw-progress)
  );
  background-size: 100% 3px;
  background-repeat: no-repeat;
  background-position: bottom left;
}
.promise:hover,
.promise:focus-within {
  --gw-progress: 100%;
}

@media (prefers-reduced-motion: reduce) {
  .promise {
    transition: none;
  }
}

/* ── 검토 반영: 조리개 조작 줄 한 줄 · 고객 시점 가림 글 대비 ── */
.gw-aperture-bar { justify-content: space-between; flex-wrap: wrap; row-gap: 8px; }
@container (max-width: 420px) {
  .gw-aperture-bar .gw-range-wrap input[type="range"] { width: 92px; }
}
.gw-redacted { color: var(--ink-2); }
.gw-popover-legacy { position: fixed; inset: auto 16px 16px auto; max-width: min(360px, calc(100vw - 32px)); z-index: 30; }
