:root { --bg:#0f0f12; --fg:#e8e8ee; --muted:#9aa0a6; --card:#17171c; --primary:#6ca0ff; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin:0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background:var(--bg); color:var(--fg); -webkit-font-smoothing: antialiased; }
.container { max-width: 900px; margin: 0 auto; padding: 1rem; }

/* Navigation */
nav { background: #131318; border-bottom: 1px solid #1f2030; padding: 0.75rem 0; }
nav .container { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem; }
nav .brand { color:var(--fg); text-decoration:none; font-weight:700; font-size: 1.2rem; }
nav .nav-links { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
nav a { color:var(--muted); text-decoration: none; white-space: nowrap; padding: 0.25rem 0.5rem; border-radius: 4px; transition: background 0.2s, color 0.2s; }
nav a:hover, nav a:focus { color: var(--fg); background: #1a1a20; }
nav .nav-links span { color: var(--fg); white-space: nowrap; }

@media (max-width: 768px) {
  nav .container { padding: 0.5rem 1rem; }
  nav .brand { font-size: 1.1rem; }
  nav .nav-links { gap: 0.5rem; font-size: 0.9rem; }
  nav a { padding: 0.25rem 0.4rem; }
}
main h1 { margin: 1rem 0; font-size: clamp(1.5rem, 4vw, 2rem); }

/* Forms and Inputs */
form { display:flex; flex-direction: column; gap: .5rem; }
input, textarea {
  background: #0f0f15;
  color: var(--fg);
  border: 1px solid #2a2a3a;
  border-radius: 6px;
  padding: .6rem .7rem;
  font-size: 16px; /* Prevents iOS zoom on focus */
  width: 100%;
}
button, .button {
  background: var(--primary);
  color: #0a0a0f;
  border: none;
  border-radius: 6px;
  padding: .6rem 1rem;
  cursor:pointer;
  font-weight:600;
  text-decoration: none;
  width: fit-content;
  font-size: 16px; /* Prevents iOS zoom */
  touch-action: manipulation; /* Improves touch responsiveness */
}
button:hover, .button:hover {
  opacity: 0.9;
}
button:active, .button:active {
  transform: scale(0.98);
}
.card { background: var(--card); border:1px solid #222334; padding: 1rem; border-radius: 8px; }

@media (max-width: 768px) {
  .card { padding: 0.75rem; }
  .card h3 { font-size: clamp(1.1rem, 3vw, 1.3rem); margin: 0.5rem 0; }
}
.actions { margin-top: 1rem; }
.flashes { list-style: none; padding:0; }
.flashes li { margin: .5rem 0; padding: .5rem .75rem; border-radius:6px; }
.flashes .error { background:#3a1a1a; color:#ffdede; }
.flashes .success { background:#183a1a; color:#d9ffde; }
/* Chat Interface */
.chat { display:flex; flex-direction: column; gap:.5rem; margin-bottom: 1rem; }
.msg { background: var(--card); border:1px solid #222334; padding:.6rem .8rem; border-radius:8px; word-wrap: break-word; overflow-wrap: break-word; }
.msg .role { font-size:.75rem; color:var(--muted); margin-bottom:.25rem; text-transform:uppercase; letter-spacing:.08em; }
.msg.user { border-left: 4px solid #5bd1a4; }
.msg.assistant { border-left: 4px solid var(--primary); }
.chat-input { position: sticky; bottom: 0; background: #0f0f12; padding: 0.75rem 0 1rem; display: flex; gap: 0.5rem; flex-direction: column; }
.chat-input textarea { resize: vertical; min-height: 60px; }
.chat-input button { align-self: flex-start; }
.inline { display:flex; gap:.5rem; align-items:center; flex-wrap: wrap; }
.latest-reply { margin-top:.5rem; color: var(--muted); font-size:.9rem; }

@media (max-width: 768px) {
  .msg { padding: 0.5rem 0.6rem; }
  .msg .content { font-size: 0.95rem; }
  .chat-input { padding: 0.5rem 0 0.75rem; }
}

/* Markdown styling */
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: .6rem 0 .4rem; font-size: clamp(1rem, 2.5vw, 1.3rem); }
.markdown p { margin: .4rem 0; }
.markdown pre { background:#0c0c12; padding:.6rem .8rem; border-radius:6px; overflow-x:auto; border:1px solid #1f2030; -webkit-overflow-scrolling: touch; font-size: 0.9rem; }
.markdown code { background:#14141b; padding:.1rem .3rem; border-radius:4px; border:1px solid #222334; font-size: 0.9em; word-break: break-word; }
.markdown table { width:100%; border-collapse: collapse; margin: .5rem 0; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.markdown th, .markdown td { border:1px solid #27283a; padding:.4rem .5rem; min-width: 80px; }
.markdown blockquote { border-left:3px solid #3a3b54; padding-left:.6rem; color:#bac0c6; margin: .5rem 0; }

@media (max-width: 768px) {
  .markdown pre { font-size: 0.85rem; padding: 0.5rem; }
  .markdown th, .markdown td { padding: 0.3rem 0.4rem; font-size: 0.9rem; }
}

/* Interests & Vocab UI */
.grid { display:grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 900px) { .grid { grid-template-columns: 1fr 1fr; } }
.row { display:flex; gap:.5rem; flex-wrap: wrap; }
.col { flex:1 1 180px; min-width: 180px; }
.radio-row { display:flex; gap:1rem; margin-bottom:.5rem; flex-wrap: wrap; }
.checkbox { margin:.5rem 0; color: var(--muted); }
.table-wrap { overflow-x:auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 100%; }

@media (max-width: 768px) {
  .row { flex-direction: column; }
  .col { min-width: 100%; width: 100%; }
  .radio-row { gap: 0.5rem; }
  .radio-row label { font-size: 0.95rem; }
}
.muted { color: var(--muted); }
.button.danger, button.danger { background:#d66; color:#140a0a; }

/* Quiz Section */
.quiz { margin-bottom: 1rem; background: var(--card); border: 1px solid #222334; padding: 1rem; border-radius: 8px; }
.quiz-header { display:flex; justify-content: space-between; align-items:center; margin-bottom:.5rem; gap: 0.5rem; flex-wrap: wrap; }
.quiz-header strong { flex-shrink: 0; }
.quiz-question { font-size: clamp(1rem, 3vw, 1.1rem); margin:.25rem 0 .5rem; font-weight: 500; }

@media (max-width: 768px) {
  .quiz { padding: 0.75rem; }
  .quiz-header { font-size: 0.9rem; }
  .quiz-header .muted { font-size: 0.85rem; }
}
.quiz-feedback {
  margin: .75rem 0;
  padding: .75rem 1rem;
  border-radius: 6px;
  border-left: 4px solid;
}
.quiz-feedback.correct {
  background: #183a1a;
  border-left-color: #5bd1a4;
  color: #d9ffde;
}
.quiz-feedback.partial {
  background: #3a2f1a;
  border-left-color: #e8b84d;
  color: #ffedc9;
}
.quiz-feedback.incorrect {
  background: #3a1a1a;
  border-left-color: #e85d5d;
  color: #ffdede;
}
.quiz-feedback strong {
  display: block;
  margin-bottom: .25rem;
  text-transform: capitalize;
}
.quiz-feedback span {
  display: block;
  font-size: .95rem;
}
/* Tutor Layout */
.tutor-layout { display:flex; gap:1rem; }
.sidebar { width: 260px; flex: 0 0 260px; background: var(--card); border-radius: 8px; padding: 1rem; }
.main { flex: 1 1 auto; min-width: 0; /* Prevents flex overflow */ }
.sidebar .sidebar-header { display:flex; justify-content: space-between; align-items:center; margin-bottom:.5rem; flex-wrap: wrap; gap: 0.5rem; }
.sidebar .title { font-weight: 700; font-size: 1.1rem; }
.chat-list { list-style:none; padding:0; margin:0; display:flex; flex-direction:column; gap:.25rem; max-height: 60vh; overflow:auto; }
.chat-link { display:block; padding:.4rem .5rem; background: #0f0f15; border:1px solid #222334; border-radius:6px; text-decoration:none; color: var(--fg); transition: all 0.2s; }
.chat-link:hover { border-color: var(--primary); background: #17171c; }
.chat-summary { font-size:.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-date { font-size:.75rem; color: var(--muted); margin-top: 0.25rem; }
.chat-actions { margin-top: .25rem; display:flex; gap:.25rem; flex-wrap: wrap; }
.chat-actions button { font-size: 0.85rem; padding: 0.4rem 0.6rem; }

@media (max-width: 768px) {
  .container { padding: 0.75rem; }
  .tutor-layout { flex-direction: column; gap: 0.75rem; }
  .sidebar { width: 100%; flex: 1; }
  .sidebar .sidebar-header { flex-direction: column; align-items: stretch; }
  .sidebar button { width: 100%; }
  .chat-list { max-height: 40vh; }
}
.hidden { display: none; }

/* Suggestion cards */
.suggestion-cards { margin: 2rem 0; }
.suggestion-cards h3 { font-size: clamp(1.2rem, 3vw, 1.5rem); }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1.5rem; }

@media (max-width: 768px) {
  .cards-grid { grid-template-columns: 1fr; gap: 1rem; }
  .suggestion-cards { margin: 1rem 0; }
}
.suggestion-card {
  background: linear-gradient(135deg, #2a2a45 0%, #22223a 100%);
  border: 3px solid #4a4a65;
  border-radius: 16px;
  padding: 2rem;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6), 0 3px 12px rgba(0, 0, 0, 0.4);
  user-select: none;
  -webkit-tap-highlight-color: rgba(108, 160, 255, 0.3);
  touch-action: manipulation;
}
.suggestion-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(108, 160, 255, 0.08) 0%, rgba(108, 160, 255, 0.02) 100%);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.suggestion-card:hover {
  background: linear-gradient(135deg, #2a2a45 0%, #242435 100%);
  border-color: var(--primary);
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 12px 32px rgba(108, 160, 255, 0.5), 0 6px 20px rgba(0, 0, 0, 0.6);
}
.suggestion-card:hover::before {
  opacity: 1;
}
.suggestion-card:active {
  transform: translateY(-3px) scale(1.01);
  background: linear-gradient(135deg, #2a2a40 0%, #222230 100%);
  border-color: #8ab8ff;
  box-shadow: 0 8px 24px rgba(108, 160, 255, 0.5), 0 2px 8px rgba(0, 0, 0, 0.6);
  transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
}
.suggestion-card h4 {
  margin: 0 0 1rem 0;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid rgba(108, 160, 255, 0.3);
  color: #a8c8ff;
  font-size: 1.4rem;
  font-weight: 700;
  position: relative;
  z-index: 1;
  transition: all 0.25s ease;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 1.1rem;
}
.suggestion-card:hover h4 {
  color: #c0d8ff;
  border-bottom-color: rgba(108, 160, 255, 0.6);
}
.suggestion-card:active h4 {
  color: #c0d8ff;
}
.suggestion-card p {
  margin: 0 0 1.25rem 0;
  color: #c5c9ce;
  font-size: 0.95rem;
  line-height: 1.7;
  position: relative;
  z-index: 1;
}
.suggestion-card .detail {
  margin-top: 1rem;
  padding: 0.6rem 1rem;
  background: rgba(108, 160, 255, 0.15);
  border: 1px solid rgba(108, 160, 255, 0.3);
  border-radius: 8px;
  font-size: 0.9rem;
  color: #9ab8ff;
  font-weight: 600;
  position: relative;
  z-index: 1;
  transition: all 0.25s ease;
}
.suggestion-card:hover .detail {
  background: rgba(108, 160, 255, 0.25);
  border-color: rgba(108, 160, 255, 0.5);
  color: #b8d0ff;
}
.suggestion-card:active .detail {
  background: rgba(108, 160, 255, 0.35);
  border-color: rgba(108, 160, 255, 0.7);
  color: #d0e0ff;
}

/* Loading Spinner */
#loading-indicator {
  padding: 1rem;
  text-align: center;
}

.loading-spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 4px solid rgba(108, 160, 255, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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