/* --- Início: Módulo de Chat (Estilos Novos e Corrigidos) --- */
#chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  box-sizing: border-box;
  padding: 1rem 1rem calc(var(--chat-form-height) + var(--nav-height) + 16px);
  gap: 0.5rem;
  background: transparent;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.25rem;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.toolbar-label {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.pill-toggle {
  border: 1px solid #e1e1e1;
  background-color: #f3f3f3;
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}
.pill-toggle:hover {
  background-color: #ececec;
}
.pill-toggle.is-active {
  background-color: #e7f1ff;
  border-color: #c9ddff;
  color: #0f4ba7;
}

.chat-messages {
  font-family:
    "SF Pro Rounded",
    "Segoe UI Rounded",
    "Nunito",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem 1rem 1rem;
  scroll-padding-bottom: calc(
    var(--chat-form-height) + var(--nav-height) + 16px
  );
  background-color: transparent;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  transform: translateZ(0);
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  margin-bottom: 8px;
  min-width: 60%;
}
.message:last-child {
  margin-bottom: calc(var(--chat-form-height) + 20px);
}

.message .author {
  font-size: 0.85rem;
  color: #7f8590;
  margin-bottom: 4px;
  padding-left: 2px;
}

.bubble {
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  position: relative;
  overflow: hidden;
  background-color: #ffffff;
}

.msg-chinese {
  font-size: 0.98rem;
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: 0.01em;
}
.msg-chinese {
  font-family: var(--font-chinese);
  font-weight: 500;
  font-size: 1.2rem;
}
.msg-pinyin,
.msg-translation,
.msg-feedback {
  font-family: var(--font-main);
  font-size: 0.95rem;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e6e6e6;
}
.msg-pinyin {
  color: rgba(0, 0, 0, 0.6);
  font-style: italic;
}
.msg-translation {
  color: #4f5563;
  font-size: 0.95rem;
}
.msg-feedback {
  font-style: italic;
}
.hidden {
  display: none;
}

.message-tutor {
  align-self: flex-start;
}
.message-tutor .bubble {
  background-color: #f5fcf7;
  border-color: #d8eddf;
}
.message-tutor {
  flex-direction: row;
  align-items: flex-start;
  gap: clamp(10px, 2.5vw, 14px);
}
.message-tutor .message-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.message-tutor .avatar {
  width: clamp(40px, 8vw, 56px);
  height: clamp(40px, 8vw, 56px);
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(135deg, #e8f3ff 0%, #d4e8ff 100%);
  border: 2px solid rgba(0, 122, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0, 122, 255, 0.15), 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.message-tutor .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.message-user {
  align-self: flex-end;
}
.message-user .bubble {
  background-color: #e8f3ff;
  border-color: #cfe2ff;
}
.message-user .msg-pinyin {
  color: #6a7a90;
}
.message-user .msg-translation {
  color: #4a5e78;
}

.user-feedback {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.user-feedback .feedback-icon {
  font-size: 1.2rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.user-feedback .feedback-text {
  background: #f5fcf7;
  border: 1px solid #d8eddf;
  border-radius: 12px;
  padding: 8px 10px;
}

.actions-container {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  justify-content: flex-start;
}
.action-btn {
  background-color: #f8f8f8;
  border: 1px solid #e3e3e3;
  border-radius: 999px;
  padding: 6px 12px;
  min-width: 40px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition:
    background-color 0.2s,
    color 0.2s,
    border-color 0.2s,
    transform 0.1s;
}
.action-btn:hover {
  background-color: #ededed;
  border-color: #dcdcdc;
}
.action-btn.is-active {
  background-color: #e7f1ff;
  border-color: #c9ddff;
  color: #0f4ba7;
}
.action-btn.audio-btn {
  font-size: 0.9rem;
  padding: 6px 10px;
}
.action-btn.is-pending {
  cursor: default;
  animation: pulse 1.5s infinite;
}
.action-btn.is-error {
  background-color: #ffe0e0;
  color: #c02020;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes thinking {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}
.thinking-indicator {
  animation: thinking 1.4s ease-in-out infinite;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  background: transparent;
}
.empty-copy {
  color: #4e4e4e;
  font-size: 0.93rem;
}
.empty-suggestions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.empty-suggestions .suggestion-btn {
  border: 1px solid #e5e5e5;
  background: #e8f3ff;
  border-radius: 14px;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  transition:
    background-color 0.2s,
    border-color 0.2s,
    transform 0.1s;
  color: #123a74;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}
.empty-suggestions .suggestion-btn:hover {
  background: #dbeafc;
  border-color: #cfe2ff;
  transform: translateY(-1px);
}

.suggestion-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 1rem;
  justify-content: center;
}
.suggestion-chip {
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 10px 16px;
  font-size: 0.9rem;
  color: var(--text-primary);
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: all 0.2s;
}
.suggestion-chip:hover {
  background-color: #f5f5f5;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.07);
}

.chat-form-container {
  display: none;
  min-height: var(--chat-form-height);
}

#chat.active .chat-form-container {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  align-items: center;
  padding: 0.5rem 0.25rem 0.25rem;
  min-height: var(--chat-form-height);
  pointer-events: none;
}
.chat-form {
  display: flex;
  width: 100%;
  gap: 10px;
  align-items: center;
}
.chat-form {
  min-height: var(--chat-form-height);
}
.chat-form,
.chat-form * {
  pointer-events: auto;
}
.message-input {
  flex-grow: 1;
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 999px;
  font-size: 1rem;
  background-color: #f6f6f6;
  transition: all 0.2s ease;
}
.message-input:focus {
  outline: none;
  background-color: #ffffff;
  border-color: #d0d0d0;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}
.send-button {
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: #e8f3ff;
  color: #0f4ba7;
  border: 1px solid #cfe2ff;
  box-shadow: 0 6px 14px rgba(0, 122, 255, 0.18);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background-color 0.2s ease;
}
.send-button:disabled {
  background: #f2f2f2;
  border-color: #e5e5e5;
  color: #9a9a9a;
  box-shadow: none;
  cursor: not-allowed;
}
.send-button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 18px rgba(0, 122, 255, 0.24);
  background: #deebff;
}
.send-button svg {
  fill: currentColor;
}

@media (max-width: 720px) {
  #chat {
    padding: 0.4rem 0.4rem
      calc(var(--chat-form-height) + var(--nav-height) + 12px);
  }
  .chat-messages {
    padding: 0.4rem 0.6rem 0.9rem;
    scroll-padding-bottom: calc(
      var(--chat-form-height) + var(--nav-height) + 12px
    );
    min-height: 0;
  }
  .message:last-child {
    margin-bottom: calc(var(--chat-form-height) + 16px);
  }
  .msg-chinese {
    font-size: 0.95rem;
  }
  .msg-pinyin,
  .msg-translation,
  .msg-feedback {
    font-size: 0.9rem;
  }

  /* Role-play grid: flexível no mobile */
  #role-play .scenario-list {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.65rem;
  }
}

@media (max-width: 480px) {
  .message-tutor .avatar {
    width: clamp(42px, 12vw, 52px);
    height: clamp(42px, 12vw, 52px);
  }
}

@media (min-width: 721px) {
  .message-tutor .avatar {
    width: 52px;
    height: 52px;
  }
}

@media (hover: hover) {
  .message-tutor .avatar:hover {
    transform: scale(1.08);
  }
}
/* --- Fim: Módulo de Chat --- */

/* --- Início: Módulos de Role-Play e Vocabulário (Estilos Originais Restaurados) --- */
#role-play .scenario-list-container {
  padding: 1.5rem;
}
#role-play h2 {
  display: none;
}
.scenario-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}
.scenario-button {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.85rem 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.15s,
    box-shadow 0.15s,
    border-color 0.15s;
}
.scenario-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
  border-color: #d8e7ff;
}
.scenario-icon {
  width: 26px;
  height: 26px;
  stroke: #123a74;
  fill: none;
}
.role-play-chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.role-play-exit {
  align-self: flex-start;
  border: 1px solid var(--border-color);
  background: #fff;
  border-radius: 10px;
  padding: 0.35rem 0.65rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.06);
}
#role-play .role-play-controls {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  padding: 0.5rem 0;
  z-index: 5;
  filter: drop-shadow(0 -2px 8px rgba(0, 0, 0, 0.1));
}
#role-play .mic-button {
  background: #e8f3ff;
  border: 2px solid #cfe2ff;
  border-radius: 16px;
  padding: 0.7rem 1.35rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #0f4ba7;
  box-shadow: 0 8px 18px rgba(0, 122, 255, 0.2);
  font-weight: 700;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
}
#role-play .mic-button:active {
  transform: scale(0.97);
}
#role-play .mic-button.recording {
  background: #fdecea;
  border-color: #f6c2b9;
  color: #b63820;
  box-shadow: 0 10px 22px rgba(182, 56, 32, 0.25);
  animation: mic-pulse 1.1s ease-in-out infinite;
}

@keyframes recording-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 0 rgba(255, 59, 48, 0.7),
      0 6px 14px rgba(255, 59, 48, 0.18);
  }
  50% {
    box-shadow:
      0 0 0 10px rgba(255, 59, 48, 0),
      0 6px 14px rgba(255, 59, 48, 0.18);
  }
}

@keyframes mic-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.05);
    opacity: 1;
  }
}
.mic-icon {
  fill: currentColor;
}
.recording-indicator {
  width: 10px;
  height: 10px;
  background: #ff3b30;
  border-radius: 50%;
}

#vocabulary {
  padding: 0;
  box-sizing: border-box;
}
.vocab-controls {
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--header-bg);
}
.vocab-controls h2 {
  font-size: 1.5rem;
  margin: 0;
}
.add-word-btn {
  background-color: var(--send-button-bg);
  color: white;
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 24px;
  line-height: 38px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}
.vocab-list {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  padding: 1rem;
}
.empty-list-msg {
  text-align: center;
  padding-top: 4rem;
  color: #888;
}

.word-card {
  background-color: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.07);
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border-color);
}
.word-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: linear-gradient(to right, #f5a623, #f56e23);
}
.word-card[data-hsk="HSK1"]::before {
  background: linear-gradient(to right, #a8e063, #56ab2f);
}
.word-card[data-hsk="HSK2"]::before {
  background: linear-gradient(to right, #6dd5ed, #2193b0);
}
.word-card-main {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.2rem 1rem;
  cursor: pointer;
}
.word-card .character {
  font-size: 2.5rem;
  font-weight: 500;
  min-width: 50px;
  text-align: center;
  color: var(--text-primary);
}
.word-card .info-stack {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.word-card .pinyin {
  font-size: 1.15rem;
  color: var(--text-secondary);
}
.word-card .translation {
  font-size: 1rem;
  color: var(--text-primary);
}
.word-card .tags {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.word-card .tag {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
  border: 1px solid transparent;
}
.word-card .tag.hsk {
  color: var(--user-bubble-bg);
  background-color: #e3f2fd;
  border-color: #d1e9fc;
}
.word-card .tag.pos {
  color: var(--text-secondary);
  background-color: #f0f0f0;
  border-color: #e8e8e8;
}
.word-card .audio-btn {
  background-color: transparent;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #a0a0a0;
  margin-left: auto;
}
.word-card .audio-btn svg path {
  fill: var(--user-bubble-bg);
}
.word-card-extended {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition:
    max-height 0.4s ease,
    opacity 0.3s ease,
    padding-bottom 0.4s ease;
}
.word-card.expanded .word-card-extended {
  max-height: 300px;
  opacity: 1;
  padding-bottom: 1rem;
}
.extended-content-wrapper {
  padding: 0 1rem;
  border-top: 1px solid var(--border-color);
  margin: 0 1rem;
  padding-top: 1rem;
}
.example-container {
  margin-bottom: 1rem;
}
.word-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border-color);
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 16px;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  box-sizing: border-box;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-overlay.hidden {
  display: none;
}

body.modal-open {
  overflow: hidden;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal-content {
  background: var(--app-bg);
  border-radius: 16px;
  padding: 1.5rem;
  width: 90%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  transform: scale(0.95);
  transition: transform 0.3s ease;
}
.modal-overlay.active .modal-content {
  transform: scale(1);
}
#word-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Role-play modal */
.role-modal {
    width: 92%;
    max-width: 440px;
    max-height: 90vh;
    padding: 1.25rem 1.25rem 1rem;
  background: linear-gradient(
    180deg,
    rgba(198, 225, 254, 0.9) 0%,
    rgba(255, 255, 255, 0.96) 65%
  );
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.role-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}
.role-modal-title {
  margin: 0;
  font-size: 1.25rem;
}
.role-modal-desc {
  margin: 0.2rem 0 0;
  color: var(--text-secondary);
  line-height: 1.5;
}
.role-modal-close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem 0.45rem;
  border-radius: 8px;
}
.role-modal-close:hover {
  background: rgba(0, 0, 0, 0.06);
}
.role-modal-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 0.75rem;
  flex: 1 1 auto;
  overflow: hidden;
}
.role-modal-messages {
  flex: 1 1 auto;
  max-height: 60vh;
  overflow-y: auto;
  padding: 0.4rem 0.6rem 0.75rem;
}
.modal-controls {
  position: static;
  padding: 0;
}

@media (max-width: 720px) {
    .role-modal {
        width: 95%;
        max-width: none;
        max-height: 94vh;
        padding: 1.4rem 1.25rem 1.1rem;
        border-radius: 18px;
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
    }
    .role-modal-title { font-size: 1.1rem; }
    .role-modal-desc { font-size: 0.95rem; }
    .role-modal-messages {
        max-height: 65vh;
        padding: 0.5rem 0.75rem 1rem;
    }
}
/* --- Fim: Estilos Restaurados --- */
.icon-speaker {
  display: block;
}
#role-play .chat-form-container {
  position: static;
  padding: 0.75rem 0.25rem;
}
#role-play .chat-form-container {
  display: none;
}
#vocabulary .chat-form-container {
  display: none;
}
#lessons .chat-form-container {
  display: none;
}
