:root {
  --bg: #05060A;
  --ink: #DDE3F0;
  --muted: #8E98AE;
  --hair: rgba(255, 255, 255, 0.14);
  --accent: 34, 230, 255;           /* 현재 도형의 네온 색 (JS가 갱신) */
  --focus: #EAF0FF;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg) radial-gradient(ellipse 80% 55% at 50% 42%, #0D1222 0%, #05060A 72%) no-repeat;
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* 상단: 좌측에 이름과 그 아래 한 줄 문구, 우측에 언어 */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px 24px 0; }
.id { min-width: 0; padding-top: 6px; }
.brand { margin: 0 0 6px; font-size: 1rem; font-weight: 400; letter-spacing: 0.01em; line-height: 1.2; color: var(--ink); }
.tagline { margin: 0; font-size: 0.75rem; font-weight: 300; letter-spacing: 0.03em; line-height: 1.6; color: var(--muted); white-space: pre-line; }

.tools { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.lang { display: inline-flex; gap: 0; flex: none; }
.snd { position: relative; display: grid; place-items: center; min-width: 40px; min-height: 40px; padding: 0; background: none; border: 0; color: var(--muted); cursor: pointer; }
.snd svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.snd[aria-pressed="true"] { color: var(--ink); }
.snd.tip::after { top: calc(100% + 2px); bottom: auto; }
@media (hover: hover) { .snd:hover { color: rgb(var(--accent)); } }
.lang button {
  font: inherit; font-size: 0.6875rem; font-weight: 300; letter-spacing: 0.08em;
  min-height: 40px; min-width: 40px; padding: 0 9px;
  background: none; border: 0; color: var(--muted); cursor: pointer;
  border-bottom: 1px solid transparent;
}
.lang button[aria-pressed="true"] { color: var(--ink); border-bottom-color: rgb(var(--accent)); }

/* 도형 무대: 화면 전체를 쓴다 */
.main { flex: 1; display: flex; flex-direction: column; }
.stage-wrap { flex: 1; display: flex; min-height: clamp(260px, 50dvh, 720px); }
.stage { position: relative; flex: 1; }
.stage canvas {
  /* 모션은 화면 전체를 기준으로 그린다 → 도형의 중심 = 화면 정중앙 (상단 문구·하단 조작은 그 위에 겹쳐 있음) */
  position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0;
  opacity: 1; transition: opacity 0.24s ease;
}
.top, .dock, .note { position: relative; z-index: 1; }
.stage.is-switching canvas,
.stage.is-switching .fire { opacity: 0; }
/* 모닥불 영상: 화면 정중앙에 영상 전체가 보이도록(잘림 없음) 작게 두고, 테두리만 배경으로 살짝 녹인다 */
.fire {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 0;
  width: min(92vw, 1040px, calc(58vh * 16 / 9)); height: auto; aspect-ratio: 16 / 9;
  object-fit: contain; display: block; background: transparent;
  opacity: 1; transition: opacity 0.24s ease;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 9%, #000 93%, transparent 100%), linear-gradient(to right, transparent 0, #000 9%, #000 91%, transparent 100%);
  -webkit-mask-composite: source-in;
          mask-image: linear-gradient(to bottom, transparent 0, #000 9%, #000 93%, transparent 100%), linear-gradient(to right, transparent 0, #000 9%, #000 91%, transparent 100%);
          mask-composite: intersect;
}
.nojs { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; color: var(--muted); }

.note { min-height: 1.3em; margin: 0; padding: 0 24px; text-align: center; font-size: 0.8125rem; color: var(--muted); }

/* 하단: 방향키 모양 조작 */
.dock { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0 16px 18px; transition: opacity 0.6s ease; }

.pad {
  position: relative;
  display: grid;
  gap: 0;                                     /* 버튼 사이 여백 */
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: auto repeat(3, 44px);
  grid-template-areas:
    ".    readout .    "
    ".    up      .    "
    "left center right"
    ".    down    .    ";
}
.up { grid-area: up; }
.down { grid-area: down; }
.left { grid-area: left; }
.right { grid-area: right; }
.center { grid-area: center; }

.pb {
  position: relative; padding: 0; display: grid; place-items: center;
  min-width: 44px; min-height: 44px;
  background: none; border: 0; border-radius: 0; color: var(--muted); cursor: pointer;
  transition: color 0.3s ease, opacity 0.3s ease;
}
.pb svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.pb svg.fill { width: 18px; height: 18px; fill: currentColor; stroke: none; }
.pb[aria-disabled="true"] { opacity: 0.28; cursor: default; }
.play { color: rgb(var(--accent)); }

/* 현재 속도: ^ 위에 작게 */
.readout {
  grid-area: readout; justify-self: center; align-self: end;
  font-size: 0.6875rem; font-weight: 300; letter-spacing: 0.04em; line-height: 1;
  color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 0.5s ease;   /* 평소엔 숨김, 조절할 때만 나타남 */
}
.readout.show { opacity: 1; transition-duration: 0.15s; }

/* 설명이 필요할 때만 뜨는 작은 툴팁 */
.tip::after {
  content: attr(data-label);
  position: absolute; bottom: calc(100% + 2px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 0.75rem; color: var(--ink);
  background: rgba(20, 24, 38, 0.95); border: 1px solid var(--hair);
  padding: 4px 9px; border-radius: 8px; opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease; z-index: 2;
}
/* 위·아래 버튼의 툴팁은 왼쪽 빈 칸으로 */
.up::after, .down::after { bottom: auto; top: 50%; left: auto; right: calc(100% + 2px); transform: translateY(-50%); }
.tip:focus-visible::after { opacity: 1; }
@media (hover: hover) { .tip:hover::after { opacity: 1; } }

/* 하단 오른쪽의 아주 작은 링크: 통계 끄기 / 개인정보 처리방침 */
.foot {
  position: fixed; right: 12px; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 1;
  padding: 0; text-align: right; color: var(--muted); font-size: 0.6875rem; font-weight: 300;
  transition: opacity 0.6s ease;
}
.foot p { margin: 0; }
.link {
  font: inherit; font-size: inherit; color: var(--muted);
  background: none; border: 0; padding: 6px 6px; margin: 0;
  text-decoration: none; cursor: pointer;
}
@media (hover: hover) { .link:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; } }

button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: -4px; border-radius: 8px; }
.lang button:focus-visible { outline-offset: 2px; }

@media (hover: hover) {
  .pb:hover:not([aria-disabled="true"]):not(.play) { color: rgb(var(--accent)); }
  .lang button:hover:not([aria-pressed="true"]) { color: var(--ink); }
}

/* 전체 화면: 도형과 조작만 남기고, 잠시 후 조작도 흐려진다 */
body.is-focus .top,
body.is-focus .note,
body.is-focus .foot { display: none; }
body.is-focus .dock { padding-top: 8px; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
/* 5초간 입력이 없으면: 조작 패널, 상단 문구·언어, 커서를 서서히 숨긴다. 움직이거나 누르면 다시 나타난다. */
.top { transition: opacity 0.6s ease; }
body.is-idle .dock,
body.is-idle .top,
body.is-idle .foot { opacity: 0; pointer-events: none; }
body.is-idle, body.is-idle * { cursor: none !important; }

@media (max-width: 640px) {
  .top { padding: 12px 16px 0; }
  .dock { padding-bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
