:root {
  --bg: #fff8f6;
  --surface: #ffffff;
  --surface-soft: #fff1ee;
  --ink: #2b1e24;
  --muted: #6e5a63;
  --border: #f0dcd8;
  --accent: #d94e6c;
  --accent-hover: #c13d5a;
  --accent-soft: #fde8ec;
  --mint: #1f8a65;
  --mint-soft: #eaf8f2;
  --amber: #a85d00;
  --amber-soft: #fff6e6;
  --shadow: 0 10px 30px rgba(84, 38, 52, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 10% 10%, rgba(217, 78, 108, 0.12), transparent 40%),
    radial-gradient(circle at 90% 15%, rgba(255, 190, 152, 0.18), transparent 38%),
    radial-gradient(circle at 50% 95%, rgba(217, 78, 108, 0.08), transparent 45%);
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 36px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ff8ba0, #d94e6c);
  display: grid;
  place-items: center;
  font-size: 24px;
  box-shadow: 0 8px 18px rgba(217, 78, 108, 0.28);
}

.brand h1 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.5rem;
  line-height: 1.15;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

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

.control-pill,
.icon-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(43, 30, 36, 0.04);
}

.control-pill span {
  color: var(--muted);
  font-weight: 500;
}

.control-pill select {
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  outline: none;
}

.icon-pill {
  cursor: pointer;
}

.icon-pill:hover {
  border-color: var(--accent);
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
}

.status-pill.online .dot {
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
}

.status-pill.offline .dot {
  background: #dc2626;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 14px;
}

.tab-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 10px 15px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.18s ease;
}

.tab-btn:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px rgba(217, 78, 108, 0.25);
}

.badge {
  background: rgba(255, 255, 255, 0.24);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.78rem;
}

.tab-btn:not(.active) .badge {
  background: var(--accent-soft);
  color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Topic Bar */
.topic-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.topic-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip,
.mini-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip.active,
.chip:hover,
.mini-chip:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.ghost-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  border-radius: 10px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.ghost-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.primary-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Chat Box */
.chat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  height: 56vh;
  min-height: 360px;
  max-height: 620px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  gap: 6px;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  padding: 12px 15px;
  border-radius: 16px;
  line-height: 1.52;
  font-size: 0.95rem;
}

.msg.user .bubble {
  background: linear-gradient(135deg, #e55b78, #d94e6c);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

.bubble-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.speak-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 3px 7px;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}

.speak-btn:hover {
  border-color: var(--accent);
}

.reply-vi {
  margin-top: 6px;
  font-size: 0.84rem;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}

.feedback-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--mint);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.84rem;
  line-height: 1.45;
  width: 100%;
}

.feedback-title {
  font-weight: 700;
  color: var(--mint);
  margin-bottom: 3px;
}

.better-line {
  margin-top: 5px;
  padding: 6px 8px;
  background: var(--mint-soft);
  border-radius: 8px;
  font-weight: 600;
  color: #135d43;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.vocab-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.vocab-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--amber-soft);
  border: 1px solid #f4dfb6;
  color: var(--amber);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
}

.save-mini-btn {
  border: none;
  background: rgba(168, 93, 0, 0.14);
  color: var(--amber);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.save-mini-btn:hover {
  background: var(--amber);
  color: #fff;
}

/* Composer */
.chat-composer {
  margin-top: 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}

.chat-composer textarea,
#coach-input {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  resize: none;
  outline: none;
  padding: 6px 4px;
}

#coach-input {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--bg);
}

.mic-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.mic-btn.listening {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

.hint-line {
  margin: 8px 4px 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 6px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.25rem;
}

.muted {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.wrap {
  flex-wrap: wrap;
}

.quick-examples {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.coach-result {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.coach-result.hidden {
  display: none;
}

.result-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.result-label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 5px;
}

.result-text {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.vocab-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.vocab-controls select {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
}

.vocab-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.vocab-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vocab-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.vocab-word {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--ink);
}

.vocab-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.vocab-meaning {
  font-weight: 600;
  color: var(--accent);
}

.vocab-example {
  font-size: 0.86rem;
  background: var(--surface-soft);
  padding: 9px 10px;
  border-radius: 10px;
  line-height: 1.45;
}

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

.vocab-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 4px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 16px;
}

@media (max-width: 640px) {
  .msg {
    max-width: 96%;
  }
  .chat-box {
    height: 52vh;
  }
  .app-shell {
    padding-bottom: 96px;
  }
}

/* PWA Mobile Install UI */
.pwa-pill {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(217, 78, 108, 0.3);
  font-weight: 600;
}

.pwa-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 40;
  max-width: 540px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: 0 14px 36px rgba(84, 38, 52, 0.18);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: pwaSlideUp 0.25s ease-out;
}

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

.pwa-banner-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.pwa-banner-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex-shrink: 0;
}

.pwa-banner-info strong {
  display: block;
  font-size: 0.92rem;
  color: var(--ink);
}

.pwa-banner-info p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pwa-install-btn {
  padding: 8px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.pwa-close-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: grid;
  place-items: center;
}

.pwa-close-btn:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.pwa-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(43, 30, 36, 0.45);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.pwa-modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 20px 48px rgba(43, 30, 36, 0.25);
}

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

.pwa-modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.pwa-modal-body {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink);
}

.pwa-modal-body ol {
  margin: 8px 0 0;
  padding-left: 20px;
}

.pwa-modal-body li + li {
  margin-top: 8px;
}

.pwa-modal-ok {
  width: 100%;
  margin-top: 16px;
}

.hidden {
  display: none !important;
}
