:root {
  --bg: #212121;
  --bg-elevated: #2f2f2f;
  --border: #3d3d3d;
  --text: #ececec;
  --text-dim: #9a9a9a;
  --accent: #ffffff;
  --toggle-active: #4d8dff;
  --user-bubble: #2f2f2f;
  --error: #ff6b6b;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", Helvetica, Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  font-weight: 600;
  font-size: 15px;
}

.model {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}

.new-chat {
  margin-left: auto;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.new-chat:hover { background: var(--bg-elevated); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  display: flex;
}

.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.bubble {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 85%;
}

.bubble-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
  font-size: 15px;
  padding: 10px 14px;
  border-radius: 14px;
}

.bubble-text:empty { display: none; }

.msg.user .bubble-text {
  background: var(--user-bubble);
  border: 1px solid var(--border);
}

.msg.assistant .bubble-text {
  background: transparent;
  padding-left: 0;
}

.bubble-image {
  max-width: 100%;
  max-height: 360px;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
}

.bubble.pending .bubble-text::after {
  content: "▍";
  animation: blink 1s steps(1) infinite;
  margin-left: 2px;
}

.bubble-text.error { color: var(--error); }

@keyframes blink { 50% { opacity: 0; } }

.attachment-chip {
  max-width: 760px;
  width: calc(100% - 32px);
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.attachment-chip img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 6px;
}

.attachment-chip .chip-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip .chip-remove {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
}
.attachment-chip .chip-remove:hover { color: var(--text); }

.composer {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 760px;
  width: calc(100% - 32px);
  margin: 0 auto 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px 10px;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  max-height: 200px;
  line-height: 1.4;
  padding: 8px 4px;
}

.composer textarea::placeholder { color: var(--text-dim); }

.icon-btn {
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--border); color: var(--text); }

.icon-btn.toggle.active {
  color: #fff;
  background: var(--toggle-active);
}
.icon-btn.toggle.active:hover { background: var(--toggle-active); }

.send {
  background: var(--accent);
  color: #111;
  border: none;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.send:hover { opacity: 0.85; }

.disclosure {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin: 0 0 14px;
}

@media (max-width: 600px) {
  .bubble { max-width: 92%; }
}

/* --- views ---------------------------------------------------------------- */

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.center-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 16px;
  text-align: center;
}
.center-screen h1 { margin: 0; font-size: 22px; }
.center-screen p { margin: 0; color: var(--text-dim); }
.dead-end-icon { font-size: 40px; }

/* --- name picker ------------------------------------------------------------ */

.picker {
  flex: 1;
  overflow-y: auto;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 16px;
}

.picker-title { margin: 0 0 4px; font-size: 24px; text-align: center; }
.picker-hint { margin: 0 0 20px; text-align: center; color: var(--text-dim); }
.picker-notice { margin: 0 auto 16px; max-width: 420px; text-align: center; color: var(--error); font-size: 14px; }

.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.student-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}
.student-card:hover,
.student-card:focus-visible { border-color: var(--text-dim); outline: none; }
.student-card.teacher { border-color: #ffd54f80; }

.student-name {
  text-align: center;
  line-height: 1.3;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  line-height: 1;
  flex-shrink: 0;
}
.avatar.small { width: 26px; height: 26px; font-size: 15px; }

/* --- signed-in chip ----------------------------------------------------------- */

.whoami {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 12px 3px 3px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.whoami:hover { background: var(--bg-elevated); }
.whoami-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whoami .switch-label { color: var(--text-dim); font-size: 12px; }

@media (max-width: 600px) {
  .topbar { padding: 10px 12px; }
  .model { display: none; }
  .student-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .avatar { width: 52px; height: 52px; font-size: 30px; }
  .avatar.small { width: 26px; height: 26px; font-size: 15px; }
}
