@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Disable touch-and-hold selection on interactive elements */
.dialogue-line,
.word-item,
.word-pair,
.flashcard,
.flashcard-inner,
.keyword,
.list-words {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

:root {
  --primary: #e63946;
  --primary-dark: #c1121f;
  --secondary: #457b9d;
  --accent: #f4a261;
  --dark: #1d3557;
  --light: #f1faee;
  --bg: #fef9ef;
  --card: #ffffff;
  --text: #1d3557;
  --text-light: #457b9d;
  --shadow: rgba(29, 53, 87, 0.15);
}

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 20% 80%, rgba(230, 57, 70, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(69, 123, 157, 0.05) 0%, transparent 50%);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px var(--shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
  gap: 1rem;
}

/* Logo */
.header-logo {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: white;
  flex-shrink: 0;
}

.logo-icon {
  font-size: 1.25rem;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

/* Header Navigation */
.header-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.nav-group {
  display: flex;
  gap: 0.25rem;
}

.nav-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.3);
}

/* Header User Section */
.header-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.user-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.2);
}

.user-status.verified {
  background: rgba(76, 175, 80, 0.3);
  color: #c8ffc8;
}

.user-btn {
  padding: 0.35rem 0.75rem;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.user-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
}

.user-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.user-btn-secondary {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.4);
}

.user-btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
}

.user-btn-logout {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.3);
  opacity: 0.7;
}

.user-btn-logout:hover:not(:disabled) {
  background: rgba(255, 100, 100, 0.3);
  border-color: rgba(255, 150, 150, 0.5);
  opacity: 1;
}

.user-cancel-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
}

.user-cancel-btn:hover {
  color: white;
}

.header-email-form {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.header-email-input,
.header-code-input {
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  width: 140px;
}

.header-code-input {
  width: 90px;
  text-align: center;
  letter-spacing: 2px;
  font-weight: 600;
}

.header-email-input::placeholder,
.header-code-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.header-email-input:focus,
.header-code-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.25);
}

/* Mode Toggle (in header nav) */
.mode-toggle button {
  padding: 0.3rem 0.6rem;
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.mode-toggle button:hover {
  border-color: rgba(255, 255, 255, 0.6);
  color: white;
}

.mode-toggle button.active {
  background: rgba(255, 255, 255, 0.2);
  border-color: white;
  color: white;
}

/* Rate Limits Indicator */
.rate-limits-indicator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  margin-right: 1rem;
}

.limit-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.1);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.limit-item.exhausted {
  color: rgba(255, 200, 200, 0.9);
  background: rgba(255, 100, 100, 0.2);
}

.limit-icon {
  font-size: 0.7rem;
}

.limit-reset {
  font-size: 0.65rem;
  opacity: 0.8;
}

main {
  display: flex;
  flex: 1;
  gap: 0;
  position: relative;
}

/* Dialogue View Toggle (in sidebar) */
.dialogue-view-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 0.5rem;
  background: var(--light);
  border-radius: 6px;
  padding: 2px;
}

.dialogue-view-toggle button {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-light);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.dialogue-view-toggle button:hover {
  color: var(--text);
}

.dialogue-view-toggle button.active {
  background: var(--secondary);
  color: white;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--card);
  border-right: 3px solid var(--light);
  padding: 1.5rem;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar h2 {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dialogue-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dialogue-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem;
  background: var(--light);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 48px;
  border-left: 4px solid transparent;
}

.dialogue-item:hover,
.dialogue-item:active {
  background: #e8f4f8;
  transform: translateX(4px);
}

.dialogue-item.active {
  background: #dbeafe;
  border-left-color: var(--secondary);
}

.dialogue-title {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 600;
}

.delete-btn {
  background: none;
  border: none;
  color: #a0aec0;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s;
}

.delete-btn:hover,
.delete-btn:active {
  color: var(--primary);
  background: rgba(230, 57, 70, 0.1);
}

.empty-message {
  color: var(--text-light);
  font-style: italic;
  font-size: 0.9rem;
  padding: 1rem 0;
  text-align: center;
}

/* Sidebar Collapsible Sections */
.sidebar-section {
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--light);
  padding-bottom: 0.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 0.5rem 0;
  -webkit-user-select: none;
  user-select: none;
}

.section-header:hover {
  opacity: 0.8;
}

.section-header h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: var(--text);
  margin: 0;
}

.section-toggle {
  font-size: 0.7rem;
  color: var(--text-light);
  width: 1rem;
}

.section-content {
  overflow: hidden;
}

/* Word Lists Section */
.word-lists-section .section-header {
  margin-bottom: 0;
}

.word-lists-section .section-content {
  padding-top: 0.5rem;
}

.header-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.create-list-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--secondary);
  background: transparent;
  color: var(--secondary);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.create-list-btn:hover {
  background: var(--secondary);
  color: white;
}

.create-list-form {
  background: var(--light);
  padding: 0.75rem;
  border-radius: 10px;
  margin-bottom: 0.75rem;
}

.create-list-input {
  width: 100%;
  padding: 0.5rem;
  border: 2px solid var(--secondary);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  margin-bottom: 0.5rem;
}

.create-list-input:focus {
  outline: none;
  border-color: var(--primary);
}

.create-list-actions {
  display: flex;
  gap: 0.5rem;
}

.create-list-save,
.create-list-cancel {
  flex: 1;
  padding: 0.4rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.create-list-save {
  background: var(--secondary);
  color: white;
  border: none;
}

.create-list-cancel {
  background: transparent;
  border: 1px solid var(--text-light);
  color: var(--text-light);
}

/* Header buttons container */
.header-buttons {
  display: flex;
  gap: 0.5rem;
}

.import-btn {
  padding: 0.25rem 0.5rem;
  border: 2px solid var(--secondary);
  background: transparent;
  color: var(--secondary);
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.import-btn:hover {
  background: var(--secondary);
  color: white;
}

/* Import form */
.import-form {
  background: var(--light);
  padding: 0.75rem;
  border-radius: 10px;
  margin-bottom: 0.75rem;
}

.import-name-input {
  width: 100%;
  padding: 0.5rem;
  border: 2px solid var(--secondary);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  margin-bottom: 0.5rem;
}

.import-name-input:focus {
  outline: none;
  border-color: var(--primary);
}

.import-select {
  width: 100%;
  padding: 0.5rem;
  border: 2px solid var(--secondary);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  margin-bottom: 0.5rem;
  background: white;
  cursor: pointer;
}

.import-select:focus {
  outline: none;
  border-color: var(--primary);
}

.import-words-input {
  width: 100%;
  padding: 0.5rem;
  border: 2px solid var(--light);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 0.5rem;
}

.import-words-input:focus {
  outline: none;
  border-color: var(--secondary);
}

.import-actions {
  display: flex;
  gap: 0.5rem;
}

.import-save,
.import-cancel {
  flex: 1;
  padding: 0.4rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.import-save {
  background: var(--secondary);
  color: white;
  border: none;
}

.import-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.import-cancel {
  background: transparent;
  border: 1px solid var(--text-light);
  color: var(--text-light);
}

.import-cancel:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.word-list-item {
  background: var(--light);
  border-radius: 10px;
  margin-bottom: 0.5rem;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.word-list-item.current {
  border-left-color: var(--accent);
  background: #fff8f3;
}

.list-header {
  display: flex;
  align-items: center;
  padding: 0.625rem 0.75rem;
  gap: 0.5rem;
}

.list-name {
  flex: 1;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.list-name:hover {
  color: var(--secondary);
}

.current-indicator {
  color: var(--accent);
  font-size: 0.6rem;
}

.word-count {
  font-size: 0.75rem;
  color: var(--text-light);
  font-weight: 400;
}

.list-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.study-btn {
  padding: 0.25rem 0.5rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

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

.study-btn-full {
  width: calc(100% - 1.5rem);
  margin: 0 0.75rem 0.5rem;
  padding: 0.5rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

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

.expand-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-light);
  font-size: 1rem;
  cursor: pointer;
  border-radius: 4px;
}

.expand-btn:hover {
  background: rgba(0,0,0,0.05);
}

.list-words {
  padding: 0 0.75rem 0.75rem;
}

.empty-words {
  font-size: 0.8rem;
  color: var(--text-light);
  font-style: italic;
  padding: 0.5rem 0;
}

.word-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  background: white;
  border-radius: 8px;
  margin-bottom: 0.35rem;
  border-left: 2px solid var(--secondary);
  transition: opacity 0.2s;
}

.word-item:hover {
  background: #f8f9fa;
}

.word-item.mastered {
  opacity: 0.5;
  border-left-color: #4caf50;
}

.mastered-indicator {
  color: #4caf50;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.word-pair {
  flex: 1;
  min-width: 0;
}

.word-text {
  display: block;
  font-weight: 600;
  color: var(--text);
  font-size: 0.85rem;
  word-break: break-word;
}

.word-reading {
  display: block;
  font-size: 0.75rem;
  color: var(--secondary);
  margin-top: 0.1rem;
}

.word-translation {
  display: block;
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 0.1rem;
}

/* Content */
.content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  min-width: 0;
}

/* Auth Section */
.auth-section {
  background: var(--card);
  padding: 2rem;
  border-radius: 20px;
  box-shadow: 0 4px 20px var(--shadow);
  margin-bottom: 1.5rem;
  text-align: center;
  border: 3px dashed var(--secondary);
}

.auth-section label {
  display: block;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text);
  font-size: 1.1rem;
}

.auth-input-row {
  display: flex;
  gap: 0.5rem;
  max-width: 320px;
  margin: 0 auto;
}

.auth-input-row input {
  flex: 1;
  padding: 0.875rem 1rem;
  border: 2px solid var(--light);
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.auth-input-row input:focus {
  outline: none;
  border-color: var(--secondary);
}

.auth-btn {
  padding: 0.875rem 1.5rem;
  background: var(--secondary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-btn:hover {
  background: var(--dark);
}

.auth-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Input Section - Speech Bubble Style */
.input-section {
  background: var(--card);
  padding: 1.5rem;
  border-radius: 20px;
  box-shadow: 0 4px 20px var(--shadow);
  margin-bottom: 1.5rem;
  position: relative;
  border: 3px solid var(--light);
}

.input-section::before {
  content: '✏️';
  position: absolute;
  top: -12px;
  left: 20px;
  background: var(--bg);
  padding: 0 8px;
  font-size: 1.25rem;
}

.input-section label {
  display: block;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text);
  font-size: 1rem;
}

.input-section textarea {
  width: 100%;
  padding: 1rem;
  border: 2px solid var(--light);
  border-radius: 12px;
  font-size: 16px;
  resize: vertical;
  font-family: inherit;
  min-height: 100px;
  transition: border-color 0.2s;
}

.input-section textarea:focus {
  outline: none;
  border-color: var(--secondary);
}

.input-section textarea::placeholder {
  color: #a0aec0;
}

/* Word List Selection for Dialogue Generation */
.wordlist-select-section {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--light);
  border-radius: 10px;
}

.wordlist-select-section label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 0.5rem;
}

.wordlist-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.wordlist-checkbox {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  background: white;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.wordlist-checkbox:hover {
  border-color: var(--secondary);
}

.wordlist-checkbox:has(input:checked) {
  background: var(--secondary);
  color: white;
}

.wordlist-checkbox input {
  display: none;
}

/* Script Mode Toggle (below textarea) */
.script-toggle-section {
  margin-top: 0.75rem;
}

.script-toggle-inline {
  display: inline-flex;
  gap: 0;
  background: var(--light);
  border-radius: 8px;
  padding: 3px;
}

.script-toggle-inline button {
  padding: 0.4rem 0.8rem;
  border: none;
  background: transparent;
  color: var(--text-light);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  font-family: inherit;
}

.script-toggle-inline button:hover {
  color: var(--text);
}

.script-toggle-inline button.active {
  background: var(--secondary);
  color: white;
}

/* New Dialogue Button (collapsed state) */
.new-dialogue-btn {
  width: 100%;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  color: var(--secondary);
  border: 2px dashed var(--secondary);
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  margin-bottom: 1rem;
}

.new-dialogue-btn:hover {
  background: var(--secondary);
  color: white;
  border-style: solid;
}

/* Generating dialogue loading state */
.generating-section {
  background: var(--card);
  border-radius: 16px;
  padding: 3rem 2rem;
  text-align: center;
  box-shadow: 0 4px 20px var(--shadow);
  animation: fadeIn 0.3s ease-out;
}

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

.generating-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.generating-section h3 {
  color: var(--text);
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.generating-section p {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.progress-bar {
  height: 6px;
  background: var(--light);
  border-radius: 3px;
  overflow: hidden;
  max-width: 300px;
  margin: 0 auto;
}

.progress-bar-inner {
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 3px;
  animation: progress 1.5s ease-in-out infinite;
}

@keyframes progress {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(250%); }
  100% { transform: translateX(-100%); }
}

.generate-btn {
  margin-top: 1rem;
  padding: 1rem 2rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  min-height: 52px;
  box-shadow: 0 4px 15px rgba(230, 57, 70, 0.3);
}

.generate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(230, 57, 70, 0.4);
}

.generate-btn:active:not(:disabled) {
  transform: translateY(0);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Dialogue Section */
.dialogue-section {
  background: var(--card);
  padding: 1.5rem;
  border-radius: 20px;
  box-shadow: 0 4px 20px var(--shadow);
  border: 3px solid var(--light);
  position: relative;
}

.dialogue-section::before {
  content: '🗣️';
  position: absolute;
  top: -12px;
  left: 20px;
  background: var(--bg);
  padding: 0 8px;
  font-size: 1.25rem;
}

.dialogue-section h2 {
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px dashed var(--light);
  font-weight: 700;
}

.dialogue-content {
  font-size: 1.1rem;
  line-height: 2;
  touch-action: manipulation;
}

/* Dialogue Lines - Chat Bubble Style */
.dialogue-line {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, #f8f9fa 0%, #f1f3f4 100%);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  position: relative;
  border-left: 4px solid var(--accent);
}

.dialogue-line:nth-child(even) {
  background: linear-gradient(135deg, #e8f4f8 0%, #dbeafe 100%);
  border-left-color: var(--secondary);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}

.speaker {
  font-weight: 800;
  color: var(--primary);
  display: block;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.dialogue-line:nth-child(even) .speaker {
  color: var(--secondary);
}

.keyword {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
  cursor: pointer;
  transition: all 0.2s;
}

.keyword:hover,
.keyword:active {
  text-decoration-color: var(--primary);
  background: rgba(244, 162, 97, 0.2);
  border-radius: 4px;
}

/* Edit Mode */
.edit-textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
  padding: 1rem;
  border-radius: 12px;
  border: 2px solid var(--secondary);
  background: var(--light);
  color: var(--text);
  resize: vertical;
  min-height: 200px;
}

.edit-textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}

.edit-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  justify-content: flex-end;
}

.edit-save-btn {
  padding: 0.6rem 1.25rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  min-height: 44px;
}

.edit-save-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(230, 57, 70, 0.3);
}

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

.edit-cancel-btn {
  padding: 0.6rem 1.25rem;
  background: transparent;
  border: 2px solid var(--light);
  color: var(--text-light);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  min-height: 44px;
}

.edit-cancel-btn:hover:not(:disabled) {
  border-color: var(--text-light);
  color: var(--text);
}

.edit-cancel-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Popup Overlay */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(29, 53, 87, 0.15);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.2s;
}

.popup-overlay.show {
  opacity: 1;
}

/* Popup - Speech Bubble */
.popup {
  position: fixed;
  background: var(--dark);
  color: white;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  text-align: center;
  transform: translate(-50%, -100%);
  margin-top: -8px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.15s;
}

.popup:hover {
  background: var(--secondary);
  transform: translate(-50%, -100%) scale(1.05);
}

.popup-reading {
  font-size: 0.85rem;
  opacity: 0.85;
  font-weight: 500;
}

.popup-translation {
  font-weight: 600;
}

.popup-hint {
  font-size: 0.7rem;
  opacity: 0.7;
  font-weight: 400;
}

.popup::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--dark);
}

/* Instructions */
.instructions {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-light);
  background: var(--card);
  border-radius: 20px;
  border: 3px dashed var(--light);
}

.instructions p {
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.instructions p:first-child {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--secondary) 0%, var(--dark) 100%);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  z-index: 101;
  box-shadow: 0 4px 20px rgba(29, 53, 87, 0.4);
  transition: transform 0.2s;
  border: 3px solid var(--light);
}

.sidebar-toggle:active {
  transform: scale(0.95);
}

.sidebar-toggle-icon {
  display: block;
  line-height: 1;
}

/* Mobile close button for sidebar */
.sidebar-close {
  display: none;
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  background: var(--light);
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
}

/* Responsive */
@media (max-width: 768px) {
  .header-inner {
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .header-logo {
    order: 1;
  }

  .logo-icon {
    font-size: 1.1rem;
  }

  .logo-text {
    font-size: 1.1rem;
  }

  .header-nav {
    order: 3;
    width: 100%;
    justify-content: center;
    gap: 0.5rem;
    padding-top: 0.35rem;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
  }

  .nav-divider {
    display: none;
  }

  .rate-limits-indicator {
    order: 2;
    margin-left: 0;
    margin-right: 0.5rem;
  }

  .header-user {
    order: 3;
  }

  .header-email-input {
    width: 100px;
  }

  .header-code-input {
    width: 70px;
  }

  .mode-toggle button {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
  }

  main {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    padding-top: 4rem;
    box-shadow: 4px 0 30px rgba(0,0,0,0.2);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(29, 53, 87, 0.6);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
  }

  .sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .content {
    padding: 1rem;
    padding-bottom: 5rem;
  }

  .input-section,
  .dialogue-section,
  .auth-section {
    padding: 1.25rem;
    border-radius: 16px;
  }

  .dialogue-content {
    font-size: 1rem;
    line-height: 1.9;
  }

  .dialogue-line {
    padding: 0.625rem 0.875rem;
    margin-bottom: 0.75rem;
  }

  .keyword {
    text-underline-offset: 2px;
  }

  /* Center popup on mobile */
  .popup {
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%);
    padding: 0.5rem 1rem;
    margin-top: 0;
    font-size: 1rem;
  }

  .popup:hover {
    transform: translate(-50%, -50%) scale(1.05);
  }

  .popup::after {
    display: none;
  }

  .generate-btn {
    padding: 1rem;
  }
}

@media (max-width: 380px) {
  .content {
    padding: 0.75rem;
  }

  .input-section,
  .dialogue-section,
  .auth-section {
    padding: 1rem;
    border-radius: 12px;
  }

  .dialogue-content {
    font-size: 0.95rem;
  }

  .logo-text {
    font-size: 1rem;
  }

  .logo-icon {
    font-size: 1rem;
  }

  .header-nav {
    gap: 0.35rem;
  }
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
  .content {
    padding-bottom: max(5rem, env(safe-area-inset-bottom));
  }

  .sidebar-toggle {
    bottom: max(1.5rem, env(safe-area-inset-bottom));
  }
}

/* Footer */
footer {
  text-align: center;
  padding: 1rem;
  margin-top: auto;
  display: flex;
  justify-content: center;
  gap: 1.5rem;
}

.footer-link {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.6;
  font-family: inherit;
}

.footer-link:hover {
  opacity: 1;
  text-decoration: underline;
}

.footer-link.active {
  opacity: 1;
  color: var(--primary);
  font-weight: 700;
}

/* Loading animation */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.generate-btn:disabled span {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Translate Icon */
.translate-icon {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.75rem;
  color: #c0c0c0;
  cursor: pointer;
  transition: all 0.2s;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  user-select: none;
}

.translate-icon:hover {
  color: var(--secondary);
  background: rgba(69, 123, 157, 0.1);
}

.translate-icon.loading {
  color: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.translate-icon.available {
  color: var(--secondary);
  font-weight: bold;
}

.translate-icon.available:hover {
  background: rgba(69, 123, 157, 0.2);
}

/* Dialogue line needs relative positioning for translate icon */
.dialogue-line {
  position: relative;
  padding-right: 2rem;
}

/* Line Translation Popup */
.line-popup {
  position: fixed;
  background: var(--dark);
  color: white;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 4px 15px rgba(0,0,0,0.25);
  text-align: center;
  transform: translate(-50%, -100%);
  margin-top: -12px;
  max-width: 90vw;
  line-height: 1.5;
}

.line-popup::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--dark);
}

@media (max-width: 768px) {
  .translate-icon {
    width: 24px;
    height: 24px;
    font-size: 0.8rem;
  }

  .dialogue-line {
    padding-right: 2.25rem;
  }

  /* Center line popup on mobile */
  .line-popup {
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%);
    margin-top: 0;
    max-width: 85vw;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
  }

  .line-popup::after {
    display: none;
  }
}

/* Flash Card Mode */
[x-cloak] {
  display: none !important;
}

.flashcard-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--bg) 0%, #fff 100%);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}

.flashcard-container {
  text-align: center;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  position: relative;
}

.flashcard-close {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 44px;
  background: var(--light);
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
  transition: all 0.2s;
}

.flashcard-close:hover {
  background: var(--primary);
  color: white;
}

.flashcard-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.flashcard-progress {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
  font-weight: 600;
}

.flashcard {
  width: 100%;
  height: 220px;
  perspective: 1000px;
  cursor: pointer;
  margin-bottom: 1.5rem;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard.no-transition .flashcard-inner {
  transition: none;
}

.flashcard-front,
.flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  font-size: 1.75rem;
  font-weight: 700;
  padding: 1.5rem;
  box-shadow: 0 8px 30px var(--shadow);
}

.flashcard-front {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
}

.flashcard-back {
  background: linear-gradient(135deg, var(--secondary) 0%, var(--dark) 100%);
  color: white;
  transform: rotateY(180deg);
  flex-direction: column;
  gap: 0.5rem;
}

.flashcard-reading {
  font-size: 1.25rem;
  opacity: 0.85;
  font-weight: 500;
}

.flashcard-nav {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.flashcard-nav-btn {
  padding: 0.75rem 1.5rem;
  background: var(--card);
  color: var(--text);
  border: 2px solid var(--light);
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.flashcard-nav-btn:hover {
  border-color: var(--secondary);
  color: var(--secondary);
}

.flashcard-hint {
  font-size: 0.85rem;
  color: var(--text-light);
  margin: 0;
}

/* TTS Speaker Button */
.flashcard-speak-btn {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 1.25rem;
}

.flashcard-speak-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

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

.flashcard-speak-btn.loading {
  animation: pulse 1s ease-in-out infinite;
}

/* Mastered button on flashcard back */
.flashcard-mastered-btn {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.7);
}

.flashcard-mastered-btn:hover {
  background: rgba(76, 175, 80, 0.8);
  color: white;
  transform: scale(1.1);
}

.flashcard-mastered-btn.active {
  background: #4caf50;
  color: white;
}

.flashcard-mastered-btn.active:hover {
  background: rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.9);
}

/* Footer with email section */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.footer-left,
.footer-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Email status indicator */
.email-status {
  font-size: 0.75rem;
  color: #4caf50;
  font-weight: 600;
}

/* Email form */
.email-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.email-form-input,
.email-form-code {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.email-input,
.code-input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--light);
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  width: 160px;
}

.code-input {
  width: 100px;
  text-align: center;
  letter-spacing: 2px;
  font-weight: 600;
}

.email-input:focus,
.code-input:focus {
  outline: none;
  border-color: var(--secondary);
}

.email-form-actions {
  display: flex;
  gap: 0.25rem;
}

.email-btn {
  padding: 0.4rem 0.6rem;
  background: var(--secondary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.email-btn:hover:not(:disabled) {
  background: var(--dark);
}

.email-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.email-login-btn {
  background: transparent;
  color: var(--secondary);
  border: 1px solid var(--secondary);
}

.email-login-btn:hover:not(:disabled) {
  background: var(--secondary);
  color: white;
}

.email-cancel-btn {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  opacity: 0.6;
}

.email-cancel-btn:hover {
  opacity: 1;
  color: var(--primary);
}

@media (max-width: 768px) {
  footer {
    flex-direction: column;
    gap: 0.75rem;
  }

  .footer-left,
  .footer-right {
    width: 100%;
    justify-content: center;
  }

  .email-form-input,
  .email-form-code {
    flex-wrap: wrap;
    justify-content: center;
  }

  .email-input {
    width: 100%;
    max-width: 200px;
  }
}

/* CAPTCHA Modal */
.captcha-overlay {
  position: fixed;
  inset: 0;
  background: rgba(29, 53, 87, 0.7);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
}

.captcha-modal {
  background: var(--card);
  padding: 2rem;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 360px;
  width: 90%;
  position: relative;
}

.captcha-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 32px;
  height: 32px;
  background: var(--light);
  border: none;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.captcha-close:hover {
  background: var(--primary);
  color: white;
}

.captcha-modal h3 {
  font-size: 1.25rem;
  color: var(--text);
  margin: 0 0 0.5rem 0;
  font-weight: 700;
}

.captcha-modal p {
  font-size: 0.9rem;
  color: var(--text-light);
  margin: 0 0 1.5rem 0;
}

#captcha-container {
  display: flex;
  justify-content: center;
  min-height: 65px;
}

@media (max-width: 380px) {
  .captcha-modal {
    padding: 1.5rem;
  }

  .captcha-modal h3 {
    font-size: 1.1rem;
  }
}


/* Community dialogue items */
.community-item {
  border-left-color: var(--accent) !important;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--light);
}

.pagination button {
  padding: 0.3rem 0.6rem;
  background: var(--secondary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  min-width: 36px;
  transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
  background: var(--dark);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination span {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 600;
}
