/* ============================================================
   tnms — shared document stylesheet
   Light / Dark theme via CSS custom properties
   ============================================================ */

/* --- Theme tokens ------------------------------------------ */
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Menlo', monospace;

  /* Light theme (default) */
  --bg: #f5f5fa;
  --bg-surface: #ffffff;
  --bg-code: #eef0f5;
  --text: #1a1a2e;
  --text-secondary: #5a5a72;
  --text-muted: #8e8ea0;
  --border: #dcdce8;
  --accent: #4361ee;
  --accent-hover: #3a56d4;
  --accent-glow: rgba(67, 97, 238, 0.15);
  --link: #4361ee;
  --link-hover: #3a56d4;
  --shadow: rgba(67, 97, 238, 0.08);
  --shadow-lg: rgba(67, 97, 238, 0.12);
  --toggle-bg: #e2e2ea;
  --toggle-fg: #1a1a2e;
  --tag-bg: #eef0fb;
  --tag-text: #4361ee;
  --gradient-1: rgba(67, 97, 238, 0.06);
  --gradient-2: rgba(124, 58, 237, 0.04);
  --gradient-3: rgba(236, 72, 153, 0.03);
  --grid-color: rgba(67, 97, 238, 0.06);
  --dot-color: rgba(67, 97, 238, 0.12);
}

[data-theme="dark"] {
  --bg: #0a0a14;
  --bg-surface: #12121e;
  --bg-code: #16162a;
  --text: #e4e4ef;
  --text-secondary: #a0a0b8;
  --text-muted: #6c6c82;
  --border: #1e1e34;
  --accent: #7b8cff;
  --accent-hover: #9ba6ff;
  --accent-glow: rgba(123, 140, 255, 0.12);
  --link: #7b8cff;
  --link-hover: #9ba6ff;
  --shadow: rgba(123, 140, 255, 0.06);
  --shadow-lg: rgba(123, 140, 255, 0.1);
  --toggle-bg: #1e1e34;
  --toggle-fg: #e4e4ef;
  --tag-bg: #16162e;
  --tag-text: #7b8cff;
  --gradient-1: rgba(123, 140, 255, 0.05);
  --gradient-2: rgba(139, 92, 246, 0.04);
  --gradient-3: rgba(236, 72, 153, 0.03);
  --grid-color: rgba(123, 140, 255, 0.05);
  --dot-color: rgba(123, 140, 255, 0.1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background 0.4s ease, color 0.3s ease;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* --- Animated background ----------------------------------- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, var(--gradient-1) 0%, transparent 60%),
    radial-gradient(ellipse 60% 80% at 80% 30%, var(--gradient-2) 0%, transparent 60%),
    radial-gradient(ellipse 70% 50% at 50% 90%, var(--gradient-3) 0%, transparent 60%);
  animation: bgShift 20s ease-in-out infinite alternate;
  transition: background 0.4s ease;
}

@keyframes bgShift {
  0% {
    transform: scale(1) translate(0, 0);
  }

  33% {
    transform: scale(1.05) translate(-2%, 3%);
  }

  66% {
    transform: scale(1.02) translate(2%, -2%);
  }

  100% {
    transform: scale(1) translate(-1%, 1%);
  }
}

/* Dot grid overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(circle, var(--dot-color) 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.5;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, black 30%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, black 30%, transparent 70%);
  transition: opacity 0.4s ease;
  pointer-events: none;
}

/* --- Layout ------------------------------------------------ */
.doc-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
  animation: fadeInUp 0.5s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Header / Nav ------------------------------------------ */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  max-width: 900px;
  margin: 0 auto;
  animation: fadeInDown 0.4s ease-out;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.site-header .logo {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.5px;
  transition: color 0.2s ease;
}

.site-header .logo:hover {
  text-decoration: none;
}

.site-header .logo span {
  color: var(--accent);
  display: inline-block;
  transition: transform 0.2s ease;
}

.site-header .logo:hover span {
  transform: translateX(3px);
}

/* --- Theme toggle button ----------------------------------- */
.theme-toggle {
  background: var(--toggle-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--toggle-fg);
  font-size: 1.1rem;
  transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.theme-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  transition: transform 0.3s ease;
}

.theme-toggle:hover svg {
  transform: rotate(-15deg);
}

/* --- Typography -------------------------------------------- */
h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--text);
  font-weight: 650;
  line-height: 1.3;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

h1 {
  font-size: 2.2rem;
  letter-spacing: -0.8px;
  margin-top: 0;
  background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: 1.45rem;
  letter-spacing: -0.3px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  position: relative;
}

h2::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 40px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  transition: width 0.3s ease;
}

h2:hover::after {
  width: 80px;
}

h3 {
  font-size: 1.15rem;
}

h4 {
  font-size: 1rem;
  color: var(--text-secondary);
}

p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

strong {
  color: var(--text);
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color 0.2s ease, text-shadow 0.2s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
  text-shadow: 0 0 12px var(--accent-glow);
}

/* --- Lists ------------------------------------------------- */
ul,
ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

li {
  margin-bottom: 0.35rem;
}

li::marker {
  color: var(--text-muted);
}

/* --- Code -------------------------------------------------- */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-code);
  padding: 0.15em 0.45em;
  border-radius: 5px;
  color: var(--accent);
  border: 1px solid var(--border);
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 1.25rem;
  line-height: 1.55;
  position: relative;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

pre:hover {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 0.85rem;
  border: none;
}

/* --- Blockquote -------------------------------------------- */
blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.85rem 1.1rem;
  margin: 1rem 0 1.25rem;
  background: var(--bg-code);
  border-radius: 0 10px 10px 0;
  color: var(--text-secondary);
  position: relative;
  overflow: hidden;
}

blockquote::before {
  content: '"';
  position: absolute;
  top: -8px;
  left: 8px;
  font-size: 3.5rem;
  font-family: Georgia, serif;
  color: var(--accent);
  opacity: 0.12;
  line-height: 1;
}

/* --- Horizontal rule --------------------------------------- */
hr {
  border: none;
  height: 1px;
  margin: 2rem 0;
  background: linear-gradient(90deg, transparent, var(--border) 20%, var(--accent) 50%, var(--border) 80%, transparent);
  opacity: 0.6;
}

/* --- Tables ------------------------------------------------ */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.25rem;
  font-size: 0.925rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

th,
td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text);
  background: var(--bg-code);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

td {
  color: var(--text-secondary);
  transition: background 0.15s ease;
}

tr:hover td {
  background: var(--accent-glow);
}

/* --- Document index (landing page) ------------------------- */
.doc-list {
  list-style: none;
  padding: 0;
}

.doc-list li {
  margin-bottom: 0;
  animation: fadeInUp 0.5s ease-out backwards;
}

.doc-list li:nth-child(1) {
  animation-delay: 0.1s;
}

.doc-list li:nth-child(2) {
  animation-delay: 0.18s;
}

.doc-list li:nth-child(3) {
  animation-delay: 0.26s;
}

.doc-list li:nth-child(4) {
  animation-delay: 0.34s;
}

.doc-list li:nth-child(5) {
  animation-delay: 0.42s;
}

.doc-list li:nth-child(6) {
  animation-delay: 0.50s;
}

.doc-list li:nth-child(7) {
  animation-delay: 0.58s;
}

.doc-list li:nth-child(8) {
  animation-delay: 0.66s;
}

.doc-list a {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1.15rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 0.6rem;
  text-decoration: none;
  color: var(--text);
  background: var(--bg-surface);
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease, background 0.25s ease;
  position: relative;
  overflow: hidden;
}

.doc-list a::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent-glow) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.doc-list a:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 24px var(--shadow-lg), 0 0 0 1px var(--accent-glow);
  transform: translateY(-2px);
  text-decoration: none;
}

.doc-list a:hover::before {
  opacity: 1;
}

.doc-list .doc-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  transition: transform 0.25s ease;
  position: relative;
  z-index: 1;
}

.doc-list a:hover .doc-icon {
  transform: scale(1.15);
}

.doc-list .doc-title {
  font-weight: 600;
  font-size: 0.95rem;
  position: relative;
  z-index: 1;
}

.doc-list .doc-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  position: relative;
  z-index: 1;
}

/* --- Breadcrumb -------------------------------------------- */
.breadcrumb {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  animation: fadeInUp 0.4s ease-out;
}

.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.breadcrumb a:hover {
  color: var(--accent);
  text-decoration: none;
  text-shadow: none;
}

.breadcrumb .sep {
  margin: 0 0.35rem;
  opacity: 0.4;
}

/* --- Doc count badge --------------------------------------- */
.doc-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  background: var(--bg-code);
  padding: 0.2em 0.6em;
  border-radius: 6px;
  border: 1px solid var(--border);
  position: relative;
  z-index: 1;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.doc-list a:hover .doc-count {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Tags -------------------------------------------------- */
.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 0.2em 0.6em;
  border-radius: 5px;
  letter-spacing: 0.3px;
  border: 1px solid transparent;
  transition: border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.tag:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* --- Footer ------------------------------------------------ */
.site-footer {
  text-align: center;
  padding: 2.5rem 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 1px;
  position: relative;
}

.site-footer::before {
  content: '';
  display: block;
  width: 32px;
  height: 2px;
  background: var(--accent);
  margin: 0 auto 1rem;
  border-radius: 1px;
  opacity: 0.4;
}

/* --- Responsive -------------------------------------------- */

/* Wide desktop — allow content to breathe more */
@media (min-width: 1200px) {
  .doc-container {
    max-width: 1080px;
    padding: 3rem 2.5rem 5rem;
  }

  .site-header {
    max-width: 1080px;
    padding: 1.5rem 2.5rem;
  }

  h1 {
    font-size: 2.5rem;
  }
}

/* Tablet landscape */
@media (max-width: 768px) {
  .doc-container {
    padding: 2rem 1.25rem 3.5rem;
  }

  .site-header {
    padding: 1rem 1.25rem;
  }

  h1 {
    font-size: 1.85rem;
  }

  h2 {
    font-size: 1.3rem;
  }

  h3 {
    font-size: 1.05rem;
  }

  pre {
    padding: 0.9rem 1rem;
    border-radius: 8px;
  }

  pre code {
    font-size: 0.82rem;
  }

  .doc-list a {
    padding: 0.9rem 1rem;
    gap: 0.75rem;
  }
}

/* Small tablet / large phone */
@media (max-width: 600px) {
  .doc-container {
    padding: 1.5rem 1rem 3rem;
  }

  .site-header {
    padding: 0.85rem 1rem;
  }

  .site-header .logo {
    font-size: 1.1rem;
  }

  h1 {
    font-size: 1.6rem;
    letter-spacing: -0.4px;
  }

  h2 {
    font-size: 1.2rem;
    padding-bottom: 0.35rem;
  }

  h2::after {
    width: 28px;
  }

  h2:hover::after {
    width: 56px;
  }

  h3 {
    font-size: 1rem;
  }

  p,
  li {
    font-size: 0.92rem;
  }

  /* Cards stack content better on small screens */
  .doc-list a {
    padding: 0.85rem 0.9rem;
    gap: 0.65rem;
    border-radius: 10px;
  }

  .doc-list .doc-icon {
    font-size: 1.15rem;
  }

  .doc-list .doc-title {
    font-size: 0.9rem;
  }

  .doc-list .doc-desc {
    font-size: 0.78rem;
  }

  /* Doc count moves below on narrow cards */
  .doc-count {
    font-size: 0.68rem;
    padding: 0.15em 0.5em;
  }

  /* Breadcrumb wrapping */
  .breadcrumb {
    font-size: 0.75rem;
    word-break: break-all;
  }

  .breadcrumb .sep {
    margin: 0 0.25rem;
  }

  /* Code blocks */
  code {
    font-size: 0.82em;
    padding: 0.12em 0.35em;
  }

  pre {
    padding: 0.8rem 0.9rem;
    border-radius: 8px;
    margin-left: -0.25rem;
    margin-right: -0.25rem;
  }

  pre code {
    font-size: 0.78rem;
  }

  /* Tables: horizontal scroll wrapper */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    font-size: 0.85rem;
  }

  th,
  td {
    padding: 0.5rem 0.65rem;
  }

  th {
    font-size: 0.72rem;
  }

  /* Blockquote */
  blockquote {
    padding: 0.7rem 0.9rem;
    margin-left: 0;
    margin-right: 0;
  }

  blockquote::before {
    font-size: 2.5rem;
  }

  /* Tags */
  .tag {
    font-size: 0.68rem;
    padding: 0.15em 0.5em;
  }

  /* Footer */
  .site-footer {
    padding: 2rem 1rem;
    font-size: 0.72rem;
  }

  /* Reduce background dot density on mobile */
  body::after {
    background-size: 32px 32px;
    opacity: 0.3;
  }
}

/* Phone portrait */
@media (max-width: 420px) {
  .doc-container {
    padding: 1.25rem 0.85rem 2.5rem;
  }

  .site-header {
    padding: 0.75rem 0.85rem;
  }

  .site-header .logo {
    font-size: 1rem;
  }

  h1 {
    font-size: 1.4rem;
  }

  h2 {
    font-size: 1.1rem;
  }

  /* Make cards full-touch-friendly */
  .doc-list a {
    padding: 0.8rem 0.85rem;
    gap: 0.55rem;
    /* min height for comfortable tapping */
    min-height: 56px;
  }

  .doc-list .doc-title {
    font-size: 0.85rem;
  }

  .doc-list .doc-desc {
    font-size: 0.74rem;
  }

  .doc-list .doc-icon {
    font-size: 1.05rem;
  }

  /* Theme toggle touch target */
  .theme-toggle {
    width: 42px;
    height: 42px;
    border-radius: 10px;
  }

  /* Code: slightly smaller */
  pre code {
    font-size: 0.74rem;
  }

  pre {
    padding: 0.7rem 0.75rem;
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    border-radius: 6px;
  }

  /* Breadcrumb: allow wrapping */
  .breadcrumb {
    font-size: 0.72rem;
    line-height: 1.6;
    word-break: break-word;
  }

  /* Table cells tighter */
  th,
  td {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
  }

  /* Disable hover transforms on touch (no hover state) */
  .doc-list a:hover {
    transform: none;
  }

  /* Reduce background effects for performance */
  body::before {
    animation: none;
  }

  body::after {
    display: none;
  }
}

/* --- Print ------------------------------------------------- */
@media print {
  body {
    background: #fff;
    color: #000;
  }

  body::before,
  body::after {
    display: none;
  }

  .site-header,
  .theme-toggle,
  .site-footer {
    display: none;
  }

  .doc-container {
    max-width: 100%;
    padding: 0;
  }

  h1 {
    -webkit-text-fill-color: initial;
    background: none;
  }
}

/* --- Reduced motion --------------------------------------- */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}