/* 로봉 시뮬레이터: 어두운 로봇 화면 + 밝은 패널. 바깥 글꼴·스크립트·그림 없이 이 파일만으로 그린다. */

:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #1b222b;
  --muted: #566170;
  --line: #d5dce4;
  --soft: #f3f6f9;
  --accent: #14708f;
  --accent-soft: #e2f2f7;
  --on: #1b7f46;
  --off: #b3372b;
  --warn-bg: #fff2cc;
  --warn-ink: #6b4a00;
  --focus: #0b63c5;

  --stage: #12161b;
  --stage-line: #2a323c;
  --stage-ink: #e1e8f0;
  --stage-muted: #a3afbd;
  --stage-focus: #8ec5ff;

  --radius: 12px;
  --mono: Consolas, "D2Coding", "Courier New", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}

code, .mono { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--soft); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

h1, h2, h3, p { margin: 0; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.stage :focus-visible { outline-color: var(--stage-focus); }

/* ---- 머리말 ---- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.badges { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.badge { font-size: 13px; color: var(--muted); }
.badge strong { color: var(--ink); font-family: var(--mono); }
.admin-link { font-size: 13px; font-weight: 600; color: var(--ink); border: 1px solid currentColor; border-radius: 999px; padding: 3px 10px; text-decoration: none; }
.admin-link[hidden] { display: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  font-size: 13px;
  white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill[data-state="on"] { color: var(--on); border-color: #a9d6bb; background: #eaf7ef; }
.pill[data-state="off"] { color: var(--off); border-color: #e4b4ae; background: #fbeeec; }

/* ---- 불러오는 중 · 오류 ---- */
.boot { padding: 48px 24px; text-align: center; color: var(--muted); }
.boot.error { color: var(--off); }
.load-error {
  max-width: 720px;
  margin: 32px auto;
  padding: 18px 22px;
  background: #fff;
  border: 2px solid var(--off);
  border-radius: var(--radius);
}
.load-error h2 { font-size: 17px; color: var(--off); margin-bottom: 8px; }
.load-error p + p { margin-top: 8px; }

/* ---- 배치 ---- */
.layout {
  display: grid;
  grid-template-columns: fit-content(62%) minmax(360px, 1fr);
  gap: 20px;
  align-items: start;
  max-width: 1680px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

/* ---- 왼쪽: 로봇 화면과 대화 (어두운 영역) ---- */
.stage {
  position: sticky;
  top: 12px;
  min-width: 0;
  max-height: calc(100vh - 24px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px 14px;
  background: var(--stage);
  color: var(--stage-ink);
  border-radius: 18px;
}

.bezel {
  align-self: center;
  padding: 12px;
  background: #05070a;
  border: 1px solid var(--stage-line);
  border-radius: 22px;
  box-shadow: inset 0 0 0 2px #0d1116;
}
#screen {
  display: block;
  background: #000;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

.stage-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--stage-muted); font-size: 13px; }
.stage-bar label { color: var(--stage-ink); }
.stage-hint { flex: 1 1 auto; }

.stage select,
.stage input[type="text"] {
  min-height: 36px;
  padding: 4px 10px;
  background: #0b0f14;
  color: var(--stage-ink);
  border: 1px solid #3a4553;
  border-radius: 8px;
  font: inherit;
}
.stage input[type="text"]::placeholder { color: #7f8b99; }

.talk { display: flex; flex-direction: column; gap: 10px; }

.ptt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  min-height: 58px;
  padding: 7px 14px;
  background: #1b7a99;
  color: #fff;
  border: 0;
  border-radius: 14px;
  font: inherit;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.ptt:hover { background: #218aac; }
.ptt-main { font-size: 18px; font-weight: 700; }
.ptt-sub { font-size: 12px; color: #e6f4f9; }
.ptt[aria-pressed="true"] { background: #c93c3c; }

.dev-text { display: flex; flex-direction: column; gap: 6px; }
.dev-text label { font-size: 13px; color: var(--stage-muted); }
.dev-row { display: flex; gap: 8px; }
.dev-row input { flex: 1; min-width: 0; }
.dev-row button {
  min-height: 36px;
  padding: 4px 16px;
  background: #2a3541;
  color: var(--stage-ink);
  border: 1px solid #3a4553;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.dev-row button:hover { background: #34414f; }

.forget { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.forget .hint { margin: 0; font-size: 12px; color: var(--stage-muted); }
.forget button {
  min-height: 36px;
  padding: 4px 14px;
  background: #2a3541;
  color: var(--stage-ink);
  border: 1px solid #3a4553;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.forget button:hover { background: #34414f; }

.notice {
  padding: 8px 12px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 8px;
  font-size: 13px;
}

.stage .hint { color: var(--stage-muted); }
.speech { flex-wrap: wrap; gap: 4px 8px; }
.speech .hint { margin: 0; }
.voice { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 13px; }
.voice label { display: inline-flex; align-items: center; gap: 6px; }
.voice select { max-width: 220px; font: inherit; }
.voice input[type="range"] { width: 110px; accent-color: var(--accent); }
.voice output { min-width: 2.5em; font-variant-numeric: tabular-nums; }
.voice button {
  padding: 4px 14px;
  background: #2a3541;
  color: var(--stage-ink);
  border: 1px solid #3a4553;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.voice .hint { flex-basis: 100%; margin: 0; font-size: 12px; color: var(--stage-muted); }

/* ---- 오른쪽: 밝은 패널 ---- */
.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  min-width: 0;
  align-items: start;
}
.panel {
  min-width: 0;
  padding: 16px 18px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.panel-wide { grid-column: 1 / -1; }
.panel h2 { font-size: 16px; margin-bottom: 8px; }
.panel h3 { font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.empty { color: var(--muted); font-size: 13px; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

button {
  font: inherit;
}
.panel button:not(.preset) {
  min-height: 34px;
  padding: 3px 14px;
  background: var(--soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.panel button:not(.preset):hover { background: #e8edf2; }

input[type="range"] { accent-color: var(--accent); min-width: 0; }
.panel input[type="text"] {
  min-height: 34px;
  padding: 3px 10px;
  border: 1px solid #b7c1cc;
  border-radius: 8px;
  font: inherit;
}

.field {
  display: grid;
  grid-template-columns: 6em minmax(0, 1fr) 3.6em;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.field > .check { grid-column: 1 / -1; }
.field > input[type="text"] { grid-column: 2 / -1; }
.field output { font-family: var(--mono); text-align: right; }

/* 표정 공장 */
.mode {
  display: inline-block;
  margin-bottom: 8px;
  padding: 2px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
}
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; margin-bottom: 4px; }
.current { font-size: 13px; color: var(--muted); }
.current output { color: var(--ink); font-weight: 700; }

.preset-grid { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 14px; }
.preset-group h3 { margin: 0 0 4px; }
.preset-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; }
.preset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  padding: 6px 10px 7px;
  background: var(--soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
}
.preset:hover { background: #e8edf2; }
.preset .pid { font-family: var(--mono); font-weight: 700; color: var(--accent); line-height: 1.3; }
.preset .pname { font-size: 15px; line-height: 1.3; }
.preset .pkey { font-family: var(--mono); font-size: 11px; color: var(--muted); line-height: 1.3; }
.preset[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.gaze { margin: 0 0 12px; padding: 6px 12px 10px; border: 1px solid var(--line); border-radius: 8px; }
.gaze legend { padding: 0 6px; font-size: 13px; color: var(--muted); }
.gaze .field { grid-template-columns: 4em minmax(0, 1fr) 2.4em; max-width: 420px; }

.margins summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
.table-scroll { max-height: 264px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 4px 10px; border-bottom: 1px solid #e6ebf0; }
thead th { position: sticky; top: 0; background: var(--soft); text-align: center; z-index: 1; }
thead th:first-child, tbody th { text-align: left; }
tbody th { font-weight: 400; white-space: nowrap; }
tbody td { text-align: center; font-family: var(--mono); }
td.zero { background: var(--warn-bg); color: var(--warn-ink); font-weight: 700; }
.variant { color: var(--muted); font-size: 12px; }

/* 연결 · 계측 */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 0; align-items: center; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv dd.mono { font-size: 12px; }
.kv dd a { color: var(--accent); font-weight: 700; }
.kv dd a[aria-current="page"] { color: var(--ink); text-decoration: none; cursor: default; }
.metrics dd { font-family: var(--mono); text-align: right; }

/* 몸짓 */
.motion-list { list-style: none; margin: 0; padding: 0; }
.motion-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-bottom: 1px solid #e6ebf0; }
.motion-item:first-child { background: var(--accent-soft); font-weight: 700; border-radius: 8px; }
.motion-icon { width: 1.8em; text-align: center; font-size: 18px; color: var(--accent); }
.motion-time { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 12px; font-weight: 400; }

/* ---- 좁은 화면 ---- */
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px; }
  .stage { position: static; max-height: none; }
  .topbar { padding: 12px; }
}
