:root {
  --bg: #0c0c0d;
  --bar: #151516;
  --line: #2a2a2d;
  --ink: #ecece8;
  --ink-soft: #9a9a96;
  --accent: #d9dbd7;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* 화면 */
.stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.stage.dragging { cursor: grabbing; }
.frame {
  /* 16:9 화면을 스테이지 안에 다 보이게 넣는다. 확대는 이 상자를 당기는 방식(scale). */
  aspect-ratio: 16 / 9;
  width: min(100%, calc((100dvh - var(--bar-h, 64px)) * 16 / 9));
  max-height: 100%;
  transform: scale(var(--zoom, 1));
  transform-origin: 50% 50%;
  will-change: transform;
  position: relative;
  background: #000;
}
/* 캔버스 두 장을 같은 자리에 겹쳐 두고 하나만 보인다(끄는 동안 fast, 멈춘 뒤 view) */
.frame canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
.frame canvas.off { visibility: hidden; }
/* 3DGS 배경: 스테이지 가운데, 그림 상자 밑. 크기는 gs.js 가 정한다 */
.gs {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  background: #000;
  pointer-events: none;
}
.gs[hidden] { display: none; }
.frame.over { background: transparent; }   /* 3DGS 보기: 밑의 스플랫이 비친다 */

/* 정보 표시 */
.info {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  display: grid;
  gap: 3px;
  width: 176px;
  max-width: calc(100% - 24px);
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(12, 12, 13, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font: 12px/1.35 ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  pointer-events: none;      /* 숫자 부분은 끌기를 막지 않는다 */
}
.info[hidden] { display: none; }
.info .row { display: flex; gap: 12px; justify-content: space-between; align-items: center; }
.info .row[hidden] { display: none; }
.info .note { color: #d8b377; white-space: normal; }
.info span { color: var(--ink-soft); }
.info b { font-weight: 500; color: var(--ink); }

/* 정보 표시 안의 조절부: 여기만 손이 닿는다 */
.info .ctl {
  display: grid;
  gap: 5px;
  margin-top: 5px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  pointer-events: auto;
  cursor: default;
}
.info .knob {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 8px;
}
.info .knob output { color: var(--ink); }
.info .knob input {
  grid-column: 1 / -1;
  width: 100%;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.info .seam { display: grid; gap: 4px; }
.info .seam[hidden] { display: none; }
.info .seam button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}
.info .seam button b { color: var(--ink-soft); }
.info .seam button[aria-pressed="true"] { background: #232326; border-color: #4a4a4e; }
.info .seam button[aria-pressed="true"] span,
.info .seam button[aria-pressed="true"] b { color: var(--ink); }

.status {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(12, 12, 13, 0.72);
  color: var(--ink-soft);
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
}
.status[hidden] { display: none; }
.load:not([hidden]) ~ .status { bottom: 62px; }

/* 묶음 그림 진행 표시 */
.load {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 8px 14px 10px;
  border-radius: 10px;
  background: rgba(12, 12, 13, 0.72);
  color: var(--ink-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
}
.load[hidden] { display: none; }
.load-track {
  width: min(240px, 60vw);
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.load-fill { width: 0; height: 100%; background: var(--accent); transition: width 0.15s linear; }

/* 조작 줄 */
.bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--bar);
  border-top: 1px solid var(--line);
}
button, .ghost {
  font: inherit;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.ghost {
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.ghost:hover { border-color: #4a4a4e; }
.ghost.toggle[aria-pressed="true"] { background: #232326; border-color: #4a4a4e; }
.ghost.toggle[aria-pressed="false"] { color: var(--ink-soft); }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.seg button {
  height: 40px;
  padding: 0 14px;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
}
.seg button:first-child { border-left: 0; }
.seg button:hover:not(:disabled) { background: #1e1e20; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #141414; font-weight: 600; }
.seg button:disabled { color: #55555a; cursor: not-allowed; }

.zoom {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  color: var(--ink-soft);
}
.zoom input { width: clamp(110px, 16vw, 200px); accent-color: var(--accent); }
.zoom output {
  min-width: 46px;
  color: var(--ink);
  font: 12px ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 640px) {
  .bar { gap: 8px 8px; padding-left: 10px; padding-right: 10px; }
  .seg { order: -1; width: 100%; }
  .seg button { flex: 1 1 0; padding: 0 6px; }
  .zoom { flex: 1 1 100%; order: 1; }
  .zoom input { flex: 1 1 auto; width: auto; }
  .ghost { flex: 1 1 0; justify-content: center; }
  /* 좁은 화면: 숫자는 왼쪽, 조절부는 오른쪽에 나란히 두어 그림을 덜 가린다 */
  .info {
    font-size: 11px;
    padding: 8px 10px;
    width: auto;
    right: calc(12px + env(safe-area-inset-right));
    max-width: 360px;
    grid-template-columns: minmax(96px, auto) 1fr;
    column-gap: 12px;
    align-content: start;
  }
  .info .row { grid-column: 1; }
  .info .ctl {
    grid-column: 2;
    grid-row: 1 / span 9;
    margin-top: 0;
    padding-top: 0;
    padding-left: 12px;
    border-top: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.12);
    gap: 3px;
  }
  .info .ctl .row { grid-column: auto; }
  .info .knob input { height: 24px; }
  .info .seam button { height: 28px; }
}
