/* 디자인 토큰(assets/디자인/토큰.json -> tokens.css) 단일 기준. AI 티(그라데이션·보라·이모지·검은 그림자) 금지 */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--r-badge);
  background: var(--primary-soft);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}
.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.stat-pill {
  padding: 4px 10px;
  border-radius: var(--r-badge);
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 16px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 20px;
  min-width: 0;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.muted {
  color: var(--text-muted);
  font-size: 13px;
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 280px;
  max-height: 460px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: hidden;
}
#avatar-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.stage-status-bar {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-btn);
  font-size: 13px;
}
.mode-tag {
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}
.mouth-meter-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 100px;
}
.mouth-meter {
  width: 68px;
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-badge);
  overflow: hidden;
}
.mouth-meter-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 60ms linear;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: var(--r-btn);
  cursor: pointer;
  line-height: 1.25;
  word-break: keep-all;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn:hover { background: var(--bg); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn-dark {
  background: var(--text);
  color: #ffffff;
  border-color: var(--text);
}
.btn-soft {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}
.btn-danger {
  background: var(--down-soft);
  color: var(--down);
  border-color: var(--down);
}
.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.field input, .field select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}

.notice-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--r-btn);
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.notice-box.warn {
  background: var(--down-soft);
  border-color: var(--down);
  color: var(--down);
}
.notice-box.info {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.transcript-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px 0;
}
.msg {
  padding: 10px 12px;
  border-radius: var(--r-btn);
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 14px;
  overflow-wrap: anywhere;
}
.msg.tutor {
  background: var(--primary-soft);
  border-color: var(--primary-4);
}
.msg-role {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.memory-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 190px;
  overflow-y: auto;
}
.memory-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.kpi {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-btn);
  background: var(--bg);
}
.kpi-val {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
}

.footer {
  max-width: 1120px;
  margin: 8px auto 32px;
  padding: 12px 16px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--line);
}
.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

dialog.policy-dialog {
  width: min(640px, calc(100vw - 24px));
  max-height: 82vh;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
}
dialog.policy-dialog::backdrop {
  background: rgba(20, 20, 30, 0.45);
}
.policy-body {
  font-size: 14px;
  overflow-y: auto;
  max-height: 58vh;
}
.policy-body h3 { margin: 14px 0 6px; font-size: 15px; }
.policy-body p, .policy-body li { margin: 4px 0; }

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }
  .card { padding: 16px; }
  .stage-wrap { aspect-ratio: 1 / 1; min-height: 260px; }
  .form-grid { grid-template-columns: 1fr; }
  .controls .btn { flex: 1 1 calc(50% - 4px); text-align: center; }
}
