/* ============================================================
   narrative.css  -  M7 Narrative Hub styles
   Stable identity, rivalry card, tribe heritage, chronicle archive,
   standings lens toggle, and chronicle card.

   All properties use logical CSS (inline-start/inline-end, block-start/block-end)
   except the pulse-duel time axis which stays physical for RTL race direction.
   Colors come only from tokens.css variables. No raw hex literals.
   ============================================================ */

/* ----- Stable page ------------------------------------------ */

.stable-page {
  padding-block: 48px 64px;
}

.stable-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-block-end: 32px;
  padding-block-end: 24px;
  border-block-end: 1px solid var(--line);
}

.stable-header__crest {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.stable-crest {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-block-end: 16px;
}

.stable-crest__emblem {
  flex-shrink: 0;
  border-radius: 50%;
}

.stable-crest__label {
  font-size: .78rem;
  opacity: .6;
  font-family: var(--f-body, inherit);
}

.stable-name {
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  font-weight: 700;
  line-height: 1.1;
  margin: 0;
}

.stable-name-alt {
  font-size: .9rem;
  opacity: .55;
  letter-spacing: .04em;
}

.stable-meta {
  font-size: .85rem;
  opacity: .75;
}

/* ----- Tab list -------------------------------------------- */

.tab-list {
  display: flex;
  flex-direction: row;
  gap: 4px;
  border-block-end: 2px solid var(--line);
  margin-block-end: 24px;
  padding-block-end: 0;
  overflow-x: auto;
}

.tab-btn {
  background: none;
  border: none;
  border-block-end: 3px solid transparent;
  padding: 10px 16px;
  font: inherit;
  font-size: .92rem;
  font-weight: 500;
  color: inherit;
  opacity: .65;
  cursor: pointer;
  transition: opacity .18s, border-color .18s;
  white-space: nowrap;
}

.tab-btn:hover,
.tab-btn:focus-visible {
  opacity: 1;
  outline: none;
}

.tab-btn--active,
.tab-btn[aria-selected="true"] {
  opacity: 1;
  border-block-end-color: var(--green);
  color: var(--text-strong);
}

/* ----- Tab panels ------------------------------------------ */

.tab-panel {
  padding-block: 16px;
}

.tab-panel[hidden] {
  display: none;
}

.tab-panel--active {
  display: block;
}

/* ----- Stable info table ------------------------------------ */

.stable-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-block-end: 16px;
}

.stable-info__row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 12px;
  padding-block: 6px;
  border-block-end: 1px solid var(--line);
  font-size: .88rem;
}

.stable-info__row span:first-child {
  opacity: .6;
  flex-shrink: 0;
}

/* ----- Owners row ------------------------------------------ */

.stable-owners {
  font-weight: 500;
}

/* ----- Stable roster --------------------------------------- */

.stable-roster {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stable-roster__item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--surface-2);
  border-radius: 8px;
}

/* thumbnail: real <img> */
.stable-roster__thumb {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* avatar placeholder: token-colored circle */
.stable-roster__thumb--avatar {
  display: inline-block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  opacity: .5;
  flex-shrink: 0;
}

.stable-roster__name {
  flex: 1;
  font-weight: 600;
  text-decoration: none;
  color: inherit;
}

.stable-roster__name:hover,
.stable-roster__name:focus-visible {
  text-decoration: underline;
  color: var(--green);
}

.stable-roster__cat {
  font-size: .78rem;
  opacity: .6;
  white-space: nowrap;
}

.stable-roster__time {
  font-size: .85rem;
  min-width: 4rem;
  text-align: end;
}

/* ----- Swords (kept separate, never merged) ---------------- */

.stable-swords {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-block: 16px;
}

.sword-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface-2);
  border-radius: 8px;
  border-inline-start: 3px solid var(--gold);
}

.sword-item__label {
  font-size: .88rem;
  font-weight: 500;
}

.sword-item__count {
  font-family: var(--f-mono, monospace);
  font-weight: 700;
  color: var(--gold);
}

/* ----- Cross links ----------------------------------------- */

.stable-cross-links {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 10px;
  margin-block-start: 10px;
  font-size: .88rem;
}

.stable-tribe-link,
.stable-rivalry-link,
.stable-chronicle-link {
  color: var(--green);
  text-decoration: none;
}

.stable-tribe-link:hover,
.stable-rivalry-link:hover,
.stable-chronicle-link:hover {
  text-decoration: underline;
}

.stable-story {
  font-size: .92rem;
  line-height: 1.65;
  opacity: .85;
  margin-block: 16px;
}

/* ----- Lens toggle (standings) ----------------------------- */

.lens-toggle {
  display: flex;
  flex-direction: row;
  gap: 4px;
  margin-block: 24px 10px;
  flex-wrap: wrap;
}

.lens-btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 18px;
  font: inherit;
  font-size: .85rem;
  font-weight: 500;
  color: inherit;
  opacity: .65;
  cursor: pointer;
  transition: background .18s, opacity .18s, border-color .18s;
  white-space: nowrap;
}

.lens-btn:hover,
.lens-btn:focus-visible {
  opacity: 1;
  border-color: var(--green);
  outline: none;
}

.lens-btn--active,
.lens-btn[aria-checked="true"] {
  background: var(--green);
  border-color: var(--green);
  color: var(--text-strong); /* pinned dark ink: --night is now warm-white (~3.2:1 on coral fails AA small) */
  opacity: 1;
}

.lens-concept-badge {
  margin-block-end: 10px;
}

/* ----- Lens panel ------------------------------------------ */

.lens-panel {
  animation: fadeIn .15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .lens-panel { animation: none; }
}

/* ----- Standings page --------------------------------------- */

.standings-page {
  padding-block: 48px 64px;
}

/* ----- Chronicle card (on standings) ----------------------- */

.chronicle-card {
  width: 100%;
  margin-block-end: 32px;
  background: var(--surface-2);
  border-radius: 8px;
  overflow: hidden;
  border-inline-start: 4px solid var(--gold);
}

.chronicle-card__inner {
  padding: 24px 32px;
}

.chronicle-card__title {
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  font-weight: 700;
  margin-block: 10px 10px;
}

.chronicle-card__body {
  font-size: .95rem;
  line-height: 1.7;
  opacity: .85;
  margin-block-end: 16px;
}

.chronicle-coming-soon {
  padding: 24px;
  opacity: .6;
  font-style: italic;
}

.lang-toggle {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
  color: inherit;
  transition: background .18s;
}

.lang-toggle:hover,
.lang-toggle:focus-visible {
  background: var(--surface-3);
  outline: none;
}

/* ----- Rivalry page (dark background) ---------------------- */

.rivalry-page {
  padding-block: 48px 64px;
}

.rivalry-page.dark,
.rivalry-page[data-dark] {
  background: var(--theater); /* intentional dark rivalry section */
  min-height: 100vh;
  color: var(--on-theater); /* warm-white text on theater backdrop */
}

.rivalry-card {
  max-width: 860px;
  margin-inline: auto;
  padding: 48px;
  background: var(--surface-2);
  border-radius: 8px;
}

.rivalry-stables {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
  margin-block: 16px;
  font-size: 1.15rem;
  font-weight: 600;
}

.rivalry-stable-link {
  text-decoration: none;
}

.rivalry-stable-link:hover {
  text-decoration: underline;
}

.rivalry-vs {
  opacity: .45;
  font-weight: 400;
}

.head-to-head {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: .9rem;
  margin-block: 16px;
  opacity: .8;
}

.h2h-wins {
  font-family: var(--f-mono, monospace);
  font-weight: 700;
  font-size: 1.15rem;
}

/* ----- Pulse-duel chart ------------------------------------- */

.pulse-duel-chart {
  width: 100%;
  margin-block: 16px;
}

.pulse-duel-chart svg {
  width: 100%;
  height: auto;
  display: block;
  background: var(--surface-3);
  border-radius: 6px;
}

.pulse-duel-axis {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  font-family: var(--f-mono, monospace);
  opacity: .55;
  margin-block-start: 4px;
  /* physical left-to-right for RTL: time axis runs right-to-left in AR
     matching race direction per PRD 12 section 7 */
  direction: ltr;
}

/* ----- Tribe page ------------------------------------------ */

.tribe-page {
  padding-block: 48px 64px;
}

.tribe-header {
  margin-block-end: 24px;
}

.tribe-header h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 700;
  margin-block-end: 6px;
}

.tribe-name-alt {
  font-size: .9rem;
  opacity: .55;
  letter-spacing: .04em;
}

.tribe-region {
  font-size: .88rem;
  opacity: .7;
  margin-block-start: 6px;
}

.tribe-map {
  margin-block: 24px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.map-placeholder {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.map-placeholder__label {
  font-size: .88rem;
  opacity: .55;
  font-style: italic;
}

/* ----- Nabati poetry --------------------------------------- */

.nabati-poetry {
  margin-block: 24px;
}

.poetry-excerpt {
  border-inline-start: 4px solid var(--gold);
  margin: 0;
  padding: 16px 24px;
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
}

.poetry-excerpt p {
  margin: 0 0 10px;
  font-size: .95rem;
  line-height: 1.75;
  font-style: italic;
}

.poetry-attribution {
  font-size: .8rem;
  opacity: .55;
  display: block;
  font-style: normal;
}

/* ----- Archive photo placeholder --------------------------- */

.archive-photo {
  margin-block: 24px;
  border-radius: 8px;
  overflow: hidden;
}

.photo-placeholder {
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  font-size: .88rem;
  opacity: .55;
  font-style: italic;
}

/* ----- Tribe stats ----------------------------------------- */

.tribe-stats {
  margin-block: 24px;
}

.tribe-stables-section {
  margin-block-start: 24px;
}

.tribe-stables-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tribe-stable-link {
  color: var(--green);
  text-decoration: none;
  font-weight: 500;
}

.tribe-stable-link:hover {
  text-decoration: underline;
}

/* ----- Chronicle archive page ------------------------------ */

.chronicles-page {
  padding-block: 48px 64px;
}

.chronicle-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-block-start: 24px;
}

.chronicle-item {
  background: var(--surface-2);
  border-radius: 8px;
  border-inline-start: 3px solid var(--gold);
}

.chronicle-item__link {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  text-decoration: none;
  color: inherit;
  transition: background .15s;
}

.chronicle-item__link:hover,
.chronicle-item__link:focus-visible {
  background: var(--surface-3);
  border-radius: 8px;
  outline: none;
}

.chronicle-item__day {
  font-family: var(--f-mono, monospace);
  font-size: .8rem;
  opacity: .55;
  white-space: nowrap;
}

.chronicle-item__title {
  font-weight: 500;
  font-size: .95rem;
}

/* ----- Responsive breakpoints (mobile-first) --------------- */

@media (max-width: 900px) {
  .rivalry-card { padding: 24px; }
  .stable-header { gap: 8px; }
}

@media (max-width: 860px) {
  .stable-roster__item { flex-wrap: wrap; }
  .chronicle-card__inner { padding: 16px 20px; }
}

@media (max-width: 820px) {
  .rivalry-stables { flex-direction: column; gap: 6px; }
  .lens-toggle { gap: 4px; }
}

@media (max-width: 720px) {
  .stable-page { padding-block: 24px 40px; }
  .chronicles-page { padding-block: 24px 40px; }
  .tribe-page { padding-block: 24px 40px; }
}

@media (max-width: 680px) {
  .tab-list { gap: 0; }
  .tab-btn { padding: 8px 12px; font-size: .82rem; }
  .stable-info__row { flex-direction: column; gap: 4px; }
}

@media (max-width: 560px) {
  .rivalry-card { padding: 16px; }
  .rivalry-stables { font-size: 1rem; }
  .lens-btn { padding: 5px 12px; font-size: .8rem; }
  .chronicle-item__link { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* ----- RTL/LTR flip (logical properties handle most; explicit overrides below) -- */

[dir="ltr"] .poetry-excerpt {
  border-inline-start: 4px solid var(--gold);
  border-radius: 0 8px 8px 0;
}

[dir="rtl"] .poetry-excerpt {
  border-inline-start: 4px solid var(--gold);
  border-radius: 8px 0 0 8px;
}

/* pulse-duel axis stays physical LTR so bpm numbers read left-to-right */
.pulse-duel-axis {
  unicode-bidi: isolate;
}
