/* Explore: the free story library.
   Tokens (--surface, --accent, ...) come from the app shell. Class prefix: xp-. */

.xp {
  /* The accent as text. --accent itself is 4:1 on the dark canvas, short of AA
     for small type, so text and selected states use a lighter violet there. */
  --xp-ink: #b8abf3;
  color: var(--text);
}
html[data-theme="light"] .xp { --xp-ink: var(--accent-hover); }

.xp-flag { display: inline-flex; align-items: center; font-size: 1.1em; line-height: 1; }

/* ── index: header and controls ─────────────────────────────────────────── */
.xp-head { margin-bottom: 20px; }

.xp-controls {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px 20px; margin-bottom: 14px;
}
.xp-readin { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.xp-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-mute);
}

/* language picker: a disclosure menu */
.xp-pick { position: relative; }
.xp-pick > summary { list-style: none; }
.xp-pick > summary::-webkit-details-marker { display: none; }
.xp-pick__btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 11px 0 12px;
  border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; user-select: none;
  transition: border-color 0.15s, background 0.15s;
}
.xp-pick__btn:hover, .xp-pick[open] > .xp-pick__btn { border-color: var(--accent); }
.xp-pick__btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.xp-pick__chev { width: 13px; height: 13px; color: var(--text-mute); transition: transform 0.15s; }
.xp-pick[open] .xp-pick__chev { transform: rotate(180deg); }
.xp-pick__menu {
  position: absolute; z-index: 40; top: calc(100% + 6px); left: 0;
  width: min(400px, calc(100vw - 28px)); max-height: min(60vh, 420px); overflow-y: auto;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; padding: 6px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}
html[data-theme="light"] .xp-pick__menu { box-shadow: 0 14px 36px rgba(20, 20, 27, 0.14); }
.xp-pick__item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  font-size: 13.5px; color: var(--text-mute); transition: background 0.12s, color 0.12s;
}
.xp-pick__item:hover { background: var(--surface-2); color: var(--text); }
.xp-pick__item:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.xp-pick__item.is-active { background: var(--accent-soft); color: var(--xp-ink); font-weight: 600; }

/* level picker: segmented control */
.xp-levels {
  display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.xp-level {
  min-width: 38px; height: 28px; padding: 0 8px; display: grid; place-items: center;
  border-radius: 7px; font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--text-mute); transition: background 0.15s, color 0.15s;
}
.xp-level:hover { color: var(--text); }
.xp-level:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.xp-level.is-active { background: var(--accent); color: #fff; }

/* search */
.xp-search { position: relative; display: block; width: min(250px, 100%); }
.xp-search svg {
  position: absolute; left: 11px; top: 50%; width: 15px; height: 15px;
  transform: translateY(-50%); color: var(--text-mute); pointer-events: none;
}
.xp-search input {
  width: 100%; height: 36px; padding: 0 12px 0 34px; border-radius: 9px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 13.5px; transition: border-color 0.15s;
}
.xp-search input::placeholder { color: var(--text-mute); opacity: 0.85; }
.xp-search input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }

/* topic chips */
.xp-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.xp-chip {
  height: 30px; padding: 0 10px; border-radius: 99px; border: 1px solid var(--border-strong);
  background: transparent; color: var(--text-mute); font-size: 12.5px; font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.xp-chip:hover { color: var(--text); border-color: var(--text-dim); }
.xp-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.xp-chip[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent-line); color: var(--xp-ink); font-weight: 600;
}
.xp-count { margin: 0 0 12px; font-size: 12.5px; color: var(--text-mute); font-variant-numeric: tabular-nums; }

/* ── story grid and cards ───────────────────────────────────────────────── */
.xp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }

.xp-card {
  display: flex; flex-direction: column; overflow: hidden; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  transition: border-color 0.15s, transform 0.15s;
}
.xp-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.xp-card:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.xp-card[hidden] { display: none; }
.xp-card__body { display: flex; flex-direction: column; gap: 3px; padding: 14px 16px 16px; }
.xp-card__flag { font-size: 11px; font-weight: 600; color: var(--xp-ink); }
.xp-card__topic {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-mute);
}
.xp-card__title { margin: 0; font-size: 16px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.xp-card__en { margin: 0; font-size: 12.5px; color: var(--text-mute); }
.xp-card__teaser {
  margin: 6px 0 0; font-size: 13px; line-height: 1.5; color: var(--text-mute);
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
/* the story of the day takes two columns, cover beside text */
.xp-card--featured { grid-column: span 2; flex-direction: row; }
.xp-card--featured .xp-cover { flex: 0 0 46%; aspect-ratio: auto; min-height: 100%; }
.xp-card--featured .xp-card__body { justify-content: center; padding: 20px 22px; gap: 5px; }
.xp-card--featured .xp-card__title { font-size: 21px; line-height: 1.2; }
.xp-card--featured .xp-card__teaser { font-size: 14px; -webkit-line-clamp: 3; line-clamp: 3; }

/* covers: topic colour + topic icon + rings placed by the story's own seed */
.xp-cover {
  --xp-h: 285; --xp-c: 0.085; --xp-hue: calc(var(--xp-h) + var(--xp-s, 0));
  position: relative; isolation: isolate; overflow: hidden; aspect-ratio: 16 / 9;
  background: #26233b; background: oklch(28% calc(var(--xp-c) * 0.78) var(--xp-hue));
  color: #b3a8ee; color: oklch(78% calc(var(--xp-c) * 1.5) var(--xp-hue));
}
html[data-theme="light"] .xp-cover {
  background: #ece8fb; background: oklch(93.5% calc(var(--xp-c) * 0.5) var(--xp-hue));
  color: #4b3fa6; color: oklch(42% calc(var(--xp-c) * 1.9) var(--xp-hue));
}
.xp-cover::before {
  content: ""; position: absolute; inset: 0; z-index: -1; opacity: 0.15;
  background: repeating-radial-gradient(circle at var(--xp-x, 70%) var(--xp-y, 30%), transparent 0 13px, currentColor 13px 14px);
}
.xp-cover__icon { position: absolute; left: 18px; bottom: 16px; width: 44px; height: 44px; }
.xp-card--featured .xp-cover__icon { left: 24px; bottom: 22px; width: 56px; height: 56px; }
.xp-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }

.xp-topic--mystery { --xp-h: 285; }
.xp-topic--travel  { --xp-h: 232; }
.xp-topic--food    { --xp-h: 52; }
.xp-topic--nature  { --xp-h: 145; }
.xp-topic--science { --xp-h: 195; }
.xp-topic--legend  { --xp-h: 318; }
.xp-topic--humor   { --xp-h: 88; }
.xp-topic--life    { --xp-h: 18; }
.xp-topic--work    { --xp-h: 255; --xp-c: 0.03; }
.xp-topic--culture { --xp-h: 350; }

.xp-empty {
  padding: 44px 20px; text-align: center; border: 1px dashed var(--border-strong);
  border-radius: 14px; color: var(--text-mute); font-size: 14px;
}
.xp-empty[hidden] { display: none; }
.xp-empty p { margin: 0 0 14px; }

/* buttons */
.xp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px;
  padding: 0 14px; border-radius: 9px; border: 1px solid transparent; cursor: pointer;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.xp-btn svg { width: 15px; height: 15px; }
.xp-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.xp-btn--primary { background: var(--accent); color: #fff; }
.xp-btn--primary:hover { background: var(--accent-hover); }
.xp-btn--ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.xp-btn--ghost:hover { border-color: var(--accent); color: var(--xp-ink); }
.xp-btn.is-speaking { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── story page ─────────────────────────────────────────────────────────── */
.xp-col { max-width: 680px; }
.xp-back {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 18px;
  font-size: 13px; color: var(--text-mute); transition: color 0.15s;
}
.xp-back svg { width: 14px; height: 14px; transform: scaleX(-1); }
.xp-back:hover { color: var(--text); }
.xp-back:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 4px; }

.xp-story-head { margin-bottom: 18px; }
.xp-story-title { margin: 6px 0 0; font-size: 28px; line-height: 1.15; font-weight: 600; letter-spacing: -0.025em; }
.xp-story-en { margin: 7px 0 0; font-size: 13.5px; color: var(--text-mute); }

.xp-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px;
  padding: 12px 0; margin-bottom: 14px; border-block: 1px solid var(--border);
}
.xp-speak { margin-left: auto; }
.xp-meta { margin: 0 0 20px; font-size: 12.5px; color: var(--text-mute); font-variant-numeric: tabular-nums; }

.xp-reader { max-width: 66ch; font-size: 1.1875rem; line-height: 1.85; color: var(--text); }
.xp-reader p { margin: 0 0 1.1em; }
.xp-reader[lang="ar"], .xp-reader[lang="fa"] {
  font-size: 1.32rem; line-height: 2.2;
  font-family: 'DM Sans', 'Segoe UI', Tahoma, 'Geeza Pro', 'Noto Naskh Arabic', system-ui, sans-serif;
}
.xp-reader[lang="ja"] {
  line-height: 2.05; font-family: 'DM Sans', 'Hiragino Sans', 'Yu Gothic', Meiryo, 'Noto Sans JP', system-ui, sans-serif;
}
.xp-reader[lang="zh-CN"] {
  line-height: 2.05; font-family: 'DM Sans', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif;
}
.xp-reader[lang="ko"] {
  line-height: 2; word-break: keep-all;
  font-family: 'DM Sans', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
}

/* words the learner has already saved */
.fc-hit {
  background-color: rgba(116, 94, 222, 0.22); color: var(--text);
  box-shadow: inset 0 -1.5px 0 rgba(116, 94, 222, 0.6);
  padding: 1px 3px; border-radius: 3px; font-weight: 600;
}
html[data-theme="light"] .fc-hit { background-color: rgba(116, 94, 222, 0.16); }

.xp-hint {
  display: flex; align-items: center; gap: 8px; margin: 6px 0 0; font-size: 12.5px; color: var(--text-mute);
}
.xp-hint svg { width: 15px; height: 15px; flex: none; }
.xp-next {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 28px;
  font-size: 13px; color: var(--text-mute);
}

/* first visit: pick a language, then a level */
.xp-choose { padding-top: 6px; }
.xp-choose h2 { margin: 0 0 14px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.xp-lang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.xp-lang-tile {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); font-size: 14px; font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}
.xp-lang-tile:hover { border-color: var(--accent); background: var(--accent-soft); }
.xp-lang-tile:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.xp-level-list { display: grid; gap: 8px; }
.xp-level-row {
  display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 14px;
  padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  font-size: 13px; line-height: 1.45; color: var(--text-mute); transition: border-color 0.15s, background 0.15s;
}
.xp-level-row strong { color: var(--text); font-weight: 600; font-size: 14px; }
.xp-level-row:hover { border-color: var(--accent); background: var(--accent-soft); }
.xp-level-row:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.xp-level-row__code {
  display: grid; place-items: center; height: 36px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  font-size: 13px; font-weight: 700; letter-spacing: 0.02em;
}

.xp-more { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border); }
.xp-more__title { margin: 0 0 14px; font-size: 15px; font-weight: 600; }

/* ── small screens ──────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .xp-card--featured { grid-column: auto; flex-direction: column; }
  .xp-card--featured .xp-cover { flex: none; aspect-ratio: 16 / 9; min-height: 0; }
  .xp-card--featured .xp-card__body { padding: 14px 16px 16px; }
  .xp-card--featured .xp-card__title { font-size: 18px; }
  .xp-card--featured .xp-cover__icon { left: 18px; bottom: 16px; width: 44px; height: 44px; }
  .xp-search { width: 100%; }
  .xp-chips { flex-wrap: nowrap; overflow-x: auto; margin-inline: -14px; padding-inline: 14px; scrollbar-width: none; }
  .xp-chips::-webkit-scrollbar { display: none; }
  .xp-chip { flex: none; }
  .xp-story-title { font-size: 24px; }
  .xp-reader { font-size: 1.125rem; }
  .xp-speak { margin-left: 0; }
  .xp-pick__menu { width: min(400px, calc(100vw - 28px)); }
}
@media (max-width: 420px) {
  .xp-level { min-width: 34px; padding: 0 6px; }
}
