/* ===================================================================
   Readable v3 Welcome Flow & Library — shared stylesheet
   =================================================================== */

:root {
  --brand-indigo: #6e68ca;
  --title-indigo: #3d31be;
  --brand-sky: #b8ddff;
  --brand-lavender: #e3c7ff;
  --bg-soft: #faf8ff;
  --bg-tint: #f0ecff;
  --bg-page: #f4f1fb;
  --border-soft: #e0dcf5;
  --border-mid: #c8c2f0;
  --text-body: #2c2a4a;
  --text-muted: #5f5e7a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-page);
  color: var(--text-body);
  min-height: 100vh;
  padding: 28px 16px 48px;
  line-height: 1.5;
}

/* ============================== TOOLBAR ICONS ============================== */
/* For use inline within text — e.g. "click <i class="tb"><svg>...</svg></i>Play" */
.tb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5em;
  height: 1.5em;
  vertical-align: -0.35em;
  margin: 0 2px 0 1px;
  padding: 1px;
  background: #ffffff;
  border: 1px solid var(--border-mid);
  border-radius: 4px;
  color: var(--title-indigo);
}
.tb svg {
  width: 1.05em;
  height: 1.05em;
  stroke: currentColor;
  fill: none;
}
/* Icon "chip" style — pill with name next to icon */
.tbchip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 4px;
  background: var(--bg-tint);
  border: 1px solid var(--border-mid);
  border-radius: 5px;
  font-size: 0.95em;
  color: var(--title-indigo);
  font-weight: 500;
  white-space: nowrap;
}
.tbchip svg {
  width: 1em;
  height: 1em;
  stroke: currentColor;
  fill: none;
}

/* Keychip — keyboard key reference */
.keychip {
  display: inline-block;
  padding: 1px 7px;
  border: 1.5px solid var(--border-mid);
  background: #ffffff;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.85em;
  color: var(--title-indigo);
  margin: 0 1px;
  font-weight: 500;
  vertical-align: 0.05em;
}

/* ============================== PAGE HEADER ============================== */
.page-header {
  max-width: 680px;
  margin: 0 auto 22px;
  text-align: center;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 500;
  color: var(--title-indigo);
  margin: 0 0 4px;
}
.page-header p {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
}

/* ============================== WINDOW (DIALOG) ============================== */
.window {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 12px;
  border: 0.5px solid #cdc7e8;
  box-shadow: 0 4px 20px rgba(61, 49, 190, 0.08);
  overflow: hidden;
}
.window.window-wide { max-width: 840px; }

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  background: var(--title-indigo);
  color: #ffffff;
  font-size: 14px;
}
.titlebar-name { display: flex; align-items: center; gap: 9px; }
.logo {
  width: 20px; height: 20px;
  border-radius: 5px;
  background: #ffffff;
  color: var(--title-indigo);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500;
}
.titlebar-controls { display: flex; gap: 6px; }
.titlebar-btn {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
}

/* ============================== PROGRESS DOTS ============================== */
.progress {
  display: flex; gap: 6px;
  justify-content: center;
  align-items: center;
  padding: 16px 0 6px;
}
.progress-meta {
  font-size: 12px;
  color: var(--brand-indigo);
  margin-left: 10px;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--brand-lavender);
  transition: all 0.25s;
}
.dot.active {
  background: var(--brand-indigo);
  width: 24px;
  border-radius: 4px;
}
.dot.completed { background: var(--brand-indigo); }

/* ============================== CARD CONTENT ============================== */
.card { padding: 14px 28px 20px; min-height: 360px; }
.card h3 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 500;
  color: var(--title-indigo);
}
.card .sub {
  margin: 0 0 16px;
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.5;
}
.card .lede {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-body);
  margin: 0 0 14px;
}
.card .lede strong { color: var(--title-indigo); }

.card-key-list {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}
.card-key-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-soft);
  border-radius: 7px;
  margin-bottom: 7px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-body);
}
.card-key-list .num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand-indigo);
  color: #ffffff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 500;
}
.card-key-list .bullet {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand-indigo);
  margin-top: 7px;
}

.card-illustration {
  height: 140px;
  margin: 0 0 14px;
  background: var(--bg-soft);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ============================== ROUTING CARD OPTIONS ============================== */
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 16px;
  padding: 13px 16px;
  background: #ffffff;
  border: 2px solid var(--border-soft);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.option:hover { background: var(--bg-soft); border-color: var(--border-mid); }
.option.selected { background: var(--bg-tint); border-color: var(--brand-indigo); }
.option:focus-visible { outline: 3px solid var(--brand-indigo); outline-offset: 2px; }
.option-icon {
  flex-shrink: 0; width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
.option.selected .option-icon { transform: scale(1.05); }
.option-icon svg { width: 36px; height: 36px; }
.option-icon.visual { background: linear-gradient(135deg, #fff4d6 0%, #ffe5b8 100%); }
.option-icon.listen { background: linear-gradient(135deg, #d8e9ff 0%, #b8ddff 100%); }
.option-icon.audio { background: linear-gradient(135deg, #c8e9dd 0%, #a8e5d3 100%); }
.option-icon.writehelp { background: linear-gradient(135deg, #ffe1d8 0%, #ff9c8a 100%); }
.option-icon.meanings { background: linear-gradient(135deg, #ffeacc 0%, #ffd86b 100%); }
.option-icon.focus { background: linear-gradient(135deg, #e3c7ff 0%, #c4a5ff 100%); }
.option-text { flex: 1; min-width: 0; }
.option-title {
  font-size: 17px; font-weight: 500;
  color: var(--text-body);
  margin: 0; line-height: 1.35;
}
.option.selected .option-title { color: var(--title-indigo); }
.option-check {
  flex-shrink: 0; width: 24px; height: 24px;
  border: 2px solid var(--border-mid);
  border-radius: 5px;
  background: #ffffff;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.option.selected .option-check {
  background: var(--brand-indigo);
  border-color: var(--brand-indigo);
}
.option.selected .option-check::after {
  content: '';
  width: 6px; height: 11px;
  border: solid #ffffff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
  margin-top: -3px;
}

/* ============================== FAMILY CHIP ============================== */
.family-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 6px;
  background: var(--bg-tint);
  border-radius: 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--title-indigo);
  margin-bottom: 6px;
}
.family-chip-icon {
  width: 22px; height: 22px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
}
.family-chip-icon svg { width: 14px; height: 14px; }
.family-chip-icon.visual { background: linear-gradient(135deg, #fff4d6, #ffe5b8); }
.family-chip-icon.listen { background: linear-gradient(135deg, #d8e9ff, #b8ddff); }
.family-chip-icon.audio { background: linear-gradient(135deg, #c8e9dd, #a8e5d3); }
.family-chip-icon.writehelp { background: linear-gradient(135deg, #ffe1d8, #ff9c8a); }
.family-chip-icon.meanings { background: linear-gradient(135deg, #ffeacc, #ffd86b); }
.family-chip-icon.focus { background: linear-gradient(135deg, #e3c7ff, #c4a5ff); }

/* ============================== TOAST ============================== */
.toast {
  background: var(--bg-tint);
  border-left: 4px solid var(--brand-indigo);
  padding: 12px 16px;
  margin: 0 28px 14px;
  border-radius: 0 8px 8px 0;
  font-size: 14px;
  color: #3a3858;
  line-height: 1.5;
  display: none;
}
.toast.show { display: block; }
.toast strong { color: var(--title-indigo); font-weight: 500; }

/* ============================== TELL-ME-MORE ============================== */
.more-toggle {
  background: none;
  border: none;
  color: var(--brand-indigo);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  padding: 4px 0;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.more-toggle:hover { color: var(--title-indigo); }
.more-toggle .arrow { transition: transform 0.2s; display: inline-block; }
.more-toggle.open .arrow { transform: rotate(180deg); }
.more-content {
  display: none;
  padding: 12px 16px;
  background: var(--bg-soft);
  border-left: 3px solid var(--brand-indigo);
  border-radius: 0 7px 7px 0;
  font-size: 14px;
  color: #3a3858;
  line-height: 1.6;
  margin-top: 8px;
}
.more-content.open { display: block; }
.more-content p { margin: 0 0 8px; }
.more-content p:last-child { margin-bottom: 0; }
.more-content a {
  color: var(--brand-indigo);
  font-size: 13px;
  text-decoration: none;
}
.more-content a:hover { text-decoration: underline; }

/* ============================== CONTROLS ============================== */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 26px;
  border-top: 0.5px solid #ece8f5;
  gap: 12px;
}
.listen {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  background: var(--bg-tint);
  border: 1.5px solid var(--border-mid);
  border-radius: 7px;
  color: var(--title-indigo);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
}
.listen:hover { background: #e3dcff; }
.listen.playing { background: var(--brand-indigo); color: #ffffff; border-color: var(--brand-indigo); }
.nav { display: flex; gap: 10px; align-items: center; }
.skip-link {
  color: var(--brand-indigo);
  cursor: pointer;
  text-decoration: underline;
  font-size: 14px;
  background: none;
  border: none;
  font-family: inherit;
  padding: 0 6px;
}
.btn {
  padding: 9px 18px;
  border-radius: 7px;
  border: 1.5px solid var(--border-mid);
  background: #ffffff;
  color: var(--title-indigo);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
}
.btn:hover { background: var(--bg-soft); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: var(--brand-indigo);
  color: #ffffff;
  border-color: var(--brand-indigo);
}
.btn-primary:hover { background: #5a55b5; }

/* ============================== FOOTER ============================== */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 26px 13px;
  background: var(--bg-soft);
  font-size: 13px;
  color: var(--text-muted);
}
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.pane { display: none; }
.pane.active { display: block; }

/* ============================== ANIMATIONS ============================== */
.tw-cursor { animation: tw-cursor-move 4s ease-in-out infinite; }
@keyframes tw-cursor-move {
  0%   { transform: translateX(0); }
  25%  { transform: translateX(50px); }
  50%  { transform: translateX(100px); }
  75%  { transform: translateX(150px); }
  100% { transform: translateX(0); }
}
.tw-uw {
  stroke: var(--brand-indigo);
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0;
}
.tw-uw.w1 { animation: tw-flash 4s ease-in-out infinite; animation-delay: 0.4s; }
.tw-uw.w2 { animation: tw-flash 4s ease-in-out infinite; animation-delay: 1.4s; }
.tw-uw.w3 { animation: tw-flash 4s ease-in-out infinite; animation-delay: 2.4s; }
.tw-uw.w4 { animation: tw-flash 4s ease-in-out infinite; animation-delay: 3.4s; }
@keyframes tw-flash { 0%, 100% { opacity: 0; } 10%, 30% { opacity: 1; } }

.welcome-illustration { text-align: center; }

/* ============================== LIBRARY-SPECIFIC ============================== */
.library-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.library-tile {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px;
  background: var(--bg-soft);
  border: 1.5px solid var(--border-soft);
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s;
}
.library-tile:hover { border-color: var(--brand-indigo); background: var(--bg-tint); }
.library-tile-icon {
  flex-shrink: 0; width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.library-tile-icon svg { width: 22px; height: 22px; }
.library-tile-icon.visual { background: linear-gradient(135deg, #fff4d6, #ffe5b8); }
.library-tile-icon.listen { background: linear-gradient(135deg, #d8e9ff, #b8ddff); }
.library-tile-icon.audio { background: linear-gradient(135deg, #c8e9dd, #a8e5d3); }
.library-tile-icon.writehelp { background: linear-gradient(135deg, #ffe1d8, #ff9c8a); }
.library-tile-icon.meanings { background: linear-gradient(135deg, #ffeacc, #ffd86b); }
.library-tile-icon.focus { background: linear-gradient(135deg, #e3c7ff, #c4a5ff); }
.library-tile-text { flex: 1; }
.library-tile-title { font-size: 14px; font-weight: 500; color: var(--text-body); margin: 0; }
.library-tile-count { font-size: 11px; color: var(--text-muted); margin: 0; }

/* ============================== LIBRARY PAGE ============================== */
.lib-header {
  padding: 18px 28px 12px;
}
.lib-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 500;
  color: var(--title-indigo);
}
.lib-header p {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.lib-tour-banner {
  margin: 0 28px 18px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--bg-tint), #e3dcff);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.lib-tour-banner svg.lib-tour-icon { flex-shrink: 0; width: 44px; height: 44px; color: var(--title-indigo); }
.lib-tour-banner .lib-tour-text { flex: 1; }
.lib-tour-banner h4 { margin: 0 0 2px; font-size: 15px; font-weight: 500; color: var(--title-indigo); }
.lib-tour-banner p { margin: 0; font-size: 13px; color: var(--text-muted); }
.lib-tour-banner button {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--brand-indigo);
  color: #ffffff;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.lib-tour-banner button:hover { background: #5a55b5; }

.lib-nav {
  display: flex;
  gap: 6px;
  padding: 0 28px 14px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 14px;
  overflow-x: auto;
}
.lib-nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.15s;
}
.lib-nav-tab:hover { color: var(--title-indigo); background: var(--bg-soft); }
.lib-nav-tab.active {
  color: var(--title-indigo);
  border-bottom-color: var(--brand-indigo);
  background: var(--bg-soft);
}
.lib-nav-tab .lib-nav-tab-icon { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; border-radius: 5px; }
.lib-nav-tab .lib-nav-tab-icon svg { width: 12px; height: 12px; }
.lib-nav-tab-count {
  display: inline-block;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--bg-tint);
  font-size: 11px;
  color: var(--title-indigo);
  margin-left: 2px;
}

.lib-body { padding: 0 28px 24px; }
.lib-tier-section { margin-bottom: 20px; }
.lib-tier-header {
  display: inline-block;
  margin: 0 0 8px;
  padding: 3px 10px;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.lib-tier-header.essential { background: var(--brand-lavender); color: var(--title-indigo); }
.lib-tier-header.recommended { background: var(--brand-sky); color: #185fa5; }
.lib-tier-header.explore { background: #ece8f5; color: var(--text-muted); }

.lib-hint-list { display: flex; flex-direction: column; gap: 8px; }
.lib-hint {
  background: #ffffff;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.lib-hint:hover { border-color: var(--border-mid); }
.lib-hint-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}
.lib-hint-body {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-body);
  flex: 1;
}
.lib-hint-actions { display: flex; gap: 6px; flex-shrink: 0; }
.lib-hint-action {
  width: 30px; height: 30px;
  border-radius: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--brand-indigo);
}
.lib-hint-action:hover { background: var(--bg-tint); border-color: var(--brand-indigo); }
.lib-hint-action.playing { background: var(--brand-indigo); color: #ffffff; }
.lib-hint-action svg { width: 14px; height: 14px; }

/* ============================== NOTES BLOCK ============================== */
.notes {
  max-width: 620px;
  margin: 24px auto 0;
  padding: 18px 24px;
  background: #ffffff;
  border-radius: 10px;
  border: 0.5px solid #ddd6f0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-body);
}
.notes.notes-wide { max-width: 840px; }
.notes h4 { margin: 0 0 8px; font-size: 15px; font-weight: 500; color: var(--title-indigo); }
.notes ul { margin: 0 0 14px; padding-left: 20px; }
.notes li { margin-bottom: 5px; }
.notes code { background: var(--bg-tint); padding: 1px 6px; border-radius: 3px; font-size: 12.5px; color: var(--title-indigo); }

/* ============================== RESPONSIVE ============================== */
@media (max-width: 560px) {
  .card { padding: 12px 18px 18px; }
  .option { padding: 11px 12px; gap: 12px; }
  .option-icon { width: 46px; height: 46px; }
  .option-icon svg { width: 32px; height: 32px; }
  .option-title { font-size: 16px; }
  .library-grid { grid-template-columns: 1fr; }
  .controls { flex-direction: column; align-items: stretch; gap: 10px; }
  .toast { margin-left: 18px; margin-right: 18px; }
  .lib-tour-banner { flex-direction: column; align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  *, .tw-cursor, .tw-uw {
    animation: none !important;
    transition: none !important;
    opacity: 1 !important;
  }
}
