/* ==========================================================================
   Resource library — layout for the catalogue and the interactive tools
   ========================================================================== */

.lib-hero {
  padding-block: clamp(3rem, 6vw, 5rem) clamp(2rem, 4vw, 3rem);
  position: relative;
  overflow: hidden;
}
.lib-hero::before {
  content: "";
  position: absolute;
  width: 46rem; height: 46rem;
  top: -28rem; right: -14rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 140, 116, 0.11), transparent 62%);
  pointer-events: none;
}
.lib-hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr);
  gap: clamp(1.75rem, 4vw, 3.5rem);
  align-items: end;
  position: relative;
}
.lib-hero h1 { font-size: clamp(2.4rem, 1.6rem + 3.6vw, 4.2rem); margin-block: 1rem 1.3rem; }
.lib-hero h1 em { font-style: italic; color: var(--clay-deep); }

.privacy-card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 0.7rem;
}
.privacy-card h2 { font-size: 1.15rem; font-family: var(--body); font-weight: 700; display: flex; align-items: center; gap: 0.55rem; }
.privacy-card h2 svg { color: var(--teal); flex: none; }
.privacy-card p { font-size: 0.9rem; color: var(--ink-2); line-height: 1.6; }

/* ---------- Toolbar ---------- */

.lib-toolbar {
  position: sticky;
  top: var(--header-h, 72px);
  z-index: 40;
  background: rgba(242, 237, 227, 0.94);
  backdrop-filter: blur(12px);
  border-block: 1px solid var(--line);
  padding-block: 1rem;
  margin-bottom: clamp(2rem, 4vw, 3rem);
}
.toolbar-inner { display: grid; gap: 0.85rem; }
.toolbar-row { display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: center; }
.toolbar-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  flex: none;
  margin-right: 0.15rem;
}
.result-count { font-size: 0.88rem; color: var(--ink-3); margin-left: auto; flex: none; }
.result-count strong { color: var(--ink); font-weight: 700; }

/* ---------- Resource cards ---------- */

.res-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
  gap: 1.1rem;
}
.res-card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  display: grid;
  gap: 0.6rem;
  align-content: start;
  box-shadow: var(--shadow-sm);
  transition: transform 0.26s var(--ease), box-shadow 0.26s var(--ease), border-color 0.2s var(--ease);
  animation: card-in 0.4s var(--ease) both;
}
@keyframes card-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.res-card:hover { transform: translateY(-3px); border-color: var(--ink-3); box-shadow: var(--shadow-md); }
.res-top { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.res-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--sage);
  color: var(--forest);
  display: grid;
  place-items: center;
  flex: none;
}
.res-type {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.res-card h3 { font-size: 1.22rem; line-height: 1.22; }
.res-card p { font-size: 0.9rem; color: var(--ink-2); line-height: 1.6; }
.res-meta { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--ink-3); }
.res-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.35rem; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: clamp(2.5rem, 6vw, 4.5rem) 1.5rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  background: rgba(251, 248, 242, 0.5);
}
.empty-state svg { color: var(--ink-3); margin: 0 auto 1rem; }
.empty-state h3 { font-size: 1.35rem; margin-bottom: 0.5rem; }
.empty-state p { color: var(--ink-3); max-width: 36ch; margin-inline: auto; font-size: 0.93rem; }

/* ---------- Tools ---------- */

.tools { background: var(--paper-deep); border-block: 1px solid var(--line); }
.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}
.tool {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: clamp(1.35rem, 2.6vw, 1.9rem);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 1rem;
  align-content: start;
  scroll-margin-top: 8rem;
}
.tool--wide { grid-column: 1 / -1; }
.tool-head { display: flex; align-items: flex-start; gap: 0.85rem; }
.tool-head .res-icon { background: var(--clay-soft); color: var(--clay-deep); }
.tool-head h3 { font-size: 1.3rem; }
.tool-head p { font-size: 0.88rem; color: var(--ink-3); margin-top: 0.3rem; line-height: 1.5; }
.tool-foot { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.tool .hint { font-size: 0.84rem; color: var(--ink-3); line-height: 1.5; }

/* Breathing pacer */
.breathe-stage {
  display: grid;
  place-items: center;
  padding: 1.5rem 0 0.5rem;
  min-height: 15rem;
  position: relative;
}
.breathe-orb {
  width: 11rem; height: 11rem;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, rgba(0, 140, 116, 0.3), rgba(0, 140, 116, 0.08) 58%, transparent 72%);
  border: 1px solid rgba(0, 140, 116, 0.3);
  display: grid;
  place-items: center;
  text-align: center;
  transform: scale(0.62);
  transition: transform var(--phase-ms, 4000ms) cubic-bezier(0.37, 0, 0.63, 1);
}
.breathe-orb[data-phase="in"] { transform: scale(1); }
.breathe-orb[data-phase="hold"], .breathe-orb[data-phase="holdOut"] { transform: scale(1); }
.breathe-orb[data-phase="holdOut"] { transform: scale(0.62); }
.breathe-orb[data-phase="out"] { transform: scale(0.62); }
.breathe-phase { font-family: var(--display); font-size: 1.45rem; color: var(--forest); line-height: 1.2; }
.breathe-timer { font-size: 2.1rem; font-family: var(--display); color: var(--clay-deep); line-height: 1; margin-top: 0.35rem; }
.breathe-cycles { font-size: 0.82rem; color: var(--ink-3); text-align: center; }
.breathe-modes { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Mood tracker */
.slider-row { display: grid; gap: 0.4rem; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.slider-head .label { margin: 0; }
.slider-value {
  font-family: var(--display);
  font-size: 1.5rem;
  line-height: 1;
  color: var(--forest);
}
.slider-scale { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--ink-3); }

.chart-wrap { position: relative; margin-top: 0.5rem; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 1.1rem; font-size: 0.84rem; color: var(--ink-2); margin-bottom: 0.6rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 0.45rem; }
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--forest-deep);
  color: #fbf8f2;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  line-height: 1.45;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translate(-50%, -112%);
  transition: opacity 0.15s var(--ease);
  white-space: nowrap;
  z-index: 5;
}
.chart-tip[data-show="true"] { opacity: 1; }
.chart-tip b { font-weight: 600; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin-top: 0.5rem; }
.data-table caption { text-align: left; font-size: 0.8rem; color: var(--ink-3); padding-bottom: 0.5rem; }
.data-table th, .data-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line-soft); }
.data-table th { font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); font-weight: 700; }
.data-table td:not(:first-child) { font-variant-numeric: tabular-nums; }

/* Reframe workspace */
.reframe-steps { display: grid; gap: 1rem; }
.reframe-row { display: grid; gap: 0.4rem; }
.reframe-row .step-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--clay-deep);
}
.reframe-row .step-badge b {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--clay-soft);
  color: var(--clay-deep);
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  flex: none;
}
.trap-note { font-size: 0.85rem; color: var(--ink-2); background: var(--sage); padding: 0.65rem 0.85rem; border-radius: var(--radius); line-height: 1.55; }
.trap-note:empty { display: none; }
.reframe-output {
  background: var(--forest-deep);
  color: rgba(251, 248, 242, 0.88);
  border-radius: var(--radius-lg);
  padding: 1.35rem 1.5rem;
  display: grid;
  gap: 0.6rem;
}
.reframe-output h4 { color: var(--clay-soft); font-size: 0.74rem; letter-spacing: 0.16em; text-transform: uppercase; }
.reframe-output p { font-family: var(--display); font-size: clamp(1.1rem, 1rem + 0.5vw, 1.35rem); line-height: 1.45; color: #fbf8f2; }
.reframe-output .placeholder { font-family: var(--body); font-size: 0.95rem; color: rgba(251, 248, 242, 0.6); font-style: italic; }

/* 5-4-3-2-1 grounding */
.ground-stage { display: grid; gap: 0.9rem; }
.ground-progress { display: flex; gap: 0.4rem; }
.ground-dot {
  height: 4px;
  flex: 1;
  border-radius: 999px;
  background: var(--line);
  transition: background-color 0.3s var(--ease);
}
.ground-dot[data-done="true"] { background: var(--teal); }
.ground-sense { display: flex; align-items: baseline; gap: 0.7rem; }
.ground-count { font-family: var(--display); font-size: 2.6rem; line-height: 1; color: var(--clay); }
.ground-prompt { font-family: var(--display); font-size: 1.25rem; line-height: 1.3; }
.ground-inputs { display: grid; gap: 0.5rem; }
.ground-inputs input { font-size: 0.95rem; }
.ground-done { display: grid; gap: 0.75rem; }

/* Saved indicator */
.saved-flag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--teal);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}
.saved-flag[data-show="true"] { opacity: 1; }

/* Safety band */
.safety {
  background: var(--forest-deep);
  color: rgba(251, 248, 242, 0.8);
}
.safety h2 { color: #fbf8f2; }
.safety-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(1.5rem, 4vw, 3.5rem); align-items: center; }
.safety a { color: var(--clay-soft); font-weight: 700; border-bottom: 1px solid rgba(239, 213, 194, 0.4); }
.safety-numbers { display: grid; gap: 0.85rem; }
.safety-number {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-lg);
  background: rgba(251, 248, 242, 0.05);
}
.safety-number strong { font-family: var(--display); font-size: 1.9rem; color: #fbf8f2; line-height: 1; flex: none; }
.safety-number span { font-size: 0.9rem; line-height: 1.5; }

@media (max-width: 980px) {
  .lib-hero-grid, .tool-grid, .safety-grid { grid-template-columns: minmax(0, 1fr); }
  .tracker-layout { grid-template-columns: minmax(0, 1fr) !important; }
  .lib-toolbar { position: static; }
}
@media (max-width: 560px) {
  .toolbar-row .chip { flex: 0 0 auto; }
  .result-count { margin-left: 0; width: 100%; }
  .breathe-orb { width: 9rem; height: 9rem; }
}
