/* ----- global reset & typography ----- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #f2efe9;
  font-family: 'Segoe UI', Roboto, system-ui, -apple-system, sans-serif;
  padding: 2rem 1rem;
  display: flex;
  justify-content: center;
}

.book-container {
  max-width: 1300px;
  width: 100%;
  background: #ffffff;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08), 0 8px 20px rgba(0, 0, 0, 0.04);
  padding: 2.5rem 2.8rem 2rem;
  transition: all 0.2s;
}

/* ----- header / top bar ----- */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 2px solid #e6e1d8;
  padding-bottom: 0.9rem;
  margin-bottom: 1.5rem;
}

.top-bar h1 {
  font-size: 1.9rem;
  font-weight: 500;
  letter-spacing: -0.3px;
  color: #1f2a3a;
}
.top-bar h1 span {
  font-weight: 300;
  color: #6b7a8f;
}

.top-links {
  display: flex;
  gap: 1.6rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: #4a5a72;
  align-items: center;
  flex-wrap: wrap;
}
.top-links a {
  color: #2f4b7c;
  text-decoration: none;
  border-bottom: 1px dotted transparent;
  transition: border-color 0.2s;
}
.top-links a:hover {
  border-color: #2f4b7c;
}

/* ----- load controls ----- */
.load-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
  padding: 0.8rem 1.2rem;
  background: #f6f4f0;
  border-radius: 12px;
  border: 1px solid #e3dfd7;
}

.load-controls label {
  font-weight: 500;
  color: #3a4b62;
  font-size: 0.9rem;
}

.load-controls select {
  flex: 1;
  min-width: 180px;
  padding: 0.4rem 0.8rem;
  border: 1px solid #d0cbc1;
  border-radius: 8px;
  font-size: 0.9rem;
  background: #ffffff;
  color: #1f2a3a;
  cursor: pointer;
}
.load-controls select:focus {
  outline: none;
  border-color: #2f4b7c;
}

.refresh-btn {
  background: #eae6de;
  border: none;
  border-radius: 8px;
  padding: 0.3rem 0.8rem;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
}
.refresh-btn:hover {
  background: #d5cec2;
  transform: scale(1.05);
}
.refresh-btn:active {
  transform: scale(0.95);
}

.load-status {
  font-size: 0.8rem;
  color: #6b7f97;
  margin-left: auto;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.load-status.success {
  color: #2a7d4f;
}
.load-status.error {
  color: #b03a2e;
}
.load-status.loading {
  color: #b08a2e;
}
.load-status.recording {
  color: #e74c3c;
  animation: pulseText 1s infinite;
}

@keyframes pulseText {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ----- import controls ----- */
.import-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
  padding: 0.8rem 1.2rem;
  background: #e8f5e8;
  border-radius: 12px;
  border: 1px solid #b8d8b8;
}

.import-controls .label {
  font-weight: 500;
  color: #1a3a1a;
  font-size: 0.9rem;
}

.import-controls .file-input {
  padding: 0.3rem 0.6rem;
  border: 1px solid #b8d8b8;
  border-radius: 8px;
  font-size: 0.85rem;
  background: #ffffff;
  flex: 1;
  min-width: 200px;
}
.import-controls .file-input::-webkit-file-upload-button {
  background: #2f4b7c;
  color: white;
  border: none;
  padding: 0.3rem 1rem;
  border-radius: 6px;
  cursor: pointer;
}

.import-btn {
  background: #28a745;
  border: none;
  border-radius: 8px;
  padding: 0.4rem 1.2rem;
  color: #ffffff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.import-btn:hover {
  background: #1e7e34;
  transform: scale(1.02);
}
.import-btn:active {
  transform: scale(0.97);
}

.import-status {
  font-size: 0.8rem;
  color: #4a6a4a;
  margin-left: auto;
}
.import-status.success {
  color: #2a7d4f;
}
.import-status.error {
  color: #b03a2e;
}

/* ----- notification controls ----- */
.notification-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1.5rem;
  padding: 0.8rem 1.2rem;
  background: #e8f0fe;
  border-radius: 12px;
  border: 1px solid #b8d0e8;
}

.notification-controls .label {
  font-weight: 500;
  color: #1a3a5a;
  font-size: 0.9rem;
}

.notification-controls .interval-input {
  width: 80px;
  padding: 0.4rem 0.6rem;
  border: 1px solid #b8d0e8;
  border-radius: 8px;
  font-size: 0.9rem;
  text-align: center;
}
.notification-controls .interval-input:focus {
  outline: none;
  border-color: #2f4b7c;
}

.notif-btn {
  background: #2f4b7c;
  border: none;
  border-radius: 8px;
  padding: 0.4rem 1.2rem;
  color: #ffffff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.notif-btn:hover {
  background: #1d3a66;
  transform: scale(1.02);
}
.notif-btn:active {
  transform: scale(0.97);
}
.notif-btn.active {
  background: #c0392b;
}
.notif-btn.active:hover {
  background: #a93226;
}
.notif-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.notif-status {
  font-size: 0.8rem;
  color: #4a6a8a;
  margin-left: auto;
}
.notif-status.active {
  color: #c0392b;
  animation: pulseText 1s infinite;
}

/* ----- section headings ----- */
.section-head {
  display: flex;
  align-items: baseline;
  gap: 1.2rem;
  margin: 2.2rem 0 1.2rem 0;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid #dad5cc;
}
.section-head .num {
  font-size: 1.1rem;
  font-weight: 600;
  color: #7f8c9e;
  background: #edebe6;
  padding: 0.1rem 0.9rem;
  border-radius: 40px;
  letter-spacing: 0.3px;
}
.section-head h2 {
  font-size: 1.7rem;
  font-weight: 450;
  color: #1d2b3c;
  letter-spacing: -0.2px;
}
.section-head .sub {
  font-size: 1rem;
  font-weight: 400;
  color: #7a879b;
  margin-left: auto;
  font-style: italic;
}

/* ----- five‑column table ----- */
.lang-table {
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid #e3dfd7;
  margin: 0.5rem 0 1rem 0;
  background: #fcfbf9;
}

.lang-row {
  display: grid;
  grid-template-columns: 1fr 1fr 52px 52px 52px;
  border-bottom: 1px solid #eae6de;
  align-items: center;
}
.lang-row:last-child {
  border-bottom: none;
}

.lang-row .en {
  padding: 0.7rem 1.2rem;
  font-weight: 450;
  color: #1f2a3a;
  background: #f8f6f2;
  border-right: 1px solid #e3dfd7;
}

.lang-row .xh-cell {
  padding: 0.4rem 1.2rem 0.4rem 1.2rem;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  border-right: 1px solid #e3dfd7;
}

.lang-row .xh-text {
  flex: 1;
  min-width: 100px;
  color: #1f3a4b;
  padding: 0.3rem 0;
}

.lang-row .xh-text.hidden {
  display: none;
}

.toggle-btn {
  background: #eae6de;
  border: none;
  border-radius: 40px;
  padding: 0.2rem 0.9rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: #3a4b62;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.3px;
  white-space: nowrap;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.toggle-btn:hover {
  background: #d5cec2;
  color: #1d2b3c;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.toggle-btn:active {
  transform: scale(0.96);
}

/* ----- audio action columns ----- */
.lang-row .audio-cell {
  padding: 0.3rem 0.2rem;
  background: #faf9f7;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lang-row .record-cell {
  padding: 0.3rem 0.2rem;
  background: #faf9f7;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid #eae6de;
}

.lang-row .import-cell {
  padding: 0.3rem 0.2rem;
  background: #faf9f7;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid #eae6de;
}

.action-btn {
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.action-btn:hover {
  transform: scale(1.05);
}
.action-btn:active {
  transform: scale(0.92);
}
.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.play-btn {
  background: #2f4b7c;
  color: #ffffff;
}
.play-btn:hover:not(:disabled) {
  background: #1d3a66;
  box-shadow: 0 4px 12px rgba(47, 75, 124, 0.3);
}
.play-btn.playing {
  background: #c0392b;
  box-shadow: 0 2px 6px rgba(192, 57, 43, 0.3);
}
.play-btn.has-audio {
  background: #28a745;
}
.play-btn.has-audio:hover:not(:disabled) {
  background: #1e7e34;
  box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

.record-btn {
  background: #e74c3c;
  color: #ffffff;
}
.record-btn:hover:not(:disabled) {
  background: #c0392b;
  box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}
.record-btn.recording {
  background: #c0392b;
  animation: pulse 1s infinite;
  box-shadow: 0 0 0 4px rgba(231, 76, 60, 0.2);
}
.record-btn.has-recording {
  background: #27ae60;
}
.record-btn.has-recording:hover:not(:disabled) {
  background: #1e8449;
  box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3);
}
.record-btn.saving {
  background: #f39c12;
  animation: none;
}

.import-btn-small {
  background: #17a2b8;
  color: #ffffff;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.import-btn-small:hover {
  background: #138496;
  transform: scale(1.05);
}
.import-btn-small:active {
  transform: scale(0.92);
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* alternate row shading */
.lang-row:nth-child(even) .en {
  background: #f3f0ea;
}
.lang-row:nth-child(even) .xh-cell {
  background: #faf8f5;
}
.lang-row:nth-child(even) .audio-cell {
  background: #f6f4f0;
}
.lang-row:nth-child(even) .record-cell {
  background: #f6f4f0;
}
.lang-row:nth-child(even) .import-cell {
  background: #f6f4f0;
}

.lang-row.sentence .en {
  background: #edf0f5;
  font-weight: 500;
  color: #003b5c;
}
.lang-row.sentence .xh-cell {
  background: #f5f8fc;
}
.lang-row.sentence .xh-text {
  font-weight: 500;
  color: #003b5c;
}
.lang-row.sentence .audio-cell {
  background: #f0f4fa;
}
.lang-row.sentence .record-cell {
  background: #f0f4fa;
}
.lang-row.sentence .import-cell {
  background: #f0f4fa;
}

.toggle-label {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #6b7f97;
  background: #eae6de;
  padding: 0.2rem 1rem;
  border-radius: 30px;
  letter-spacing: 0.3px;
  margin: 0.2rem 0 0.6rem 0;
  cursor: default;
}

.footer-bar {
  margin-top: 2.8rem;
  padding-top: 1.5rem;
  border-top: 2px solid #e6e1d8;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: #4f5f74;
}
.footer-bar .copy {
  color: #4f5f74;
}
.footer-bar .copy a {
  color: #2f4b7c;
  text-decoration: none;
  border-bottom: 1px dotted #b0bed0;
}
.footer-bar .copy a:hover {
  border-bottom-color: #2f4b7c;
}
.footer-bar .brand {
  font-weight: 500;
  color: #1f2a3a;
}

.empty-state {
  padding: 3rem 2rem;
  text-align: center;
  color: #7a879b;
  font-size: 1.1rem;
  background: #faf9f7;
  border-radius: 14px;
  border: 2px dashed #d0cbc1;
}
.empty-state strong {
  color: #1f2a3a;
}

/* Hidden file input */
.hidden-file-input {
  display: none;
}

/* ----- responsive ----- */
@media (max-width: 900px) {
  .book-container {
    padding: 1.5rem 1rem;
  }
  .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }
  .top-links {
    flex-wrap: wrap;
    gap: 0.8rem 1.2rem;
  }
  .load-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .load-controls select {
    min-width: unset;
  }
  .load-status {
    margin-left: 0;
    text-align: center;
    white-space: normal;
    max-width: 100%;
  }
  .import-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .import-controls .file-input {
    min-width: unset;
  }
  .import-status {
    margin-left: 0;
    text-align: center;
  }
  .notification-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .notification-controls .notif-status {
    margin-left: 0;
    text-align: center;
  }
  .section-head {
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
  }
  .section-head .sub {
    margin-left: 0;
    width: 100%;
  }
  .lang-row {
    grid-template-columns: 1fr 1fr 40px 40px 40px;
    border-bottom: 1px solid #ddd8ce;
  }
  .lang-row .en {
    border-right: none;
    border-bottom: 1px dashed #ddd8ce;
    padding: 0.6rem 1rem;
    font-weight: 600;
    background: #f3f0ea;
  }
  .lang-row .xh-cell {
    padding: 0.4rem 0.6rem;
    background: #fcfbf9;
    flex-wrap: wrap;
    border-right: none;
  }
  .lang-row .audio-cell {
    padding: 0.3rem 0.1rem;
  }
  .lang-row .record-cell {
    padding: 0.3rem 0.1rem;
    border-left: none;
  }
  .lang-row .import-cell {
    padding: 0.3rem 0.1rem;
    border-left: none;
  }
  .lang-row:nth-child(even) .en {
    background: #ede9e2;
  }
  .lang-row:nth-child(even) .xh-cell {
    background: #f8f6f2;
  }
  .lang-row:nth-child(even) .audio-cell {
    background: #f3f1ec;
  }
  .lang-row:nth-child(even) .record-cell {
    background: #f3f1ec;
  }
  .lang-row:nth-child(even) .import-cell {
    background: #f3f1ec;
  }
  .footer-bar {
    flex-direction: column;
    gap: 0.6rem;
    align-items: flex-start;
  }
  .toggle-btn {
    font-size: 0.6rem;
    padding: 0.15rem 0.7rem;
    height: 24px;
  }
  .action-btn {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
  }
  .import-btn-small {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
  }
}

@media (max-width: 550px) {
  .lang-row {
    grid-template-columns: 1fr 1fr 32px 32px 32px;
    font-size: 0.85rem;
  }
  .lang-row .en {
    font-size: 0.85rem;
    padding: 0.4rem 0.5rem;
  }
  .lang-row .xh-cell {
    padding: 0.3rem 0.3rem;
  }
  .lang-row .xh-text {
    font-size: 0.8rem;
    min-width: 50px;
  }
  .action-btn {
    width: 24px;
    height: 24px;
    font-size: 0.6rem;
  }
  .import-btn-small {
    width: 24px;
    height: 24px;
    font-size: 0.6rem;
  }
  .toggle-btn {
    font-size: 0.55rem;
    padding: 0.1rem 0.5rem;
    height: 20px;
  }
}