:root {
  --bg: #0f1220;
  --panel: #171b2e;
  --panel-2: #1f2440;
  --border: #2a2f4a;
  --text: #eef0fb;
  --muted: #9aa1c4;
  --accent: #6c8cff;
  --accent-2: #58e0c1;
  --good: #58e0c1;
  --mid: #ffcf6e;
  --bad: #ff7a7a;
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  overflow-x: hidden;
  width: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #171c33, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }

.wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
}
.brand {
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}
.brand span { color: var(--accent); }

.btn {
  display: inline-block;
  padding: 12px 22px;
  border-radius: 999px;
  border: none;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, var(--accent), #8f7bff); color: white; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.hero {
  text-align: center;
  padding: 80px 20px 40px;
}
.hero h1 {
  font-size: 2.6rem;
  margin: 0 0 16px;
  letter-spacing: -0.02em;
}
.hero p {
  color: var(--muted);
  font-size: 1.15rem;
  max-width: 560px;
  margin: 0 auto 32px;
}

.pricing-card {
  max-width: 420px;
  margin: 40px auto;
  text-align: center;
}
.pricing-card .price { font-size: 2.4rem; font-weight: 800; margin: 8px 0; }
.pricing-card ul { list-style: none; padding: 0; margin: 20px 0; text-align: left; }
.pricing-card li { padding: 8px 0; color: var(--muted); }
.pricing-card li::before { content: "✓ "; color: var(--good); font-weight: 800; }

.auth-shell {
  max-width: 420px;
  margin: 60px auto;
  padding: 0 20px;
}
.auth-shell h1 { font-size: 1.7rem; margin-bottom: 6px; }
.auth-shell .subtitle { color: var(--muted); margin-bottom: 24px; }
.field { margin-bottom: 18px; }
.field label { display: block; margin-bottom: 8px; font-size: 0.9rem; color: var(--muted); }
.field input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 1rem;
}
.field input:focus { outline: 2px solid var(--accent); }
.error-msg { color: var(--bad); font-size: 0.9rem; margin-top: 10px; min-height: 1.2em; }
.auth-switch { margin-top: 20px; text-align: center; color: var(--muted); font-size: 0.95rem; }

.lang-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.lang-chip {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
  user-select: none;
  transition: all 0.15s ease;
}
.lang-chip.selected {
  background: linear-gradient(135deg, var(--accent), #8f7bff);
  border-color: transparent;
  font-weight: 700;
}
.lang-hint { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }

/* Dashboard */
.dash-header { margin-bottom: 28px; }
.dash-header h1 { margin: 0 0 4px; font-size: 1.6rem; }
.dash-header p { color: var(--muted); margin: 0; }

.session-card {
  background: linear-gradient(135deg, #24305f, #1a2044);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 28px;
  text-align: center;
}
.session-card .eyebrow { color: var(--accent-2); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; font-size: 0.8rem; }
.session-card h2 { font-size: 1.7rem; margin: 10px 0 20px; }

.skill-bars { display: flex; flex-direction: column; gap: 14px; margin-bottom: 28px; }
.skill-bar-row { display: flex; align-items: center; gap: 14px; }
.skill-bar-row .label { width: 130px; color: var(--muted); font-size: 0.95rem; }
.skill-bar-track { flex: 1; background: var(--panel-2); border-radius: 999px; height: 10px; overflow: hidden; }
.skill-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; }
.skill-bar-row .value { width: 40px; text-align: right; font-weight: 700; }

.improvement-row { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 28px; }
.improvement-item { flex: 1; min-width: 140px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.improvement-item .num { font-size: 1.4rem; font-weight: 800; }
.improvement-item .num.up { color: var(--good); }
.improvement-item .num.down { color: var(--bad); }
.improvement-item .lbl { color: var(--muted); font-size: 0.85rem; }

.tile-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: block;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile .icon { font-size: 1.8rem; margin-bottom: 10px; }
.tile h3 { margin: 0 0 6px; color: var(--text); }
.tile p { margin: 0; color: var(--muted); font-size: 0.9rem; }

/* Conversation page */
.conv-shell { max-width: 1400px; margin: 0 auto; padding: 20px; }
.conv-topbar {
  display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.conv-topbar h1 { margin: 0; font-size: 1.3rem; flex: 1; white-space: nowrap; }
.topbar-back { padding: 8px 14px; flex-shrink: 0; }
.topbar-controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.conv-topbar select {
  padding: 8px 12px; border-radius: 8px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
}
#creditsLabel { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }

.split-container {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  align-items: start;
}
.main-col, .side-col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 520px;
  max-height: 75vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.col-title { font-weight: 700; margin-bottom: 16px; color: var(--muted); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.05em; }

.chat-bubble { margin-bottom: 16px; max-width: 90%; }
.chat-bubble.user { margin-left: auto; text-align: right; }
.bubble-inner {
  display: inline-block;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--panel-2);
  line-height: 1.7;
}
.chat-bubble.ai .bubble-inner { background: #22305a; }
.chat-bubble.user .bubble-inner { background: linear-gradient(135deg, var(--accent), #8f7bff); color: white; }
.chat-bubble.pending .bubble-inner { font-style: italic; color: var(--muted); border: 1px dashed var(--border); background: transparent; }

.correction-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.correction-card .said { color: var(--bad); text-decoration: line-through; font-size: 0.9rem; }
.correction-card .better { color: var(--good); font-weight: 700; margin-top: 6px; }
.correction-card .tip { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }
.no-corrections { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 40px 10px; }

.mic-bar {
  display: flex; justify-content: center; margin-top: 20px;
}
.mic-btn {
  width: 76px; height: 76px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8f7bff);
  border: none; color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 0 rgba(108,140,255,0.5);
}
.mic-btn.recording { animation: pulse 1.4s infinite; background: linear-gradient(135deg, var(--bad), #ff9a6c); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,122,122,0.5); }
  70% { box-shadow: 0 0 0 20px rgba(255,122,122,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,122,122,0); }
}

/* My feedback page */
.fb-shell { max-width: 900px; margin: 0 auto; padding: 20px; }
.fb-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.fb-entry {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; margin-bottom: 14px;
}
.fb-entry .badges { display: flex; gap: 8px; margin-bottom: 10px; }
.badge { font-size: 0.72rem; padding: 3px 10px; border-radius: 999px; background: var(--panel-2); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.badge.lang { background: #22305a; color: var(--accent-2); }
.fb-entry .said { color: var(--bad); text-decoration: line-through; }
.fb-entry .better { color: var(--good); font-weight: 700; margin-top: 6px; }
.fb-entry .tip { color: var(--muted); font-size: 0.88rem; margin-top: 8px; }
.fb-entry .ts { color: var(--muted); font-size: 0.75rem; margin-top: 10px; }

.fb-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.fb-tab {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 10px 18px; border-radius: 999px; cursor: pointer; font-size: 0.9rem; font-weight: 600;
}
.fb-tab.active { background: linear-gradient(135deg, var(--accent), #8f7bff); color: white; border-color: transparent; }

.conv-split { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.conv-session-list {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  max-height: 60vh; overflow-y: auto;
}
.conv-session-row {
  padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.conv-session-row:last-child { border-bottom: none; }
.conv-session-row:hover { background: var(--panel-2); }
.conv-session-row.active { background: var(--panel-2); border-left: 3px solid var(--accent); }
.conv-session-date { font-weight: 600; font-size: 0.9rem; }
.conv-session-meta { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }
.conv-session-transcript {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; max-height: 60vh; overflow-y: auto;
}

@media (max-width: 640px) {
  .conv-split { grid-template-columns: 1fr; }
  .conv-session-list { max-height: 220px; }
}

/* Admin */
.admin-shell { max-width: 1000px; margin: 0 auto; padding: 40px 20px; }
.admin-login { max-width: 380px; margin: 100px auto; }
#searchInput {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); margin-bottom: 20px; font-size: 1rem;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.04em; }
.credit-cell input { width: 80px; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); }
.credit-cell .btn { padding: 8px 14px; font-size: 0.85rem; margin-left: 6px; }
.remove-btn { background: transparent; border: 1px solid var(--bad); color: var(--bad); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 0.8rem; }
.lang-tags span { display: inline-block; background: var(--panel-2); padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; margin-right: 4px; color: var(--accent-2); }

@media (max-width: 860px) {
  .split-container { grid-template-columns: 1fr; }
  .tile-row { grid-template-columns: 1fr; }

  /* Same reasoning as the 640px block below: once the columns stack,
     a phone/tablet's browser chrome resizing the viewport while scrolling
     makes vh-based panel heights visibly jump. Let the page scroll instead. */
  .main-col, .side-col {
    min-height: 0;
    max-height: none;
    overflow-y: visible;
  }
  .mic-bar { position: static; }
}

@media (max-width: 640px) {
  .wrap { padding: 20px 16px 48px; }
  .navbar { padding: 16px 18px; }
  .hero { padding: 48px 16px 28px; }
  .hero h1 { font-size: 1.9rem; }
  .hero p { font-size: 1rem; }

  .card { padding: 20px; }
  .auth-shell { margin: 36px auto; }

  /* Conversation page: stack the top bar into two clear rows instead of
     letting the title, dropdown and buttons wrap into each other. */
  .conv-shell { padding: 14px; }
  .conv-topbar {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
  }
  .conv-topbar h1 {
    order: 2;
    flex-basis: 100%;
    font-size: 1.1rem;
    white-space: normal;
    margin: 2px 0 0;
  }
  .topbar-back { order: 1; }
  .topbar-controls {
    order: 3;
    flex-basis: 100%;
    justify-content: space-between;
    gap: 8px;
  }
  .topbar-controls select { flex: 1; min-width: 0; }
  #creditsLabel { font-size: 0.8rem; }
  #endBtn { padding: 8px 12px; font-size: 0.85rem; }

  .split-container { gap: 14px; }
  .main-col, .side-col {
    padding: 14px;
    /* No vh-based heights here on purpose: mobile browsers resize the
       viewport as the address bar hides/shows while scrolling, which makes
       vh-based panels visibly jump/resize. Let the page itself scroll
       instead of nesting nested scroll areas. */
    min-height: 0;
    max-height: none;
    overflow-y: visible;
  }
  .col-title { margin-bottom: 10px; font-size: 0.8rem; }
  .chat-bubble { max-width: 96%; }

  /* No "sticky" here either - combined with a resizing viewport it caused
     the same jumpy behaviour. Keep the mic button in normal flow. */
  .mic-bar { margin: 20px 0 10px; position: static; }
  .mic-btn { width: 64px; height: 64px; font-size: 1.5rem; }

  /* Admin table: allow horizontal scroll instead of squeezing columns */
  .admin-shell { padding: 24px 14px; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
}
