/* ============================================================
   Cinnaboner — Article Index Control
   Assumes: Albert Sans + Remixicon are already loaded on the page.
   All class names prefixed with `idx-` to avoid clashing with
   Remixicon's `ri-*` selectors.
   ============================================================ */
.reading-index {
  --ri-ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ri-dur:  200ms;

  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9998;

  width: 231px;
  background: rgba(255, 248, 242, 0.85);
  border: 1px solid rgba(255, 148, 93, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 6px 5px 6px 14px;
  box-shadow: 0 4px 12px rgba(255, 148, 93, 0.12);

  font-family: 'Albert Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #1A0D03;
  font-size: 14px;
  font-weight: 500;

  display: flex;
  flex-direction: column-reverse;
  user-select: none;
  max-width: calc(100vw - 32px);

  transition:
    border-radius var(--ri-dur) var(--ri-ease),
    background    var(--ri-dur) ease,
    border-color  var(--ri-dur) ease,
    box-shadow    var(--ri-dur) ease;
}
.reading-index:hover {
  background: #FFFCF9;
  border-color: #FF945D;
  box-shadow: 0 6px 20px rgba(255, 148, 93, 0.18);
}
.reading-index.is-open,
.reading-index.is-open:hover {
  border-radius: 16px;
  border-color: #E5D9CC;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
}

.idx-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 36px;
  cursor: pointer;
}
.idx-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

/* Circular progress ring (20px footprint, same as chat widget icon) */
.idx-ring {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.idx-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  display: block;
}
.idx-ring-track {
  stroke: rgba(255, 148, 93, 0.22);
  fill: none;
  stroke-width: 3;
}
.idx-ring-fill {
  stroke: #FF945D;
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 120ms linear;
}

.idx-label {
  display: inline-flex;
  align-items: center;
  gap: 0;
  color: #1A0D03;
  font-size: 14px;
  font-weight: 300;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.idx-chev {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: #887C76;
  flex-shrink: 0;
  margin-left: -2px;
  transition: transform var(--ri-dur) var(--ri-ease);
  transform: rotate(180deg);
}
.reading-index.is-open .idx-chev { transform: rotate(0deg); }

/* Plain orange percent text, no fill */
.idx-percent {
  background: transparent;
  color: #FF945D;
  border: none;
  height: 36px;
  padding: 0 8px;
  min-width: 44px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* Expanded list — shifted -9px left in both states so items are
   visually centered against the asymmetric container padding (14L/5R)
   AND so the list doesn't "snap" during open/close transitions. */
.idx-list {
  list-style: none;
  margin: 0 0 0 -9px;
  padding: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition:
    max-height    var(--ri-dur) var(--ri-ease),
    opacity       160ms linear,
    margin-bottom var(--ri-dur) var(--ri-ease);
}
.reading-index.is-open .idx-list {
  max-height: 50vh;
  opacity: 1;
  overflow-y: auto;
  margin-bottom: 8px;
  padding: 2px 0 0;
}
.idx-item {
  color: #887C76;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.3px;
  line-height: 1.35;
  transition: color 120ms linear, background 120ms linear;
}
.idx-item:hover {
  color: #1A0D03;
  background: rgba(255, 148, 93, 0.08);
}
.idx-item.is-active {
  color: #FF945D;
  font-weight: 600;
}
.idx-item.level-3 {
  padding-left: 22px;
  font-size: 13px;
}

/* Cream wash overlay while the menu is open */
.idx-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 250, 246, 0.7);
  opacity: 0;
  pointer-events: none;
  z-index: 9997;
  transition: opacity var(--ri-dur) ease;
}
body.is-index-open .idx-overlay { opacity: 1; }

/* Scrollbar inside expanded list */
.idx-list::-webkit-scrollbar { width: 4px; }
.idx-list::-webkit-scrollbar-thumb {
  background: #E5D9CC;
  border-radius: 2px;
}

@media (max-width: 640px) {
  .reading-index {
    width: calc(100vw - 32px);
    max-width: 320px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reading-index,
  .idx-chev,
  .idx-list,
  .idx-item,
  .idx-ring-fill,
  .idx-overlay { transition: none !important; }
}
