:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #637083;
  --line: #d8dee8;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --danger: #b42318;
  --focus: rgba(15, 118, 110, .18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: white;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover { background: var(--brand-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }

.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost:hover { background: #eef2f6; }

.danger { background: var(--danger); }
.danger:hover { background: #8f1d14; }

.icon-btn {
  width: 36px;
  min-height: 36px;
  padding: 0;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.language-select {
  width: auto;
  min-width: 88px;
  min-height: 40px;
  padding: 0 10px;
  background: white;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: calc(100vh - 72px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 18px;
  overflow-y: auto;
}

.workspace {
  padding: 24px;
  overflow-x: hidden;
}

.upload-zone, .history, .note-view, .empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.upload-zone {
  padding: 16px;
  display: grid;
  gap: 10px;
}

.wide-btn {
  width: 100%;
  margin-top: 12px;
}

label {
  color: var(--muted);
  font-size: 13px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--focus);
}

.history {
  margin-top: 16px;
  padding: 14px;
}

.progress-panel {
  margin-top: 16px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  animation: panelIn .24s ease-out;
}

.progress-panel.compact {
  margin-top: 4px;
  padding: 12px;
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-head h2 {
  margin: 0;
  font-size: 16px;
}

.progress-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.progress-badge {
  min-width: 48px;
  padding: 6px 8px;
  border-radius: 999px;
  background: #e7f5f2;
  color: var(--brand-dark);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.progress-track {
  height: 9px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf2;
}

.progress-bar {
  width: 2%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #22a39a, #0f766e);
  background-size: 180% 100%;
  transition: width .35s ease;
  animation: progressFlow 1.15s linear infinite;
}

.progress-items {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 220px;
  overflow-y: auto;
}

.progress-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.progress-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.progress-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

.stage-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 999px;
  background: #94a3b8;
}

.progress-item.queued .stage-dot {
  background: #94a3b8;
}

.progress-item.analyzing .stage-dot {
  background: var(--brand);
  box-shadow: 0 0 0 0 rgba(15, 118, 110, .36);
  animation: pulseDot 1.1s ease-out infinite;
}

.progress-item.done .stage-dot,
.progress-item.ready .stage-dot {
  background: #15803d;
}

.progress-item.error .stage-dot {
  background: var(--danger);
}

@keyframes progressFlow {
  from { background-position: 0% 50%; }
  to { background-position: 180% 50%; }
}

@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(15, 118, 110, .36); }
  100% { box-shadow: 0 0 0 8px rgba(15, 118, 110, 0); }
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-head h2 {
  margin: 0;
  font-size: 16px;
}

.calendar-head {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.calendar-head strong {
  text-align: center;
  font-size: 14px;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-weekdays {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.calendar-grid {
  margin-top: 6px;
}

.calendar-day {
  position: relative;
  min-height: 38px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
}

.calendar-day:hover {
  background: #eef2f6;
}

.calendar-day.muted-day {
  color: #a6b0bf;
}

.calendar-day.today {
  border-color: var(--line);
}

.calendar-day.has-notes {
  background: #e7f5f2;
  color: var(--brand-dark);
  font-weight: 700;
}

.calendar-day.selected {
  background: var(--brand);
  color: white;
}

.calendar-day small {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 10px;
}

.selected-day-label {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.notes-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.note-item {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  min-height: 64px;
  padding: 10px;
}

.note-item.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focus);
}

.note-item span {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  min-height: 280px;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 24px;
}

.empty-state h2 { margin: 0 0 8px; }
.empty-state p { margin: 0; color: var(--muted); }

.hidden { display: none !important; }

.note-view {
  padding: 20px;
}

.note-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.note-header h2 {
  margin: 0;
  font-size: 24px;
}

.note-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-top: 16px;
  overflow-x: auto;
}

.tab {
  color: var(--muted);
  background: transparent;
  border-radius: 0;
  border-bottom: 3px solid transparent;
}

.tab:hover { background: #eef2f6; }

.tab.active {
  color: var(--brand-dark);
  border-bottom-color: var(--brand);
}

.tab-panel {
  padding-top: 18px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.summary-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.summary-section.wide {
  grid-column: 1 / -1;
}

.summary-section h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.summary-section p, .summary-section li {
  line-height: 1.65;
}

.summary-section ul {
  margin: 0;
  padding-left: 18px;
}

.vocab-table {
  width: 100%;
  border-collapse: collapse;
}

.vocab-table th, .vocab-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 6px;
  text-align: left;
  vertical-align: top;
}

.vocab-term {
  font-weight: 700;
}

.speak-btn {
  min-height: 28px;
  width: 32px;
  margin-left: 6px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--text);
  vertical-align: middle;
}

.speak-btn:hover {
  background: #e7f5f2;
  color: var(--brand-dark);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .42);
}

.modal-panel {
  width: min(520px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .22);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.settings-form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.admin-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-section h3 {
  margin: 0;
  font-size: 15px;
}

.muted {
  color: var(--muted);
}

.dialogue-line {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.dialogue-line strong {
  color: var(--brand-dark);
}

.dialogue-line small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.question {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
  background: white;
}

.question p {
  margin-top: 0;
  line-height: 1.55;
}

.options {
  display: grid;
  gap: 8px;
}

.options label {
  color: var(--text);
  display: flex;
  gap: 8px;
  align-items: center;
}

.options input {
  width: auto;
}

.result-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.practice-box {
  display: grid;
  gap: 10px;
}

#practicePrompt {
  min-height: 156px;
  overflow: hidden;
  line-height: 1.55;
}

.review-history {
  margin-top: 18px;
}

.review-history h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.review-tabs {
  scrollbar-width: thin;
}

.review-group {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.review-group h3 {
  margin: 0;
  font-size: 16px;
}

.review-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.review-card p {
  margin: 0;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.review-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.review-card-head span,
.question small {
  color: var(--muted);
  font-size: 12px;
}

.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mini-result {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f8fafc;
  line-height: 1.45;
}

.error {
  color: var(--danger);
}

.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: #eef2f6;
}

.login-panel {
  position: relative;
  width: min(380px, calc(100vw - 32px));
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.login-language {
  position: absolute;
  top: 18px;
  right: 18px;
}

.login-panel h1 {
  margin: 0 0 18px;
}

.login-panel form {
  display: grid;
  gap: 12px;
}

@media (max-width: 860px) {
  .topbar {
    height: auto;
    min-height: 72px;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }

  .topbar form {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .language-select {
    min-width: 78px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    padding: 16px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .note-header {
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }

}
