.word-progress {
  text-align: center;
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--brand-border);
  box-shadow: 0 2px 8px var(--brand-shadow);
  background: linear-gradient(135deg, #f3f4f6 0%, #ffffff 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.nav-controls {
  width: 100%;
  max-width: 300px;
}

.word-nav-select {
  width: 100%;
  padding: 6px 10px;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--brand-border);
  background-color: white;
  color: var(--brand-secondary);
  cursor: pointer;
}

.word-nav-select:focus {
  outline: 2px solid rgba(75, 85, 99, 0.2);
  border-color: var(--brand-primary);
}

.word-progress p {
  margin: 0;
  color: var(--brand-secondary);
  font-weight: 700;
  font-size: 0.9rem;
}
:root {
  --brand-primary: #4b5563; /* gray-600 */
  --brand-primary-dark: #374151; /* gray-700 */
  --brand-accent: #6b7280; /* gray-500 */
  --brand-secondary: #1f2937; /* gray-800 */
  --brand-muted: #f3f4f6; /* gray-100 */
  --brand-border: #e5e7eb; /* gray-200 */
  --brand-shadow: rgba(17, 24, 39, 0.12); /* slate-900 @ 12% */
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--brand-secondary);
  background-color: #f8fafc;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: 
    linear-gradient(rgba(248, 250, 252, 0.92), rgba(248, 250, 252, 0.92)),
    url('/images/voice.jpg') center/cover no-repeat fixed;
  padding: 24px;
  overflow-x: hidden;
}

.container {
  width: min(900px, 100%);
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-x: hidden;
}

header {
  text-align: center;
}

.header-logo h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 3rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

header p {
  margin: 4px 0 0;
  color: rgba(63, 63, 63, 0.8);
}

.card {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 10px 25px var(--brand-shadow);
  overflow-x: hidden;
  max-width: 100%;
  position: relative;
}

/* Back button */
.back-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-muted);
  border: 1px solid var(--brand-border);
  color: var(--brand-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  z-index: 10;
}

.back-btn:hover {
  background: #e5e7eb;
  color: var(--brand-secondary);
  transform: translateX(-2px);
}

/* Record controls */
.restart-btn {
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--brand-accent);
  border: none;
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
  box-shadow: 0 2px 8px var(--brand-shadow);
  min-width: 160px;
}

.restart-btn:hover {
  background: var(--brand-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--brand-shadow);
}

/* Language hero */
.lang-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

/* Mode, form and record sections with back button */
#mode-section.card,
#form-section.card,
#record-section.card {
  padding-top: 64px;
}

.lang-hero-content {
  text-align: center;
  width: 100%;
}

.lang-title {
  margin: 0 0 6px 0;
  font-size: clamp(1.4rem, 2.8vw, 2rem);
}

.lang-subtitle {
  margin: 0 0 18px 0;
  color: #475569;
}

.lang-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.lang-card {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 6px;
  align-items: center;
  justify-items: center;
  padding: 16px 14px;
  border: 1px solid var(--brand-border);
  border-radius: 12px;
  background: var(--brand-muted);
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.lang-card:hover {
  transform: translateY(-2px);
  border-color: var(--brand-primary);
  box-shadow: 0 10px 22px var(--brand-shadow);
}

.lang-emoji { font-size: 1.6rem; }
.lang-name { font-weight: 700; color: #0f172a; font-size: 0.95rem; }
.lang-code { color: #64748b; font-size: 0.85rem; }

.hidden {
  display: none;
}

form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.form-status {
  grid-column: 1 / -1;
  margin: 0;
  font-weight: 500;
  color: #0f172a;
}

.form-status.error {
  color: #dc2626;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-weight: 600;
  color: var(--brand-secondary);
}

/* Modal styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.modal:not(.hidden) {
  display: flex !important;
}

.modal-content {
  position: relative;
  background: white;
  padding: 32px;
  border-radius: 16px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalFadeIn 0.3s ease;
  z-index: 10000;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-content h3 {
  margin: 0 0 16px 0;
  font-size: 1.4rem;
  color: var(--brand-secondary);
}

.modal-content p {
  margin: 0 0 24px 0;
  color: var(--brand-secondary);
  line-height: 1.6;
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.btn-primary, .btn-secondary {
  padding: 10px 24px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-size: 0.9rem;
  transition: all 0.2s;
  pointer-events: auto;
  position: relative;
  z-index: 10001;
}

.btn-primary {
  background: var(--brand-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--brand-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--brand-shadow);
}

.btn-secondary {
  background: #e2e8f0;
  color: #475569;
}

.btn-secondary:hover {
  background: #cbd5e1;
}

input,
select {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--brand-border);
  padding: 12px;
}

button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 20px;
  font-size: 0.95rem;
}

input:focus,
select:focus {
  outline: 2px solid rgba(75, 85, 99, 0.5);
  border-color: transparent;
}

button {
  cursor: pointer;
  background: var(--brand-primary);
  color: #fff;
  font-weight: 600;
  transition: transform 150ms ease, box-shadow 150ms ease;
  border: none;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px var(--brand-shadow);
}

.word-box {
  text-align: center;
  padding: 32px 24px;
  border-radius: 16px;
  background: linear-gradient(135deg, #f3f4f6 0%, #fafafa 100%);
  min-height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 2px solid rgba(55, 65, 81, 0.15);
  box-shadow: 0 4px 16px var(--brand-shadow);
}

.word-box.sentence-mode-container {
  min-height: 280px;
  padding: 40px 48px;
  background: linear-gradient(135deg, #eef2f7 0%, #e9edf3 100%);
  border: 2px solid rgba(55, 65, 81, 0.2);
  box-shadow: 0 8px 24px var(--brand-shadow);
}

.word-box .helper {
  margin: 0 0 18px 0;
  color: rgba(63, 63, 63, 0.7);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.word-box .word {
  margin: 12px 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--brand-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  word-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  box-sizing: border-box;
}

.word-box .word.sentence-mode {
  font-size: clamp(1.15rem, 2.4vw, 1.45rem);
  font-weight: 500;
  letter-spacing: 0.4px;
  line-height: 1.75;
  text-align: left;
  padding: 20px 28px;
  max-height: 400px; /* Limit height to prevent scrolling the whole page */
  overflow-y: auto; /* Add scrollbar for the text itself */
  width: 100%;
  overflow-x: hidden;
  background: rgba(255,255,255,0.98);
  border-radius: 14px;
  border: 2px solid rgba(55, 65, 81, 0.2);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  word-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
  color: #0f172a;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.word-box .word.sentence-mode .highlight {
  color: #000000;
  font-weight: 800;
  background-color: rgba(255, 255, 0, 0.15);
  padding: 0 2px;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.word-box .word.sentence-mode::-webkit-scrollbar {
  width: 10px;
}

.word-box .word.sentence-mode::-webkit-scrollbar-track {
  background: rgba(226, 232, 240, 0.4);
  border-radius: 5px;
  margin: 6px 0;
}

.word-box .word.sentence-mode::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--brand-primary) 0%, var(--brand-primary-dark) 100%);
  border-radius: 5px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  transition: background 0.2s;
}

.word-box .word.sentence-mode::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, var(--brand-primary-dark) 0%, #4a0b00 100%);
  border-color: rgba(255, 255, 255, 0.6);
}

.attempt-info {
  margin: 6px 0 0 0;
  color: #475569;
  font-weight: 500;
  font-size: 0.9rem;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  background: rgba(75, 85, 99, 0.12);
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brand-primary);
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  color: #0f172a;
  max-width: 100%;
  overflow: hidden;
}

.status-line p {
  margin: 0;
  font-size: 0.85rem;
  white-space: nowrap;
  min-width: 60px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  font-weight: 600;
  color: rgba(63, 63, 63, 0.85);
}

.progress-wrapper {
  flex: 1;
  position: relative;
  height: 24px;
  min-width: 0;
}

.progress-time {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  font-weight: 700;
  color: #0f172a;
  pointer-events: none;
  z-index: 10;
  text-shadow: 0 0 3px rgba(255,255,255,0.9);
}

progress {
  width: 100%;
  height: 24px;
  border-radius: 999px;
  border: none;
  background: #e2e8f0;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.12);
  display: block;
}

progress::-webkit-progress-bar {
  border-radius: 999px;
  background: #e2e8f0;
}

progress::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-primary) 0%, var(--brand-accent) 100%);
  box-shadow: 0 2px 8px var(--brand-shadow);
  transition: width 0.3s ease;
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
  gap: 12px;
}

.action-buttons {
  display: flex;
  gap: 12px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.actions button {
  min-width: 160px;
  padding: 12px 20px;
  font-size: 0.95rem;
  flex: 0 1 auto;
}

#record-btn {
  background: var(--brand-primary);
  color: white;
}

.shortcut-hint {
  margin: 8px 0 0 0;
  font-size: 0.85rem;
  color: #64748b;
  text-align: center;
}

.user-card {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.user-info {
  margin: 4px 0 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #0f172a;
}

.user-card button {
  padding-inline: 20px;
  background: #f1f5f9;
  color: #0f172a;
  border: 1px solid #cbd5f5;
}

.user-card button:hover {
  box-shadow: none;
  transform: none;
}

.history {
  margin-top: 20px;
  height: 220px;
  padding: 12px 12px 12px 16px;
  border: 1px solid var(--brand-border);
  border-radius: 14px;
  background: var(--brand-muted);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5),
    0 8px 18px var(--brand-shadow);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Recording section tidy layout */
#record-section.card {
  max-width: 980px;
  margin-inline: auto;
}

#record-section .word-box { margin-top: 8px; }
#record-section .status-line { margin-top: 18px; }

/* Recording grid layout */
.record-grid {
  display: grid;
  grid-template-columns: 2fr 0.9fr;
  gap: 20px;
  max-width: 100%;
  overflow: hidden;
}

@media (max-width: 1000px) {
  .record-grid { 
    grid-template-columns: 1fr; 
  }
}

.record-side .subcard + .subcard { margin-top: 12px; }

.subcard {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  padding: 14px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.05);
}

.subcard h3 {
  margin: 0 0 10px 0;
  font-size: 0.8rem;
  color: #475569;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.summary-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: #64748b;
  padding: 5px 0;
  border-bottom: 1px solid #e2e8f0;
}

.summary-list li:last-child {
  border-bottom: none;
}

.summary-list li strong {
  color: #1e293b;
  font-weight: 600;
  font-size: 0.8rem;
}

.tips-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tips-list li {
  font-size: 0.75rem;
  color: #64748b;
  line-height: 1.4;
  padding-left: 14px;
  position: relative;
}

.tips-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--brand-primary);
  font-weight: bold;
  font-size: 1em;
}

.shortcut-hint {
  margin: 8px 0 0 0;
  color: #64748b;
  font-size: 0.85rem;
  text-align: center;
}

.badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(75, 85, 99, 0.15);
  color: #374151;
  font-weight: 600;
  font-size: 0.85rem;
  border: 1px solid rgba(75, 85, 99, 0.2);
}

.history-card { margin-top: 16px; }

.history-entry {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid var(--brand-border);
  box-shadow: 0 6px 18px var(--brand-shadow);
  font-size: 0.85rem;
  color: var(--brand-secondary);
  position: relative;
  overflow: hidden;
  max-width: 100%;
  word-wrap: break-word;
  hyphens: auto;
}

.history-entry::before {
  content: "";
  width: 4px;
  height: 60%;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--brand-primary), var(--brand-accent));
  position: absolute;
  left: 8px;
  top: 20%;
}

.history-entry span {
  padding-left: 18px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Responsive design */
@media (max-width: 768px) {
  .record-grid {
    grid-template-columns: 1fr;
  }
  
  .container {
    padding: 0;
  }
  
  body {
    padding: 12px;
  }
  
  .word-box {
    padding: 24px 16px;
    min-height: 140px;
  }
  
  .word-box.sentence-mode-container {
    min-height: 240px;
    padding: 32px 24px;
  }
  
  .word-box .word.sentence-mode {
    font-size: clamp(1.05rem, 2.4vw, 1.3rem);
    padding: 18px 20px;
    line-height: 1.7;
    letter-spacing: 0.3px;
  }
  
  .action-buttons {
    flex-direction: column;
    width: 100%;
  }
  
  .actions button {
    width: 100%;
    min-width: unset;
  }
  
  .status-line {
    gap: 12px;
  }
  
  .status-line p {
    font-size: 0.75rem;
    max-width: 80px;
    min-width: 50px;
  }
  
  .back-btn {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
  
  .restart-btn {
    font-size: 0.9rem;
    padding: 10px 16px;
  }
  
  .record-side .subcard {
    padding: 14px;
  }
  
  .summary-list li,
  .tips-list li {
    font-size: 0.8rem;
  }
}

/* Footer styles */
.footer {
  margin-top: 32px;
  padding: 24px 0;
  text-align: center;
  border-top: 1px solid var(--brand-border);
}

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

.footer-text {
  margin: 0;
  color: var(--brand-secondary);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.footer-separator {
  color: var(--brand-border);
}

#footer-brand {
  font-weight: 700;
  color: var(--brand-primary);
}

#footer-desc {
  color: rgba(63, 63, 63, 0.7);
}