:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #1d2433;
  --muted: #5b6475;
  --line: #dde2ea;
  --primary: #2f6fed;
  --primary-text: #ffffff;
  --student: #2f6fed;
  --bot: #ffffff;
  --danger-bg: #fdecec;
  --danger: #c62828;
  --notice-bg: #fff4d6;
  --notice: #8a5a00;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.6;
}

[hidden] { display: none !important; }

button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }

.primary {
  background: var(--primary);
  color: var(--primary-text);
  border: 0;
  border-radius: 10px;
  padding: 12px 22px;
  font-weight: 600;
}
.primary:disabled { opacity: 0.45; }

.status { color: var(--muted); min-height: 1.6em; }

/* ---------- 시작 화면 ---------- */
.start {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 16px;
}
.start h1 { font-size: 28px; margin: 0 0 12px; }
.lead { margin: 0 0 8px; color: var(--muted); }

.role-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 24px 0;
}
.role-card {
  text-align: left;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text);
}
.role-card:hover { border-color: #a9bff5; }
.role-card[aria-checked="true"] {
  border-color: var(--primary);
  background: #eef3ff;
}
.role-name { font-size: 19px; font-weight: 700; }
.role-desc { color: var(--muted); }

#start-btn { width: 100%; padding: 14px; font-size: 18px; }

/* ---------- 토론 화면 ---------- */
.chat {
  max-width: 760px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.chat-heading {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.chat-title { font-weight: 700; }
.chat-issue {
  font-size: 14px;
  line-height: 1.4;
  color: var(--muted);
  word-break: keep-all;
  /* 긴 쟁점은 두 줄까지 보여 주고 나머지는 … */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.exit-btn {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 15px;
}
.exit-btn:hover { color: var(--danger); border-color: #f3b8b8; }
.role-badge {
  background: #eef3ff;
  color: var(--primary);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 15px;
  font-weight: 600;
}

.log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
/* 챗봇: 카톡 프로필처럼 왼쪽에 사진, 위에 이름 */
.bot-row {
  align-self: flex-start;
  display: flex;
  gap: 8px;
  max-width: 85%;
}
.avatar {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 38%;
  object-fit: cover;
  background: #f6f1e4;
  border: 1px solid var(--line);
}
.bot-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}
.bot-name { font-size: 14px; color: var(--muted); }
.bot-row .bubble { max-width: 100%; }

.bubble.bot {
  align-self: flex-start;
  background: var(--bot);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}
.bubble.student {
  align-self: flex-end;
  background: var(--student);
  color: #fff;
  border-top-right-radius: 4px;
}
.bubble.thinking { color: var(--muted); font-style: italic; }

.banner {
  align-self: stretch;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  text-align: center;
}
.banner.warning { background: var(--danger-bg); color: var(--danger); border: 1px solid #f3b8b8; }
.banner.off-topic { background: var(--notice-bg); color: var(--notice); border: 1px solid #f1d58a; }

.system-note {
  align-self: center;
  color: var(--danger);
  font-size: 15px;
}

.composer {
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
#send-form { display: flex; gap: 8px; align-items: flex-end; }
#input {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: 160px;
}
#input:focus { outline: 2px solid #a9bff5; border-color: var(--primary); }
#input:disabled { background: #eef0f4; }

.input-meta {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  color: var(--muted);
  min-height: 1.5em;
  margin-top: 4px;
}
.input-warning { color: var(--danger); }
.counter.over { color: var(--danger); font-weight: 700; }

.ended-notice {
  background: #e8f5e9;
  color: #2e7d32;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  font-weight: 700;
  margin-bottom: 8px;
}

@media (max-width: 520px) {
  .role-cards { grid-template-columns: 1fr; }
  .bubble { max-width: 92%; }
  .bot-row { max-width: 94%; }
  .start { padding-top: 24px; }
}

/* ---------- 교사 화면 ---------- */
.teacher { max-width: 1100px; margin: 0 auto; padding: 24px 16px; font-size: 16px; }
.teacher h1 { font-size: 24px; margin: 0 0 16px; }
.teacher-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.teacher-bar .spacer { flex: 1; }
.ghost {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
}
.login-box {
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-box input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f8f9fc; font-size: 14px; color: var(--muted); white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.id { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.selected { background: #eef3ff; }
.detail { margin-top: 20px; }
.detail h2 { font-size: 18px; margin: 0 0 8px; }
.detail .meta { color: var(--muted); margin-bottom: 12px; font-size: 15px; }
.raw-msg { padding: 10px 12px; border-radius: 10px; margin-bottom: 8px; white-space: pre-wrap; border: 1px solid var(--line); }
.raw-msg.bot { background: var(--surface); }
.raw-msg.student { background: #eef3ff; }
.raw-msg .who { font-size: 13px; color: var(--muted); display: block; margin-bottom: 2px; }
.raw-msg mark { background: #ffe58a; color: inherit; border-radius: 4px; padding: 0 2px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
