:root {
  --bg: #1a0a0a;
  --bg-soft: #2d0f0f;
  --surface: #ffffff;
  --surface-alt: #fdf2f2;
  --border: #f0d6d6;
  --border-soft: #fbecec;
  --text: #2a0f0f;
  --text-muted: #7c5a5a;
  --text-light: #b79494;
  --primary: #b91c1c;
  --primary-dark: #7f1d1d;
  --primary-soft: #fee2e2;
  --accent: #ea580c;
  --success: #15803d;
  --danger: #991b1b;
  --shadow-sm: 0 1px 2px rgba(124,20,20,0.06);
  --shadow-md: 0 4px 12px rgba(124,20,20,0.09);
  --shadow-lg: 0 12px 28px rgba(124,20,20,0.14);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic Pro", "Yu Gothic", "Meiryo", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface-alt);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100vh;
  min-height: 100dvh;
}

/* HEADER */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding-top: var(--safe-top);
  box-shadow: var(--shadow-md);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  min-height: 56px;
}
#page-title {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.15);
  color: white;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:active { background: rgba(255,255,255,0.3); }

/* MAIN */
#main {
  flex: 1;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
.view { display: none; padding: 16px; padding-bottom: calc(24px + var(--safe-bot)); animation: fadeIn 0.25s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.section-title {
  font-size: 16px;
  font-weight: 700;
  margin: 24px 0 12px;
  padding-left: 4px;
  color: var(--text);
}

/* STATS BAR */
.stats-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat-num {
  display: block;
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
}
.stat-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 600;
}

/* SEARCH */
.search-wrap {
  position: relative;
  margin-bottom: 8px;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}
.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(185,28,28,0.1);
}
.search-icon {
  flex-shrink: 0;
  margin-left: 14px;
  color: var(--text-light);
}
#search-input {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  padding: 14px 12px;
  font-size: 16px;
  color: var(--text);
  min-width: 0;
}
#search-input::placeholder { color: var(--text-light); }
.btn-clear {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
}
.btn-clear:active { background: var(--surface-alt); }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 50;
  display: none;
}
.search-results.open { display: block; }
.search-result-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:active { background: var(--primary-soft); }
.sr-kanji-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.sr-kanji {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.sr-kana {
  font-size: 14px;
  color: var(--text-muted);
}
.sr-meaning {
  font-size: 14px;
  color: var(--text);
  margin-top: 6px;
}
.sr-meta {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  flex-wrap: wrap;
}
.sr-tag {
  padding: 2px 8px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-radius: 999px;
  font-weight: 600;
}
.sr-tag.jlpt { background: #fef3c7; color: #b45309; }
.sr-tag.col { background: #e0f2fe; color: #0369a1; }
.search-no-result {
  padding: 20px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.search-count {
  padding: 8px 16px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

/* COLLECTIONS GRID */
.collections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.col-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 14px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.col-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  opacity: 0;
  transition: opacity 0.15s;
}
.col-card:active { transform: scale(0.97); box-shadow: var(--shadow-md); border-color: var(--primary); }
.col-card:active::before { opacity: 1; }
.col-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.col-card-range {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}
.col-card-count {
  display: inline-flex;
  margin-top: 10px;
  font-size: 12px;
  padding: 3px 10px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-radius: 999px;
  font-weight: 700;
}

/* COLLECTION VIEW */
.collection-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-radius: var(--radius-xl);
  padding: 18px 16px;
  color: white;
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
}
.collection-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.col-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  background: rgba(255,255,255,0.22);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.col-range {
  font-size: 15px;
  font-weight: 600;
  opacity: 0.95;
}
.collection-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.btn-primary {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  background: white;
  color: var(--primary-dark);
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.btn-primary:active { transform: scale(0.97); background: var(--primary-soft); }
.words-count {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 12px;
  padding-left: 4px;
}

.settings-panel {
  background: linear-gradient(180deg, #ffffff 0%, #fef5f5 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 14px 16px 14px;
  margin-bottom: 16px;
  box-shadow:
    0 1px 2px rgba(185, 28, 28, 0.04),
    0 4px 18px rgba(185, 28, 28, 0.05);
}
.settings-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--primary-dark);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border-soft);
  text-transform: uppercase;
}
.settings-title svg { flex-shrink: 0; opacity: 0.85; }

.settings-row.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  row-gap: 8px;
  align-items: center;
}
.chip-toggle { display: inline-flex; user-select: none; cursor: pointer; position: relative; }
.chip-toggle input.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  appearance: none;
  -webkit-appearance: none;
}
.chip-toggle .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 13px 9px 11px;
  border-radius: 999px;
  background: #ffffff;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  transition: all 0.18s cubic-bezier(0.2, 0, 0, 1);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.chip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: #fff7ed;
  font-size: 12px;
  font-weight: 700;
  color: #9a3412;
  transition: all 0.18s ease;
}
.chip-label { white-space: nowrap; }
.chip-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: transparent;
  color: transparent;
  font-size: 11px;
  font-weight: 800;
  margin-left: 2px;
  line-height: 1;
  transition: all 0.18s ease;
}
.chip-toggle input.toggle-input:checked ~ .chip,
.chip-toggle:has(input.toggle-input:checked) .chip {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  border-color: #b91c1c;
  color: #ffffff;
  box-shadow:
    0 2px 6px rgba(185, 28, 28, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transform: translateY(-0.5px);
}
.chip-toggle input.toggle-input:checked ~ .chip .chip-icon,
.chip-toggle:has(input.toggle-input:checked) .chip .chip-icon {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}
.chip-toggle input.toggle-input:checked ~ .chip .chip-check,
.chip-toggle:has(input.toggle-input:checked) .chip .chip-check {
  background: #ffffff;
  color: #b91c1c;
}
.chip-toggle:hover .chip { border-color: #e8c7c7; }
.chip-toggle:active .chip { transform: scale(0.97); }

@media (max-width: 360px) {
  .settings-row.chip-group { gap: 6px; }
  .chip-toggle .chip { padding: 8px 11px 8px 9px; font-size: 13.5px; }
  .chip-icon { width: 20px; height: 20px; font-size: 11.5px; }
}

/* WORDS LIST */
.words-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.word-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.1s;
}
.word-card.expanded { border-color: var(--primary); }
.word-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}
.word-main { flex: 1; min-width: 0; }
.word-kanji-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.word-kanji {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}
.word-kana {
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 500;
}
.word-pos-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.word-pos {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-radius: 999px;
  font-weight: 600;
}
.word-pos.jlpt { background: #fef3c7; color: #b45309; }
.word-actions { display: flex; gap: 4px; flex-shrink: 0; }
.btn-play {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.1s;
}
.btn-play:active { background: #fecaca; }
.btn-detail {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: #fff1f2;
  color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.1s, transform 0.1s;
}
.btn-detail:active { background: #ffe4e6; transform: scale(0.95); }
.btn-expand {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s, background 0.1s;
}
.btn-expand:active { background: #e2e8f0; }
.word-card.expanded .btn-expand { transform: rotate(180deg); }

.word-meanings { list-style: none; padding: 0; margin: 0; }
.word-meaning {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.word-meaning:last-child { border-bottom: none; }
.meaning-num {
  display: inline-block;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  line-height: 22px;
  margin-right: 8px;
}
.meaning-text { font-size: 15px; color: var(--text); }

/* LOADING */
.loading {
  text-align: center;
  padding: 28px 16px;
  color: var(--text-muted);
  font-size: 14px;
}
.loading::before {
  content: '';
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* FLASHCARDS VIEW */
#view-flashcards {
  display: none;
  padding: 16px;
  padding-bottom: calc(20px + var(--safe-bot));
  flex-direction: column;
  min-height: calc(100vh - 56px - var(--safe-top));
}
#view-flashcards.active { display: flex; }

.flashcards-topbar {
  margin-bottom: 16px;
}
.fc-progress {
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.fc-progressbar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
#fc-progressbar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0%;
  transition: width 0.3s;
  border-radius: 999px;
}

.flashcard-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1000px;
  padding: 8px 0 20px;
  min-height: 380px;
}
.flashcard {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: 420px;
  max-height: 60vh;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4,0,0.2,1);
  cursor: pointer;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow-y: auto;
}
.flashcard-front {
  background: linear-gradient(160deg, #fff1f2 0%, #ffe4e6 60%, #fecdd3 100%);
  border: 1px solid rgba(185,28,28,0.2);
}
.flashcard-back {
  background: linear-gradient(160deg, #fef3c7 0%, #fde68a 60%, #fcd34d 100%);
  border: 1px solid rgba(245,158,11,0.2);
  transform: rotateY(180deg);
}
.fc-jlpt {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: 12px;
  padding: 3px 10px;
  background: rgba(99,102,241,0.15);
  color: var(--primary-dark);
  border-radius: 999px;
  font-weight: 700;
}
.fc-kanji {
  font-size: 56px;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.15;
  margin-bottom: 12px;
  word-break: break-all;
  padding: 0 10px;
}
.fc-kana {
  font-size: 20px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 18px;
}
.fc-play {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(99,102,241,0.4);
  transition: transform 0.1s;
}
.fc-play:active { transform: translateX(-50%) scale(0.92); }
.fc-pos {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.fc-pos .word-pos { font-size: 12px; padding: 4px 10px; }
.fc-meanings {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
}
.fc-meanings .word-meaning {
  padding: 10px 0;
  border-bottom: 1px dashed rgba(120, 53, 15, 0.2);
}
.fc-meanings .word-meaning:last-child { border-bottom: none; }
.fc-meanings .meaning-text { font-size: 16px; color: #78350f; }

.flashcards-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 8px;
}
.fc-ctrl {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s, background 0.1s;
}
.fc-ctrl:active { transform: scale(0.96); background: var(--surface-alt); }
.fc-ctrl.icon-only { flex: 0 0 auto; width: 52px; padding: 14px; }

/* ===== NEW WORD-LIST DETAILS LAYOUT ===== */

.word-meaning-preview {
  margin-top: 6px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  font-weight: 500;
}
.word-meaning-preview:empty { display: none; }
.wm-item { margin-right: 10px; display: inline-block; margin-bottom: 4px; }
.wm-num { color: var(--primary); font-weight: 700; margin-right: 2px; font-size: 13px; }

.word-details {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease, padding 0.2s ease, margin 0.2s ease;
}
.word-card.expanded .word-details {
  max-height: 2000px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}
.word-details-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.wd-section { display: flex; flex-direction: column; gap: 6px; }
.wd-section-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.wd-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.wd-list li {
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
}
.wd-muted { color: var(--text-light); font-size: 12px; }
.wd-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}
.wd-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.wd-section-actions { margin-top: 4px; }
.btn-detail-inline {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: linear-gradient(180deg, #ffffff 0%, #fff7f7 100%);
  color: var(--primary-dark);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1px;
  cursor: pointer;
  transition: all 0.16s ease;
  box-shadow: 0 1px 2px rgba(185, 28, 28, 0.03);
}
.btn-detail-inline svg:first-child {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  padding: 3px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
}
.btn-detail-inline span {
  flex: 1;
  text-align: left;
}
.btn-detail-inline .wda-chevron {
  flex-shrink: 0;
  color: var(--primary);
  opacity: 0.85;
  transition: transform 0.16s ease, opacity 0.16s ease;
}
.btn-detail-inline:hover {
  border-color: var(--primary);
  border-style: solid;
  background: linear-gradient(180deg, #fff 0%, #fff1f2 100%);
  box-shadow:
    0 2px 6px rgba(185, 28, 28, 0.08),
    0 0 0 3px rgba(185, 28, 28, 0.06);
  transform: translateY(-0.5px);
}
.btn-detail-inline:hover .wda-chevron {
  transform: translateX(2px);
  opacity: 1;
}
.btn-detail-inline:active {
  transform: scale(0.985);
  box-shadow: none;
}
.word-pos.usefulness {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}
.word-kanji-row.only-kana .word-kana {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
}
.word-kanji-row.no-script {
  display: none;
}

/* ===== FLASHCARD EXTRAS ===== */

.fc-extras {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.fc-extras:empty { display: none; }
.fc-extra-section { display: flex; flex-direction: column; gap: 6px; }
.fc-extra-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ===== WORD DETAIL PAGE ===== */

.word-back-link {
  margin-bottom: 12px;
}
.btn-text {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s;
}
.btn-text:hover { background: var(--primary-soft); }
.btn-text:active { background: #fecaca; }

#word-detail {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.25s ease;
}
.word-detail-hero {
  background: linear-gradient(160deg, #fff1f2 0%, #fee2e2 60%, #fecdd3 100%);
  border: 1px solid rgba(185,28,28,0.16);
  border-radius: var(--radius-xl);
  padding: 24px 20px 20px;
  box-shadow: var(--shadow-md);
  text-align: center;
  position: relative;
}
.wd-hero-play {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.wd-hero-play:active { transform: scale(0.94); }
.wd-hero-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}
.wd-hero-kanji {
  font-size: 56px;
  line-height: 1.1;
  font-weight: 800;
  color: var(--primary-dark);
  letter-spacing: 0.04em;
  margin: 6px 0 2px;
}
.wd-hero-kana {
  font-size: 22px;
  color: var(--text);
  margin-bottom: 6px;
  font-weight: 600;
}
.wd-hero-pos {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
}

.word-detail-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.wds-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.wds-title::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}
.wds-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wds-list > li {
  display: flex;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border-soft);
  line-height: 1.45;
}
.wds-list > li:last-child { border-bottom: none; padding-bottom: 0; }
.wds-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-weight: 800;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.wds-content { flex: 1; min-width: 0; }
.wds-meaning {
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
}
.wds-en {
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

.wds-grid {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  gap: 8px 14px;
  font-size: 14px;
}
.wds-grid .wds-k { color: var(--text-muted); font-weight: 700; }
.wds-grid .wds-v { color: var(--text); word-break: break-word; }

.wd-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.wd-chip-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  text-decoration: none;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  border: 1px solid #fecaca;
  transition: transform 0.1s, background 0.15s;
}
.wd-chip-link:hover { background: #fecaca; }
.wd-chip-link:active { transform: scale(0.97); }

@media (min-width: 640px) {
  .wd-hero-kanji { font-size: 72px; }
  .wd-hero-kana { font-size: 26px; }
  #view-word { max-width: 720px; margin: 0 auto; }
}

/* UTILS */
.hidden { display: none !important; }

/* SCROLLBAR (desktop) */
.search-results::-webkit-scrollbar,
.words-list::-webkit-scrollbar,
.flashcard-face::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-thumb,
.words-list::-webkit-scrollbar-thumb,
.flashcard-face::-webkit-scrollbar-thumb { background: var(--text-light); border-radius: 999px; }

/* TABLET+ */
@media (min-width: 640px) {
  .view { max-width: 720px; margin: 0 auto; }
  .stats-bar { grid-template-columns: repeat(3, 1fr); }
  .collections-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .fc-kanji { font-size: 64px; }
  .flashcard { height: 460px; }
}
@media (min-width: 900px) {
  .view { max-width: 900px; }
  .collections-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
  .words-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .word-card { padding: 16px; }
}
@media (min-width: 1200px) {
  .view { max-width: 1100px; }
  .collections-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

/* =========================================================
   EXAMPLES + TTS (aggiunte 2026)
   ========================================================= */

/* Pulsante TTS generico */
.btn-tts {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--primary-dark);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s;
  user-select: none;
  letter-spacing: 0.01em;
}
.btn-tts:hover { background: var(--primary-soft); border-color: #fecaca; }
.btn-tts:active { transform: scale(0.95); }
.btn-tts-sm { padding: 5px 9px; font-size: 11px; }
.btn-tts.is-speaking { background: var(--primary); color: #fff; border-color: var(--primary-dark); animation: tts-pulse 1.2s infinite; }
@keyframes tts-pulse {
  0% { box-shadow: 0 0 0 0 rgba(185,28,28,0.35); }
  70% { box-shadow: 0 0 0 8px rgba(185,28,28,0); }
  100% { box-shadow: 0 0 0 0 rgba(185,28,28,0); }
}

/* Word Card: frase esempio inclusa nel top */
.word-example-row {
  margin-top: 10px;
  padding: 10px 12px;
  background: linear-gradient(160deg, #fff7ed 0%, #ffedd5 100%);
  border: 1px solid #fed7aa;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.word-card.has-example .word-top { align-items: stretch; }
.word-example-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9a3412;
}
.word-example-label svg { color: #c2410c; }
.word-example-sentences {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.4;
}
.we-jp {
  font-size: 15px;
  font-weight: 700;
  color: #7c2d12;
  letter-spacing: 0.01em;
}
.we-kana {
  font-size: 12.5px;
  color: #a16207;
}
.we-it {
  font-size: 13.5px;
  color: #78350f;
  font-weight: 600;
}
.word-example-tts-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}

/* Retro flashcard: sezione esempio */
.fc-example {
  margin-top: 10px;
  padding: 10px 12px 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px dashed rgba(120, 53, 15, 0.3);
  border-radius: var(--radius-md);
  text-align: left;
  width: 100%;
}
.fc-example-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #92400e;
  margin-bottom: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.fc-example-title::before {
  content: '';
  width: 5px; height: 5px; border-radius: 50%;
  background: #b45309;
  display: inline-block;
}
.fc-ex-jp {
  font-size: 17px;
  font-weight: 700;
  color: #78350f;
  line-height: 1.35;
}
.fc-ex-kana {
  font-size: 13.5px;
  color: #92400e;
  margin-top: 2px;
}
.fc-ex-it {
  font-size: 14px;
  color: #78350f;
  font-weight: 600;
  margin-top: 5px;
  line-height: 1.35;
}
.fc-ex-tts-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* Dettaglio vocabolo - lista esempi migliorata */
.wd-examples-list {
  gap: 12px !important;
}
.wd-example-item {
  display: flex !important;
  flex-direction: column;
  gap: 6px !important;
  padding: 12px !important;
  background: linear-gradient(160deg, #fff7ed 0%, #ffedd5 100%);
  border: 1px solid #fed7aa;
  border-radius: var(--radius-md) !important;
  border-bottom: none !important;
  margin: 0 !important;
}
.wd-example-item:last-child { padding-bottom: 12px !important; }
.wd-example-sentences {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.45;
}
.wd-ex-jp {
  font-size: 18px;
  font-weight: 700;
  color: #7c2d12;
}
.wd-ex-kana {
  font-size: 13.5px;
  color: #a16207;
}
.wd-ex-it {
  margin-top: 4px;
  font-size: 14.5px;
  color: #78350f;
  font-weight: 600;
}
.wd-example-tts-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

/* Tablet e desktop: migliora compattezza */
@media (min-width: 640px) {
  .we-jp { font-size: 16px; }
  .fc-ex-jp { font-size: 18px; }
  .wd-ex-jp { font-size: 20px; }
}

/* Dispositivi molto piccoli */
@media (max-width: 360px) {
  .word-example-row { padding: 8px 10px; }
  .we-jp { font-size: 14px; }
  .we-kana { font-size: 12px; }
  .we-it { font-size: 12.5px; }
  .btn-tts-sm { padding: 4px 8px; font-size: 10.5px; }
}

/* SITE FOOTER */
#site-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 14px 16px calc(18px + var(--safe-bot));
  font-size: 12px;
  color: var(--text-light);
  border-top: 1px solid var(--border-soft);
  background: transparent;
  letter-spacing: 0.15px;
  line-height: 1.55;
}
#site-footer .sep { opacity: 0.35; margin: 0 6px; }
#site-footer a {
  color: var(--primary);
  opacity: 0.85;
  text-decoration: none;
  border-bottom: 1px dashed transparent;
  transition: opacity 0.15s, border-color 0.15s;
}
#site-footer a:hover, #site-footer a:active { opacity: 1; border-bottom-color: var(--primary); }
#site-footer .sf-row { margin: 3px 0; }
#site-footer .sf-links { margin-top: 6px; }
#site-footer .sf-link-btn {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--primary);
  opacity: 0.8;
  font-size: 11.5px;
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  font-family: inherit;
}
#site-footer .sf-link-btn:hover, #site-footer .sf-link-btn:active { opacity: 1; border-bottom-color: var(--primary); }

/* ============ MODALE LEGALE & COOKIE BANNER ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 41, 0.58);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: modFadeIn 0.25s ease-out;
}
@keyframes modFadeIn { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 24px; }
}
.modal-panel {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 22px 20px calc(24px + var(--safe-bot));
  position: relative;
  box-shadow: 0 -10px 40px rgba(185, 28, 28, 0.12), 0 4px 12px rgba(0,0,0,0.08);
  border-top: 2px solid var(--primary);
  animation: modSlideUp 0.3s cubic-bezier(0.22,1,0.36,1);
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 640px) {
  .modal-panel { border-radius: 18px; border: 1px solid var(--border-soft); border-top: 2px solid var(--primary); }
}
@keyframes modSlideUp { from { transform: translateY(40px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 34px; height: 34px;
  border: 1px solid var(--border-soft);
  background: var(--bg);
  color: var(--text-light);
  border-radius: 10px;
  display: inline-flex;
  align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover, .modal-close:active { background: var(--primary-soft); color: var(--primary); }
.modal-title {
  font-size: 17px;
  margin: 0 28px 16px 0;
  color: var(--primary);
  letter-spacing: 0.2px;
  font-weight: 700;
}
.modal-section { margin: 14px 0 18px; padding: 12px 14px; background: var(--surface); border-radius: 12px; border: 1px solid var(--border-soft); }
.modal-section h3 { margin: 0 0 8px; font-size: 14.5px; color: var(--ink); font-weight: 700; }
.modal-section p { margin: 6px 0; font-size: 13px; line-height: 1.6; color: var(--ink); }
.modal-section a { color: var(--primary); border-bottom: 1px dashed rgba(185,28,28,0.35); text-decoration: none; }
.modal-section a:hover, .modal-section a:active { border-bottom-style: solid; }
.legal-list { margin: 8px 0 4px 18px; padding: 0; }
.legal-list li { font-size: 13px; line-height: 1.6; color: var(--ink); margin: 4px 0; }
.modal-contact { background: var(--primary-soft); border-color: transparent; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(185, 28, 28, 0.25);
  transition: transform 0.1s, box-shadow 0.15s;
  font-family: inherit;
}
.btn-primary:active { transform: translateY(1px); box-shadow: 0 2px 6px rgba(185, 28, 28, 0.2); }

/* Cookie banner basso */
.cookie-banner {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 999;
  padding: 10px 12px calc(12px + var(--safe-bot));
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,247,237,0.97) 40%, var(--surface) 100%);
  backdrop-filter: saturate(1.2);
  animation: cbSlideUp 0.35s cubic-bezier(0.22,1,0.36,1);
}
@keyframes cbSlideUp { from { transform: translateY(110%); } to { transform: translateY(0); } }
.cookie-banner-inner {
  max-width: 760px; margin: 0 auto;
  background: #ffffff;
  color: #1f2937;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 10px 12px 10px 14px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.14), 0 0 0 1px rgba(185,28,28,0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@media (min-width: 520px) {
  .cookie-banner-inner { flex-direction: row; align-items: center; gap: 16px; }
}
.cb-text {
  font-size: 12.5px;
  line-height: 1.45;
  color: #1f2937;
  flex: 1;
}
.cb-text strong { color: var(--primary); font-weight: 700; }
.cb-actions { display: flex; gap: 8px; flex-shrink: 0; justify-content: flex-end; }
.cb-btn {
  border: 0;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}
.cb-btn:active { transform: translateY(1px); }
.cb-btn-legal {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border-soft);
}
.cb-btn-legal:hover { background: var(--primary-soft); }
.cb-btn-accept {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 3px 10px rgba(185,28,28,0.25);
}
.cb-btn-accept:hover { background: #a01818; }

/* Audio sentence button loading state */
.btn-audio-sentence.is-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.75 !important;
}
.btn-audio-sentence.is-loading::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: audioSpin 0.7s linear infinite;
}
.btn-audio-sentence.is-loading .btn-tts, .btn-audio-sentence.is-loading {
  background-color: var(--primary-soft) !important;
}
@keyframes audioSpin { to { transform: rotate(360deg); } }
