:root {
  --bg-app: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;

  --primary: #3b82f6;
  --primary-hover: #2563eb;

  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;

  --border: rgba(255, 255, 255, 0.1);
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Helvetica, Arial, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* --- Navigation --- */
.navbar {
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
}

.status-pill {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 10px;
  border-radius: 999px;
}

main {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* --- Screen transitions --- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.2s ease-in-out;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 10;
}

/* Base UI helpers */
.row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.row.end {
  justify-content: flex-end;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.small-muted {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.35;
  margin-top: 10px;
  white-space: pre-wrap;
}

.note {
  max-width: 800px;
  margin: 18px auto 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

/* Inputs */
input,
textarea,
select {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
}

textarea {
  resize: vertical;
}
select {
  cursor: pointer;
}

/* Buttons */
button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-primary.large {
  padding: 14px 18px;
  font-size: 1rem;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-radius: 10px;
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 10px 12px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-danger.small {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.24);
}

.icon-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.icon-btn.send {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.35);
  color: #dbeafe;
}

/* --- Setup Screen --- */
#setupCard {
  overflow-y: auto;
  padding: 20px;
}

.hero-text {
  text-align: center;
  margin: 20px 0 28px;
}

.hero-text h1 {
  margin: 0 0 10px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-text p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.4;
}

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  max-width: 900px;
  margin: 0 auto 18px;
  width: 100%;
}

.scenario-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 18px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, background 0.2s;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
}

.scenario-card:hover {
  transform: translateY(-2px);
  background: var(--bg-card-hover);
}

.scenario-card.selected {
  border-color: rgba(59, 130, 246, 0.7);
  background: rgba(59, 130, 246, 0.1);
}

.scenario-card h3 {
  margin: 0 0 10px 0;
  font-size: 1.05rem;
}

.scenario-card .desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.35;
  margin-bottom: 12px;
}

.scenario-card .flags {
  display: inline-block;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    'Liberation Mono', monospace;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.settings-panel {
  max-width: 520px;
  margin: 0 auto;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 10px 6px;
  color: var(--text-main);
}

.toggle-row span {
  font-weight: 500;
}

.setup-actions {
  max-width: 520px;
  margin: 14px auto 0;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.variant-hint {
  max-width: 520px;
  margin: 10px auto 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* --- Session Screen --- */
#sessionCard {
  overflow: hidden;
  padding: 0;
}

.session-header {
  flex-shrink: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.9);
  backdrop-filter: blur(6px);
}

.score-board {
  display: flex;
  flex-direction: column;
}
.score-board .label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.score-board .value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--success);
}

.scenario-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 650;
}

/* Chat area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  background: var(--bg-app);
}

.system-message {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 10px 0;
}

.msg {
  max-width: 85%;
  padding: 12px 14px;
  border-radius: 18px;
  font-size: 1rem;
  line-height: 1.5;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.08);
  animation: popIn 0.18s ease-out;
}

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

.msg.npc {
  align-self: flex-start;
  background: rgba(51, 65, 85, 0.75);
  border-bottom-left-radius: 6px;
}

.msg.user {
  align-self: flex-end;
  background: rgba(59, 130, 246, 0.85);
  border-bottom-right-radius: 6px;
  border-color: rgba(59, 130, 246, 0.35);
}

.msg-meta {
  display: block;
  font-size: 0.75rem;
  opacity: 0.8;
  margin-bottom: 6px;
  color: rgba(255, 255, 255, 0.85);
}

.inline-translation {
  margin-top: 8px;
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.82);
  border-top: 1px dashed rgba(255, 255, 255, 0.2);
  padding-top: 8px;
  white-space: pre-wrap;
  opacity: 0.95;
}

/* NEW: inline feedback under user messages */
.inline-feedback {
  margin-top: 8px;
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.85);
  border-top: 1px dashed rgba(255, 255, 255, 0.2);
  padding-top: 8px;
  white-space: pre-wrap;
}

.inline-feedback .label {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}

/* Loading bubble (role-specific placement) */
.msg.loading {
  padding: 14px 18px;
  min-width: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.msg.npc.loading {
  align-self: flex-start;
  background: rgba(51, 65, 85, 0.45);
  border-bottom-left-radius: 6px;
}

.msg.user.loading {
  align-self: flex-end;
  background: rgba(59, 130, 246, 0.45);
  border-bottom-right-radius: 6px;
}

.typing-dots {
  display: flex;
  gap: 5px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: white;
  border-radius: 50%;
  animation: bounce 0.55s infinite alternate;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.12s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes bounce {
  from {
    transform: translateY(0);
    opacity: 0.7;
  }
  to {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Controls deck */
.controls-deck {
  flex-shrink: 0;
  background: rgba(30, 41, 59, 0.92);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  position: relative;
  z-index: 30;
  backdrop-filter: blur(6px);
}

.mic-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--primary);
  border: 4px solid rgba(59, 130, 246, 0.32);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 28px rgba(59, 130, 246, 0.25);
  transition: transform 0.1s;
}

.mic-btn:active {
  transform: scale(0.96);
}
.mic-btn span {
  font-size: 30px;
}

.mic-btn.stop {
  background: var(--danger);
  border-color: rgba(239, 68, 68, 0.32);
  box-shadow: 0 12px 28px rgba(239, 68, 68, 0.2);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35);
  }
  70% {
    box-shadow: 0 0 0 18px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

/* Keyboard overlay */
.keyboard-area {
  position: absolute;
  inset: 0;
  background: rgba(30, 41, 59, 0.98);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  z-index: 35;
}

.keyboard-area input {
  flex: 1;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: white;
  padding: 12px 16px;
  border-radius: 22px;
  font-size: 16px;
}

/* Feedback toast */
.feedback-toast {
  position: absolute;
  bottom: 102px;
  left: 14px;
  right: 14px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(245, 158, 11, 0.55);
  padding: 14px 46px 14px 14px;
  border-radius: 14px;
  z-index: 40;
  box-shadow: var(--shadow);
  animation: slideUp 0.22s ease-out;
}

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

.close-toast-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: transparent;
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: rgba(245, 158, 11, 0.95);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.85;
}

.close-toast-btn:hover {
  opacity: 1;
  background: rgba(245, 158, 11, 0.1);
}

.feedback-content {
  color: #fbbf24;
  font-size: 0.95rem;
  line-height: 1.35;
  white-space: pre-wrap;
}

.suggestion-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Assist panel */
.assist-panel {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 100px;
  background: rgba(30, 41, 59, 0.96);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  z-index: 45;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.assist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-weight: 700;
}

.assist-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.assist-controls,
.assist-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.status-text {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  min-height: 1.2em;
}

.translation-result {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    'Liberation Mono', monospace;
  font-size: 0.92rem;
  min-height: 44px;
  white-space: pre-wrap;
}

/* Native text input in assist panel */
.native-text-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.native-text-row input {
  flex: 1;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  width: min(740px, 94%);
  max-height: 85vh;
  overflow-y: auto;
  background: rgba(30, 41, 59, 0.98);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.modal-content h3 {
  margin: 0 0 12px;
}

.full {
  width: 100%;
  justify-content: center;
}

/* Requirements list */
.req-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
}

.req-list li {
  padding: 10px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--text-main);
  line-height: 1.25;
}

.req-list li:last-child {
  border-bottom: none;
}
.req-list li .material-icons-round {
  font-size: 20px;
  margin-top: 2px;
}
.req-list li.met {
  color: rgba(16, 185, 129, 0.95);
}
.req-list li.notmet {
  color: rgba(148, 163, 184, 0.95);
}

/* Message action sheet */
.msg-menu {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 10px;
}

.msg-menu-inner {
  width: min(520px, 96%);
  background: rgba(30, 41, 59, 0.98);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.msg-menu-title {
  padding: 12px 14px;
  color: var(--text-muted);
  font-weight: 700;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.msg-menu-inner button {
  width: 100%;
  padding: 14px 14px;
  background: transparent;
  border: none;
  color: var(--text-main);
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.msg-menu-inner button:hover {
  background: rgba(255, 255, 255, 0.06);
}
.msg-menu-inner button.muted {
  color: var(--text-muted);
}
.msg-menu-inner button:last-child {
  border-bottom: none;
}

/* Alternatives list */
.alts-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.alt-item {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(15, 23, 42, 0.35);
  border-radius: 14px;
  padding: 12px;
}

.alt-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.alt-style {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.alt-text {
  white-space: pre-wrap;
  font-size: 1rem;
  line-height: 1.45;
}

.alt-notes {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.alt-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* Review */
#reviewCard {
  overflow-y: auto;
  padding: 20px;
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 6px 0 18px;
}

.review-header h2 {
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.review-score {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--success);
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.card {
  background: rgba(30, 41, 59, 0.88);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 14px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
}

.card h3 {
  margin: 0 0 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 800;
}

.text-content {
  margin: 0;
  color: var(--text-main);
  line-height: 1.55;
}

.transcript-container {
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.transcript-line {
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.95rem;
  line-height: 1.4;
}

.transcript-line:last-child {
  border-bottom: none;
}
.transcript-line strong {
  color: #93c5fd;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
}

.badge.ok {
  border-color: rgba(16, 185, 129, 0.32);
  color: rgba(16, 185, 129, 0.95);
}

.badge.bad {
  border-color: rgba(239, 68, 68, 0.32);
  color: rgba(239, 68, 68, 0.95);
}

.review-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding-bottom: 28px;
}

@media (max-width: 600px) {
  .scenario-grid {
    grid-template-columns: 1fr;
  }
  .settings-panel {
    max-width: 100%;
  }
  .msg {
    max-width: 92%;
  }
  .controls-deck {
    gap: 12px;
  }
}
