/* ============================================================
   UX Writing+ — Global Stylesheet
   ============================================================ */

/* --- Variables (design system tokens) --- */
:root {
  /* Color: surfaces */
  --color-bg:           #f4f5f7;
  --color-surface:      #ffffff;
  --color-text:         #16181d;
  --color-text-muted:   #52576b;
  --color-border:       #e0e3ea;

  /* Color: accent */
  --color-accent:       #2f5bea;
  --color-accent-light: #eaeffd;

  /* Color: tags */
  --color-tag-bg:       #eaeffd;
  --color-tag-text:     #2f5bea;

  /* Color: semantic (before/after examples) */
  --color-before:       #5d636e;
  --color-after:        #1a6644;

  /* Type */
  --font-sans: 'obviously-variable', 'Sora', system-ui, -apple-system, sans-serif;

  --size-sm:   0.875rem;
  --size-base: 1rem;
  --size-lg:   1.25rem;
  --size-xl:   1.75rem;
  --size-2xl:  2.5rem;
  --size-3xl:  3.5rem;

  --line-height-body:    1.7;
  --line-height-heading: 1.2;

  --weight-regular:  400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;

  /* Spacing */
  --space-xs:  0.5rem;
  --space-sm:  1rem;
  --space-md:  1.5rem;
  --space-lg:  2.5rem;
  --space-xl:  4rem;
  --space-2xl: 6rem;

  /* Layout */
  --max-width:     1200px;
  --content-width: 720px;

  /* Header */
  --header-height:       68px;
  --header-height-small: 52px;

  /* Radii */
  --radius:        4px;
  --radius-button: 8px;
  --radius-card:   8px;
  --radius-pill:   100px;

  /* Shadows */
  --shadow-card:      0 2px 12px rgba(0,0,0,0.06);
  --shadow-header:    0 2px 16px rgba(0,0,0,0.08);
  --shadow-header-sm: 0 2px 24px rgba(0,0,0,0.12);
  --shadow-popover:   0 4px 20px rgba(0,0,0,0.10);

  /* Gradients */
  --gradient-hero:    linear-gradient(160deg, #eaedfa 0%, var(--color-bg) 60%);
  --gradient-callout: linear-gradient(135deg, var(--color-accent-light) 0%, var(--color-surface) 100%);

  /* Motion */
  --dur-fast:   0.15s;
  --dur-medium: 0.25s;
  --dur-slow:   0.30s;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

body {
  font-family: var(--font-sans);
  font-size: var(--size-base);
  line-height: var(--line-height-body);
  color: var(--color-text);
  background: var(--gradient-hero);
  -webkit-font-smoothing: antialiased;
  padding-top: 1.5rem;
}

img, svg { display: block; max-width: 100%; }

a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
a:hover { opacity: 0.7; }

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  line-height: var(--line-height-heading);
  font-weight: var(--weight-bold);
  letter-spacing: -0.01em;
}
h1 { font-size: var(--size-3xl); letter-spacing: -0.02em; }
h2 { font-size: var(--size-2xl); }
h3 { font-size: var(--size-xl); }
h4 { font-size: var(--size-lg); }
h5, h6 { font-size: var(--size-base); }
p + p { margin-top: var(--space-sm); }

/* --- Layout --- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.content-width { max-width: var(--content-width); }

/* --- Floating header --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: transparent;
  border-bottom: none;
  height: auto;
  padding: 1.25rem var(--space-lg);
  transform: translateY(0);
  transition: transform var(--dur-slow) ease, box-shadow var(--dur-medium) ease;
}

.site-header.is-hidden {
  transform: translateY(-200px);
}

.site-header .container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 0.875rem 1.75rem;
  height: var(--header-height);
  box-shadow: var(--shadow-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: height var(--dur-medium) ease, padding var(--dur-medium) ease, box-shadow var(--dur-medium) ease;
}

.site-header.is-scrolled .container {
  height: var(--header-height-small);
  padding: 0 1.5rem;
  box-shadow: var(--shadow-header-sm);
}

.site-logo {
  font-size: var(--size-lg);
  font-weight: var(--weight-bold);
  text-decoration: none;
  letter-spacing: -0.02em;
  transition: font-size var(--dur-medium) ease;
  white-space: nowrap;
}

.site-header.is-scrolled .site-logo { font-size: var(--size-base); }

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  list-style: none;
}

.site-nav a {
  font-size: 0.8rem;
  font-weight: var(--weight-medium);
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: opacity var(--dur-fast) ease;
}

.site-nav a:hover { opacity: 0.6; }
.site-nav a[aria-current="page"] { text-decoration: underline; text-underline-offset: 4px; }

/* --- Scroll fade --- */
.scroll-fade {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(to bottom, var(--color-bg) 40%, transparent 100%);
  pointer-events: none;
  z-index: 99;
  opacity: 0;
  transition: opacity var(--dur-medium) ease;
}

.scroll-fade.visible { opacity: 1; }

/* --- Footer --- */
.site-footer {
  background: #eaedfa;
  padding: var(--space-xl) 0;
  margin-top: 0;
}

.site-footer .container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
  align-items: start;
}

.footer-about p {
  font-size: var(--size-sm);
  color: var(--color-text-muted);
  max-width: 340px;
  margin-top: var(--space-xs);
}

.footer-about a { color: var(--color-text-muted); }

.footer-nav {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  justify-content: flex-end;
  list-style: none;
  align-items: center;
}

.footer-nav a {
  font-size: var(--size-sm);
  text-decoration: none;
  color: var(--color-text-muted);
}

.footer-nav a:hover { color: var(--color-text); opacity: 1; }

/* --- Cards --- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}

.card-grid > * {
  margin-bottom: 0;
}

/* Index nav cards: standard grid, left-aligned */
.card-grid--index {
  columns: unset;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-md);
}

.card-grid--index > * {
  margin-bottom: 0;
}

.card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: var(--space-md);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  background: var(--color-surface);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}

.card:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-card);
  opacity: 1;
}

.card-title { font-size: var(--size-lg); font-weight: var(--weight-bold); }
.card-desc { font-size: var(--size-sm); color: var(--color-text-muted); line-height: 1.5; }

/* --- Tags --- */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  list-style: none;
  margin-top: auto;
  padding-top: var(--space-xs);
}

.tag {
  font-size: 0.75rem;
  font-weight: var(--weight-medium);
  letter-spacing: 0.03em;
  background: var(--color-tag-bg);
  color: var(--color-tag-text);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  text-decoration: none;
  display: inline-block;
}

a.tag:hover { opacity: 0.8; }

/* --- Page sections --- */
.page-hero {
  padding: var(--space-2xl) 0 var(--space-xl);
  border-bottom: 1px solid var(--color-border);
}

.page-hero h1 { margin-bottom: var(--space-sm); }

.page-hero p {
  font-size: var(--size-lg);
  color: var(--color-text-muted);
  max-width: 600px;
}

.page-section { padding: var(--space-xl) 0; }
.page-section + .page-section { border-top: 1px solid var(--color-border); }

.section-label {
  font-size: var(--size-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
}

/* --- Filter bar --- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  align-items: center;
  margin-bottom: var(--space-lg);
}

.filter-bar-label {
  font-size: var(--size-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  margin-right: var(--space-xs);
}

.filter-tag {
  font-size: 0.75rem;
  font-weight: var(--weight-medium);
  letter-spacing: 0.03em;
  background: var(--color-tag-bg);
  color: var(--color-tag-text);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease, color var(--dur-fast) ease;
}

.filter-tag:hover { border-color: var(--color-accent); }

.filter-tag.active {
  background: var(--color-accent);
  color: var(--color-surface);
  border-color: var(--color-accent);
}

.card-grid li.hidden { display: none; }

/* --- Hover card (link preview) --- */
.hover-card-wrapper {
  position: relative;
  display: inline;
}

.hover-card-preview {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 280px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: var(--space-sm);
  box-shadow: var(--shadow-popover);
  z-index: 200;
  pointer-events: none;
}

.hover-card-preview strong {
  display: block;
  font-size: var(--size-sm);
  margin-bottom: 4px;
}

.hover-card-preview p {
  font-size: var(--size-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
  margin: 0;
}

.hover-card-wrapper:hover .hover-card-preview,
.hover-card-wrapper:focus-within .hover-card-preview { display: block; }

/* --- Topic pages (best practices / inclusive writing) --- */
.topic-hero {
  padding: var(--space-2xl) 0 var(--space-xl);
  border-bottom: 1px solid var(--color-border);
}

.breadcrumb {
  font-size: var(--size-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
  display: flex;
  gap: 0.375rem;
  align-items: center;
}

.breadcrumb a { color: var(--color-text-muted); }
.breadcrumb span[aria-hidden] { color: var(--color-border); }

.topic-hero h1 { margin-bottom: var(--space-sm); }
.topic-hero .topic-lead {
  font-size: var(--size-lg);
  color: var(--color-text-muted);
  max-width: 600px;
  margin-top: var(--space-sm);
}

.topic-body { padding: var(--space-xl) 0; }

.topic-body .container {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--space-2xl);
  align-items: start;
}

.topic-content h2 {
  font-size: var(--size-xl);
  margin-top: var(--space-xl);
  margin-bottom: var(--space-sm);
}

.topic-content h2:first-child { margin-top: 0; }
.topic-content p { color: var(--color-text-muted); }
.topic-content p + p { margin-top: var(--space-sm); }

.topic-content ul {
  margin: var(--space-sm) 0 var(--space-sm) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  color: var(--color-text-muted);
}

/* --- Rule callout --- */
.rule-callout {
  border-left: 3px solid var(--color-accent);
  padding: var(--space-sm) var(--space-md);
  margin: var(--space-md) 0;
  background: var(--gradient-callout);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.rule-callout p {
  font-size: var(--size-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  margin: 0;
  line-height: 1.4;
}

/* --- Before/after example --- */
.example-block {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  overflow: hidden;
  margin: var(--space-md) 0;
  background: var(--color-surface);
}

.example-block-header {
  font-size: var(--size-sm);
  font-weight: var(--weight-semibold);
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-accent-light);
  border-bottom: 1px solid var(--color-border);
}

.example-row { display: grid; grid-template-columns: 1fr 1fr; }

.example-before, .example-after { padding: var(--space-sm); }
.example-before { border-right: 1px solid var(--color-border); }

.example-label {
  font-size: 0.75rem;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  margin-bottom: var(--space-xs);
}

.example-label.before { color: var(--color-before); }
.example-label.after  { color: var(--color-after); }
.example-copy { font-size: var(--size-base); color: var(--color-text); }
.example-note {
  font-size: var(--size-sm);
  color: var(--color-text-muted);
  padding: var(--space-xs) var(--space-sm);
  border-top: 1px solid var(--color-border);
  background: var(--color-accent-light);
}

/* --- Topic sidebar --- */
.topic-sidebar {
  position: sticky;
  top: calc(var(--header-height-small) + var(--space-md));
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.sidebar-block {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: var(--space-sm);
  background: var(--color-surface);
}

.sidebar-block h3 {
  font-size: var(--size-sm);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-sm);
  color: var(--color-text-muted);
}

.sidebar-links { list-style: none; display: flex; flex-direction: column; gap: var(--space-xs); }
.sidebar-links a { font-size: var(--size-sm); }

.topic-nav {
  display: flex;
  justify-content: space-between;
  padding: var(--space-lg) 0;
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-xl);
}

.topic-nav a { font-size: var(--size-sm); font-weight: var(--weight-medium); }

/* --- Contact form --- */
.contact-section {
  padding: var(--space-lg) 0;
  background: linear-gradient(to bottom, transparent, #eaedfa);
}

.contact-section .container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2xl);
  align-items: start;
}

.contact-intro h2 {
  font-size: var(--size-xl);
  margin-bottom: var(--space-xs);
}

.contact-intro p {
  font-size: var(--size-sm);
  color: var(--color-text-muted);
  max-width: 360px;
}

.contact-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.form-field { display: flex; flex-direction: column; gap: 0.375rem; }
.form-field label { font-size: var(--size-sm); font-weight: var(--weight-medium); }

.form-field input,
.form-field textarea {
  font-family: var(--font-sans);
  font-size: var(--size-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.625rem 0.875rem;
  width: 100%;
  transition: border-color var(--dur-fast) ease;
  -webkit-appearance: none;
}

.form-field input:focus,
.form-field textarea:focus { outline: none; border-color: var(--color-accent); }

.form-field textarea { min-height: 80px; resize: vertical; line-height: var(--line-height-body); }

.form-submit {
  font-family: var(--font-sans);
  font-size: var(--size-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-surface);
  background: var(--color-accent);
  border: none;
  border-radius: var(--radius-button);
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  align-self: flex-start;
  transition: opacity var(--dur-fast) ease;
}

.form-submit:hover { opacity: 0.8; }

.form-success {
  display: none;
  font-size: var(--size-sm);
  color: var(--color-text-muted);
  padding: var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

/* --- Glossary --- */
.glossary-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.search-wrapper { position: relative; max-width: 480px; }

.search-wrapper svg {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}

.glossary-search {
  font-family: var(--font-sans);
  font-size: var(--size-base);
  width: 100%;
  padding: 0.625rem 0.875rem 0.625rem 2.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--dur-fast) ease;
  -webkit-appearance: none;
}

.glossary-search:focus { outline: none; border-color: var(--color-accent); }

.alpha-nav { display: flex; flex-wrap: wrap; gap: 4px; list-style: none; }

.alpha-nav a,
.alpha-nav span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: var(--size-sm);
  font-weight: var(--weight-medium);
  border-radius: var(--radius);
  text-decoration: none;
  transition: background var(--dur-fast) ease;
}

.alpha-nav a { background: var(--color-tag-bg); color: var(--color-text); }
.alpha-nav a:hover { background: var(--color-accent); color: var(--color-surface); opacity: 1; }
.alpha-nav a.active { background: var(--color-accent); color: var(--color-surface); }
.alpha-nav span { color: var(--color-border); cursor: default; }

.glossary-section { margin-bottom: var(--space-xl); }

.glossary-section-letter {
  font-size: var(--size-2xl);
  font-weight: var(--weight-bold);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-md);
  scroll-margin-top: 5rem;
}

.glossary-entries { display: flex; flex-direction: column; gap: var(--space-sm); list-style: none; }

.glossary-entry {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  background: var(--color-surface);
  transition: border-color var(--dur-fast) ease;
}

.glossary-entry:hover { border-color: var(--color-accent); }

.glossary-entry a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  text-decoration: none;
}

.entry-term { font-weight: var(--weight-semibold); font-size: var(--size-base); white-space: nowrap; min-width: 200px; }
.entry-definition { font-size: var(--size-sm); color: var(--color-text-muted); flex: 1; }
.entry-tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; min-width: 120px; }
.glossary-entry .tag { font-size: 0.7rem; }

.no-results { display: none; color: var(--color-text-muted); font-size: var(--size-base); padding: var(--space-lg) 0; }

/* --- Glossary entry page tabs --- */
.entry-hero { padding: var(--space-2xl) 0 var(--space-xl); border-bottom: 1px solid var(--color-border); }
.entry-body { padding: var(--space-xl) 0; }

.entry-body .container {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: var(--space-2xl);
  align-items: start;
}

.tab-list {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  list-style: none;
  margin-bottom: var(--space-lg);
}

.tab-btn {
  font-family: var(--font-sans);
  font-size: var(--size-sm);
  font-weight: var(--weight-medium);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: var(--space-xs) var(--space-md);
  cursor: pointer;
  color: var(--color-text-muted);
  margin-bottom: -1px;
  transition: color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}

.tab-btn:hover { color: var(--color-text); }
.tab-btn.active { color: var(--color-text); border-bottom-color: var(--color-accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-panel p { color: var(--color-text-muted); line-height: var(--line-height-body); }
.tab-panel p + p { margin-top: var(--space-sm); }

.see-also { margin-top: var(--space-xl); padding-top: var(--space-lg); border-top: 1px solid var(--color-border); }
.see-also h3 { font-size: var(--size-base); font-weight: var(--weight-semibold); margin-bottom: var(--space-sm); }
.see-also ul { list-style: none; display: flex; flex-direction: column; gap: var(--space-xs); }
.see-also a { font-size: var(--size-sm); }

.entry-sidebar { position: sticky; top: calc(var(--header-height-small) + var(--space-md)); display: flex; flex-direction: column; gap: var(--space-md); }

.entry-nav {
  display: flex;
  justify-content: space-between;
  padding: var(--space-lg) 0;
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-xl);
}

.entry-nav a { font-size: var(--size-sm); font-weight: var(--weight-medium); }

/* --- Resources external link indicator --- */
.card.external .card-title::after {
  content: " ↗";
  font-size: 0.8em;
  opacity: 0.5;
}

/* --- Utility --- */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* --- Responsive --- */
@media (max-width: 900px) {
  .topic-body .container,
  .entry-body .container { grid-template-columns: 1fr; }
  .topic-sidebar, .entry-sidebar { position: static; flex-direction: row; flex-wrap: wrap; }
  .sidebar-block { flex: 1 1 200px; }
}

@media (max-width: 768px) {
  :root {
    --size-3xl: 2.25rem;
    --size-2xl: 1.75rem;
  }

  .site-nav { gap: var(--space-md); }
  .site-footer .container { grid-template-columns: 1fr; }
  .footer-nav { justify-content: flex-start; }
  .contact-section .container { grid-template-columns: 1fr; gap: var(--space-lg); }
  .glossary-entry a { flex-direction: column; gap: var(--space-xs); }
  .entry-tags { justify-content: flex-start; }
}
