:root {
  --bg: #050507;
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.62);
  --line: rgba(255, 255, 255, 0.14);
  --ok: #2ee59d;
  --bad: #ff4d6d;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --panel: rgba(8, 8, 12, 0.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background: #050507;
  color: var(--fg);
  font-family: "Sora", system-ui, sans-serif;
  color-scheme: dark;
}
body { overflow: hidden; position: relative; }

.aurora {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(
    125deg,
    #ff2d55 0%,
    #ff3b30 18%,
    #ff6a00 36%,
    #ff9500 52%,
    #ffcc00 68%,
    #ff7a18 82%,
    #ff2d55 100%
  );
  background-size: 280% 280%;
  animation: auroraDrift 36s ease-in-out infinite;
  opacity: 0.4;
  filter: blur(72px) saturate(1.15);
  will-change: background, background-position, opacity;
  transition: background 4.2s ease, opacity 4.2s ease;
}
.aurora.p-warm {
  background: linear-gradient(125deg, #ff2d55 0%, #ff3b30 18%, #ff6a00 36%, #ff9500 52%, #ffcc00 68%, #ff7a18 82%, #ff2d55 100%);
  opacity: 0.4;
}
.aurora.p-mint {
  background: linear-gradient(125deg, #0a2a4a 0%, #0d3b5c 20%, #0e7c7b 42%, #2ec4b6 62%, #9ef01a 78%, #56cfe1 92%, #0a2a4a 100%);
  opacity: 0.42;
}
.aurora.p-aqua {
  background: linear-gradient(125deg, #031a2e 0%, #023e8a 22%, #0077b6 44%, #00b4d8 62%, #90e0ef 78%, #caf0f8 90%, #023e8a 100%);
  opacity: 0.44;
}
.aurora.p-ocean {
  background: linear-gradient(125deg, #001219 0%, #005f73 20%, #0a9396 40%, #94d2bd 58%, #48cae4 74%, #023e8a 88%, #001219 100%);
  opacity: 0.42;
}
.aurora.p-sky {
  background: linear-gradient(125deg, #012a4a 0%, #01497c 25%, #2a6f97 45%, #61a5c2 65%, #a9d6e5 82%, #013a63 100%);
  opacity: 0.4;
}
.aurora-veil {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(255, 204, 0, 0.1), transparent 55%),
    radial-gradient(700px 480px at 90% 10%, rgba(0, 180, 216, 0.1), transparent 50%),
    linear-gradient(180deg, rgba(5,5,7,0.35), rgba(5,5,7,0.82) 55%, #050507 100%);
  transition: background 4.2s ease;
}
@keyframes auroraDrift {
  0% { background-position: 0% 40%; }
  50% { background-position: 100% 60%; }
  100% { background-position: 0% 40%; }
}

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  width: min(100%, 980px);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  padding: calc(14px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand {
  font-family: "Syne", "Sora", sans-serif;
  font-weight: 800;
  font-size: clamp(1.35rem, 3.4vw, 1.85rem);
  letter-spacing: -0.03em;
  line-height: 1;
  color: #fff;
}
.gear-btn {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.05);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.gear-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.gear-btn:active { transform: scale(0.96); }

.flags-wrap {
  margin: 0;
  overflow: visible;
}
.flags {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: visible;
  scroll-snap-type: x mandatory;
  padding: 10px 12px 12px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  justify-content: center;
}
.flags::-webkit-scrollbar { display: none; }
.flag-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid #fff;
  padding: 0;
  overflow: hidden;
  background: #111;
  cursor: pointer;
  scroll-snap-align: center;
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  box-sizing: border-box;
}
.flag-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  image-rendering: auto;
}
.flag-btn.active {
  box-shadow:
    0 0 0 3px rgba(255,255,255,0.9),
    0 6px 16px rgba(0,0,0,0.35);
  transform: translateY(-1px) scale(1.04);
}

.mode-toggle {
  width: fit-content;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.28);
  margin: 0 auto;
}
.mode-toggle button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.mode-toggle button.active {
  color: #111;
  background: #fff;
}

.panel {
  min-height: 0;
  display: none;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  /* clip só nas bordas do card — o brilho pode espalhar dentro do card */
  overflow: hidden;
  position: relative;
  isolation: isolate;
}
.panel.active { display: flex; }

.chat-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  /* NÃO clipar o glow do orb em círculo */
  overflow: visible;
}
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 210px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.85) transparent;
}
.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.chat-log::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.85);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.bubble {
  max-width: 86%;
  padding: 11px 13px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #fff;
  animation: rise 0.28s ease;
  flex-shrink: 0;
}
.bubble.bot {
  align-self: flex-start;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
}
.bubble.user {
  align-self: flex-end;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.2);
}
.quota-pill {
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  white-space: nowrap;
}
.bubble.pt { opacity: 0.92; font-size: 0.86rem; border-style: dashed; }
.bubble.next {
  align-self: flex-start;
  background: rgba(0, 180, 216, 0.12);
  border: 1px solid rgba(0, 180, 216, 0.28);
  font-size: 0.86rem;
}
.bubble.suggest {
  align-self: flex-start;
  background: rgba(255, 204, 0, 0.1);
  border: 1px solid rgba(255, 204, 0, 0.45);
  font-weight: 650;
  font-size: 0.9rem;
}
.bubble.suggest-pt {
  align-self: flex-start;
  background: rgba(255, 204, 0, 0.05);
  border: 1px dashed rgba(255, 204, 0, 0.32);
  font-size: 0.86rem;
  opacity: 0.95;
}
.vol-row {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 0.88rem;
  color: #fff;
}
.vol-row input[type="range"] { width: 100%; accent-color: #fff; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  color: #fff;
  font-size: 0.9rem;
}
.apple-toggle {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  border: 0;
  background: rgba(255,255,255,0.18);
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.apple-toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}
.apple-toggle.on { background: #34c759; }
.apple-toggle.on::after { transform: translateX(20px); }
.bubble.system {
  align-self: center;
  max-width: 95%;
  text-align: center;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 0.78rem;
}

.thinking {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
}
.thinking svg { flex-shrink: 0; }
.thinking-label { opacity: 0.92; }
.status-ico.spin {
  animation: statusSpin 0.85s linear infinite;
  transform-origin: 50% 50%;
}
.status-ico.speak .bar {
  transform-origin: center bottom;
  animation: statusBar 0.7s ease-in-out infinite;
}
.status-ico.speak .b1 { animation-delay: 0s; }
.status-ico.speak .b2 { animation-delay: 0.12s; }
.status-ico.speak .b3 { animation-delay: 0.24s; }
.status-ico.speak .b4 { animation-delay: 0.36s; }
@keyframes statusSpin {
  to { transform: rotate(360deg); }
}
@keyframes statusBar {
  0%, 100% { transform: scaleY(0.45); opacity: 0.55; }
  50% { transform: scaleY(1); opacity: 1; }
}

/* Orb flutuante embaixo — brilho elíptico no CARD, sem 2º círculo */
.orb-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 0;
  pointer-events: none;
  overflow: visible;
  background: transparent;
}
.orb-dock::before {
  content: "";
  position: absolute;
  left: -8%;
  right: -8%;
  bottom: 0;
  height: 78%;
  background:
    radial-gradient(ellipse 95% 70% at 50% 88%, rgba(140, 180, 255, 0.34), transparent 72%),
    radial-gradient(ellipse 60% 45% at 50% 70%, rgba(180, 210, 255, 0.16), transparent 70%),
    linear-gradient(180deg, transparent 0%, rgba(5,5,7,0.25) 48%, rgba(5,5,7,0.78) 100%);
  pointer-events: none;
  z-index: 0;
}
.orb-dock[hidden] { display: none !important; }
.orb-host {
  position: relative;
  z-index: 1;
  width: 260px;
  height: 260px;
  display: grid;
  place-items: center;
  overflow: visible;
  border: none;
  background: transparent;
  filter: none;
  border-radius: 0;
  clip-path: none;
  -webkit-mask-image: none;
  mask-image: none;
}
.orb-host canvas {
  border: none !important;
  outline: none !important;
  background: transparent !important;
  display: block;
  border-radius: 0 !important;
}
.live-transcript {
  min-height: 1.2em;
  max-width: 92%;
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
  animation: dictatePulse 1.15s ease-in-out infinite;
  text-shadow: 0 2px 10px rgba(0,0,0,0.55);
}
.live-transcript:empty { display: none; }
@keyframes dictatePulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: rgba(0,0,0,0.28);
}
.composer input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: #fff;
  border-radius: 14px;
  padding: 13px 14px;
  font: inherit;
  outline: none;
}
.composer input.dictating { animation: dictatePulse 1.15s ease-in-out infinite; box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }
.composer input:focus { border-color: rgba(255,255,255,0.4); }
.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.05);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.send { background: #fff; border-color: transparent; color: #111; }
.icon-btn.mic.listening { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.25); }

.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 0;
}
.quiz-progress { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.quiz-score { font-size: 0.85rem; color: #fff; font-weight: 600; }
.bar {
  height: 6px;
  margin: 12px 14px 0;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff2d55, #ff9500, #ffcc00);
  transition: width 0.25s ease;
}
.quiz-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.question {
  font-family: "Syne", "Sora", sans-serif;
  font-size: clamp(1.05rem, 2.4vw, 1.28rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: #fff;
}
.options { display: grid; gap: 10px; }
.option {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: #fff;
  border-radius: 14px;
  padding: 14px;
  font: inherit;
  font-size: 0.98rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.option .opt-text { flex: 1; min-width: 0; }
.option .play-pron {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.25);
  color: #fff;
  display: none;
  place-items: center;
  flex-shrink: 0;
  cursor: pointer;
  padding: 0;
}
.option .play-pron svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.option.correct { background: rgba(46, 229, 157, 0.18); border-color: var(--ok); }
.option.correct .play-pron { display: grid; }
.option.wrong { background: rgba(255, 77, 109, 0.16); border-color: var(--bad); }
.option:disabled { cursor: default; }
.quiz-done {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
.quiz-done.show { display: flex; }
.quiz-done h2 { margin: 0; font-family: "Syne", sans-serif; font-size: 1.5rem; color: #fff; }
.quiz-done p { margin: 0; color: var(--muted); }
.restart {
  margin-top: 8px;
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: #111;
  background: #fff;
}

.config-sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0,0,0,0.45);
  padding: 16px;
}
.config-sheet.open { display: flex; }
.config-card {
  width: min(440px, 100%);
  max-height: min(84dvh, 720px);
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #121218;
  padding: 16px;
  color: #fff;
  animation: rise 0.22s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.85) transparent;
}
.config-card h3 { margin: 0 0 6px; font-family: "Syne", sans-serif; }
.config-card .config-sub { margin-top: 18px; }
.config-card p { margin: 0 0 14px; color: var(--muted); font-size: 0.85rem; }
.theme-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-row button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: #fff;
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.theme-row button.active { background: #fff; color: #111; border-color: #fff; }
.voice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.85) transparent;
  padding-right: 2px;
}
.voice-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.03);
  cursor: pointer;
}
.voice-row.active { border-color: #fff; background: rgba(255,255,255,0.1); }
.voice-row .v-flag {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid #fff;
  object-fit: cover;
}
.voice-row .v-gender {
  width: 28px;
  height: 28px;
  color: #fff;
}
.voice-row .v-name { font-size: 0.86rem; font-weight: 650; }
.voice-row .v-play {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.08);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.voice-row .v-play svg { width: 14px; height: 14px; fill: currentColor; stroke: none; }
.config-close {
  margin-top: 12px;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 11px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.shake { animation: shake 0.45s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 480px) {
  .flags {
    gap: 8px;
    padding: 10px 10px 14px;
    justify-content: center;
  }
  .flag-btn { width: 40px; height: 40px; }
  .flag-btn.active {
    box-shadow:
      0 0 0 2.5px rgba(255,255,255,0.95),
      0 5px 14px rgba(0,0,0,0.35);
  }
}

@media (min-width: 860px) {
  .app {
    padding-top: 28px;
    gap: 14px;
  }
  .flag-btn { width: 46px; height: 46px; }
  .orb-host { width: 320px; height: 320px; }
  .panel { border-radius: 26px; }
  .chat-log { padding: 22px 22px 200px; }
  .composer { padding: 14px 16px; }
  .config-sheet { align-items: center; }
}
