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

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #e63946;
  --secondary: #457b9d;
  --accent: #f4a261;
  --dark: #1d3557;
  --light: #f1faee;
  --bg: #fef9ef;
  --text: #2d3436;
  --text-light: #636e72;
}

body {
  font-family: 'Nunito', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  word-break: auto-phrase;
  line-break: strict;
  overflow-wrap: break-word;
}

[x-cloak] { display: none !important; }

.page-header {
  background: var(--dark);
  color: white;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.page-header h1 { font-size: 1.25rem; font-weight: 700; }
.page-header a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.page-header a:hover { text-decoration: underline; }

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

/* Top bar / source filter */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.top-bar .count {
  font-size: 0.85rem;
  color: var(--text-light);
}
.source-filter {
  display: inline-flex;
  border: 1px solid var(--light);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}
.source-filter button {
  padding: 0.4rem 0.9rem;
  border: none;
  background: white;
  color: var(--text-light);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.source-filter button.active {
  background: var(--secondary);
  color: white;
}
.source-filter button:not(.active):hover { background: var(--light); }

/* List view: cards */
.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}
.article-card {
  background: white;
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  box-shadow: 0 1px 4px rgba(29, 53, 87, 0.06);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  cursor: pointer;
  border-left: 3px solid var(--secondary);
  transition: box-shadow 0.15s, transform 0.15s;
}
.article-card.japanese { border-left-color: var(--primary); }
.article-card:hover {
  box-shadow: 0 4px 12px rgba(29, 53, 87, 0.12);
  transform: translateY(-1px);
}
.article-card-badges {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-mode {
  background: var(--light);
  color: var(--secondary);
}
.article-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--dark);
  line-height: 1.35;
}
.article-card-date {
  font-size: 0.75rem;
  color: var(--text-light);
  opacity: 0.8;
  margin-top: auto;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
}
.pagination button {
  padding: 0.4rem 1rem;
  border: 1px solid var(--light);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info { font-size: 0.85rem; color: var(--text-light); }

/* Empty / loading / auth */
.loading-state, .empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light);
}
.auth-prompt {
  text-align: center;
  padding: 4rem 1rem;
}
.auth-prompt p { color: var(--text-light); margin-bottom: 1rem; }
.auth-prompt a { color: var(--secondary); font-weight: 600; }

/* Detail view */
.detail-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.back-link {
  color: var(--secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.back-link:hover { text-decoration: underline; }
.detail-source {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.detail-date {
  font-size: 0.8rem;
  color: var(--text-light);
}
.detail-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--dark);
  margin-bottom: 1rem;
  line-height: 1.3;
}

/* Level toggle (mirrors .script-toggle-inline pattern) */
.level-toggle {
  display: inline-flex;
  border: 1px solid var(--light);
  border-radius: 8px;
  overflow: hidden;
  background: white;
  margin-bottom: 1.25rem;
}
.level-toggle button {
  padding: 0.45rem 1rem;
  border: none;
  background: white;
  color: var(--text-light);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.level-toggle button.active {
  background: var(--dark);
  color: white;
}
.level-toggle button:not(.active):hover { background: var(--light); }

/* Article body */
.article-body {
  background: white;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 4px rgba(29, 53, 87, 0.06);
}
.article-paragraph {
  font-size: 1.05rem;
  line-height: 2.4;
  margin-bottom: 1.25rem;
}
.article-paragraph:last-child { margin-bottom: 0; }
.article-sentence {
  display: inline;
  padding-left: 2.4rem;
  position: relative;
}

.detail-hint {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(244, 162, 97, 0.15);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-light);
}

/* ===== Reused styles for keywords / popup / speak icon (copied from style.css) ===== */

.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;
}

.speak-icon {
  position: absolute;
  left: 0;
  top: 0.2rem;
  font-size: 0.85rem;
  color: #a0a0a0;
  cursor: pointer;
  transition: all 0.2s;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-left: 2px;
  border-radius: 50%;
  user-select: none;
  background: rgba(0, 0, 0, 0.05);
}
.speak-icon:hover {
  color: var(--secondary);
  background: rgba(69, 123, 157, 0.15);
}
.speak-icon.loading {
  color: var(--accent);
  animation: speak-pulse 1s ease-in-out infinite;
}
.speak-icon.playing {
  color: var(--primary);
  background: rgba(230, 57, 70, 0.15);
}
@keyframes speak-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Popup */
.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;
  pointer-events: none;
}
.popup-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.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: normal;
  max-width: 350px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  transition: background 0.15s;
}
.popup:hover { background: var(--secondary); }
.popup-type {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
}
.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;
  width: 100%;
}
.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);
}

@media (max-width: 600px) {
  .page-header { padding: 0.8rem 1rem; }
  .container { padding: 1rem 0.75rem 3rem; }
  .detail-title { font-size: 1.25rem; }
  .article-paragraph { font-size: 1rem; line-height: 1.8; }
  .popup { max-width: 85vw; }
  .popup::after { display: none; }
}
