* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0f1117;
  color: #e8e8ec;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---- Auth screen ---- */
#auth-screen {
  height: 100dvh;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #1a1d29, #0f1117);
  padding: 1rem;
}

.auth-card {
  background: #1a1d29;
  padding: 2rem;
  border-radius: 16px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

.auth-card h1 {
  text-align: center;
  margin-bottom: 1.5rem;
  font-size: 1.4rem;
}

#auth-tabs {
  display: flex;
  margin-bottom: 1rem;
  border-radius: 10px;
  overflow: hidden;
  background: #0f1117;
}

.tab-btn {
  flex: 1;
  padding: 0.6rem;
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  font-weight: 600;
}

.tab-btn.active {
  background: #6c5ce7;
  color: #fff;
}

.auth-form { display: flex; flex-direction: column; gap: 0.75rem; }

.auth-form input {
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  border: 1px solid #333;
  background: #0f1117;
  color: #fff;
  font-size: 0.95rem;
}

.auth-form button {
  padding: 0.7rem;
  border: none;
  border-radius: 8px;
  background: #6c5ce7;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.3rem;
}

.auth-form button:hover { background: #5b4bd6; }

.error { color: #ff6b6b; font-size: 0.85rem; min-height: 1.1rem; }

/* ---- App screen ---- */
#app-screen {
  display: flex;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

#sidebar {
  width: 260px;
  min-height: 0;
  background: #14161f;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.2rem;
  font-weight: 600;
}

#logout-btn {
  background: none;
  border: none;
  color: #999;
  font-size: 1.1rem;
  cursor: pointer;
}

#sidebar h3 { font-size: 0.8rem; text-transform: uppercase; color: #777; margin-bottom: 0.5rem; }

#subject-list { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; }

#subject-list li {
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#subject-list li:hover { background: #1e2130; }
#subject-list li.active { background: #6c5ce7; }

.level-badge {
  font-size: 0.7rem;
  background: rgba(255,255,255,0.15);
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
}

#chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#chat-window {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.msg {
  max-width: 70%;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: #6c5ce7;
  color: #fff;
  border-bottom-right-radius: 2px;
}

.msg.assistant {
  align-self: flex-start;
  background: #1e2130;
  border-bottom-left-radius: 2px;
}

.msg.typing { opacity: 0.6; font-style: italic; }

#chat-form {
  display: flex;
  flex-shrink: 0;
  padding: 1rem;
  gap: 0.6rem;
  border-top: 1px solid #222;
}

#chat-input {
  flex: 1;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  border: 1px solid #333;
  background: #14161f;
  color: #fff;
}

#chat-form button {
  padding: 0.8rem 1.4rem;
  border-radius: 10px;
  border: none;
  background: #6c5ce7;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

/* ---- Level bar (above chat window) ---- */
#level-bar {
  display: flex;
  flex-shrink: 0;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1.2rem;
  background: #14161f;
  border-bottom: 1px solid #222;
  font-size: 0.9rem;
}

#level-info { color: #ccc; }
#level-current-label { color: #a29bfe; }

#check-level-btn {
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  border: 1px solid #6c5ce7;
  background: transparent;
  color: #a29bfe;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

#check-level-btn:hover { background: #6c5ce7; color: #fff; }

/* ---- Assessment modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: #1a1d29;
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.assessment-status { text-align: center; margin-bottom: 1rem; color: #ccc; }

.spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto;
  border: 3px solid #333;
  border-top-color: #6c5ce7;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.assessment-progress { font-size: 0.8rem; color: #999; margin-bottom: 0.4rem; }

.progress-track {
  height: 6px;
  background: #0f1117;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 1.2rem;
}

.progress-fill {
  height: 100%;
  background: #6c5ce7;
  transition: width 0.3s ease;
}

#assessment-question-text {
  margin-bottom: 1rem;
  line-height: 1.5;
  font-size: 1.02rem;
}

#assessment-answer-input {
  width: 100%;
  padding: 0.7rem;
  border-radius: 8px;
  border: 1px solid #333;
  background: #0f1117;
  color: #fff;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 0.9rem;
}

#assessment-submit-btn,
#assessment-close-btn {
  width: 100%;
  padding: 0.7rem;
  border-radius: 8px;
  border: none;
  background: #6c5ce7;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

#assessment-submit-btn:hover,
#assessment-close-btn:hover { background: #5b4bd6; }

#assessment-result-text {
  white-space: pre-line;
  line-height: 1.6;
  margin-bottom: 1.2rem;
  text-align: center;
}

@media (max-width: 700px) {
  #app-screen {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    flex-shrink: 0;
    flex-direction: row;
    align-items: center;
    padding: 0.6rem 0.8rem;
    overflow-x: auto;
    overflow-y: visible;
    gap: 0.6rem;
  }

  .sidebar-header {
    margin-bottom: 0;
    flex-shrink: 0;
  }

  #sidebar h3 { display: none; }

  #subject-list {
    flex-direction: row;
    gap: 0.5rem;
    overflow-x: auto;
  }

  #subject-list li {
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    white-space: nowrap;
    padding: 0.5rem 0.7rem;
  }

  #subject-list li span.label { display: inline; font-size: 0.8rem; }
  #subject-list li .level-badge { font-size: 0.65rem; }

  #level-bar {
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .msg { max-width: 85%; }

  .modal-card { padding: 1.4rem; max-width: 92vw; }
}
