/*
  Shared design system for rubaiai.dev — console/technical aesthetic.
  Loaded by index.php and blog.php (footer.php has its own small block).
  Token names intentionally mirror a plain --bg/--surface/--border/--accent
  convention so future pages can reuse the same variables.
*/

/*
  Text and functional-control token pairs below were checked against WCAG 2.2
  AA contrast math (the decorative layout divider is intentionally subtler):
  - text tokens: >=4.5:1 against the surface/bg they're actually used on
  - border/border-strong: >=3:1 against the surface they outline (1.4.11
    non-text contrast for functional UI boundaries — inputs, buttons)
  See /scratchpad contrast audit from the accessibility pass for the numbers.
*/
:root {
  --bg: #ffffff;
  --sidebar-bg: #f5f6f8;
  --layout-divider: #d9dde3;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #888e98;
  --border-strong: #82868e;
  --text: #0a0c10;
  --text-dim: #333a46;
  --muted: #586170;
  --accent: #0e7490;
  --accent-strong: #0a5468;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #a16207;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  /* Tailwind color-scale stops that need a different value per color scheme
     (a single hex cannot pass 4.5:1 as both light-on-white and light-on-black
     text at once) — tailwind.config in index.php/blog.php points slate.400
     and slate.500 at these. */
  --slate-400: #586170;
  --slate-500: #626873;
}

.dark {
  --bg: #12151b;
  --sidebar-bg: #0a0c10;
  --layout-divider: #2a2f38;
  --surface: #12151b;
  --surface-2: #171b22;
  --border: #5e6674;
  --border-strong: #686c74;
  --text: #e6e8eb;
  --text-dim: #b7bec9;
  --muted: #7d8590;
  --accent: #22d3ee;
  --accent-strong: #67e8f9;
  --accent-contrast: #04141a;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #facc15;
  --slate-400: #7d8590;
  --slate-500: #8b93a0;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Global resets: sharp edges, no shadows, no glass blur ---------- */
[class*="rounded"] {
  border-radius: 0 !important;
}

[class*="shadow"] {
  box-shadow: none !important;
}

.backdrop-blur,
.backdrop-blur-sm,
.backdrop-blur-md {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

header.fixed {
  background: var(--bg) !important;
  border-bottom-color: var(--layout-divider) !important;
}

/* ---------- Header brand mark ---------- */
.rubaiai-mark {
  --mark-scroll-rotation: 0deg;
  flex: none;
  rotate: var(--mark-scroll-rotation);
  transform-origin: center;
  transition: transform 450ms ease-in-out;
}

.rubaiai-brand:hover .rubaiai-mark,
.rubaiai-brand:focus-visible .rubaiai-mark {
  transform: rotate(22.5deg) scale(1.06);
}

@media (prefers-reduced-motion: reduce) {
  .rubaiai-mark {
    rotate: none !important;
    transition: none !important;
  }

  .rubaiai-brand:hover .rubaiai-mark,
  .rubaiai-brand:focus-visible .rubaiai-mark {
    transform: none;
  }
}

/* ---------- Two-tone application shell ----------
   Keep the content canvas neutral while giving the persistent navigation and
   its mobile-drawer form a subtly darker technical-console surface. The
   divider remains present so the regions are not distinguished by color alone. */
body,
#main-content {
  background: var(--bg) !important;
}

#sidebar {
  background: var(--sidebar-bg) !important;
  border-right-color: var(--layout-divider) !important;
}

#sidebar > div > :first-child {
  border-bottom-color: var(--layout-divider) !important;
}

#sidebar > div > :last-child {
  border-top-color: var(--layout-divider) !important;
}

/* ---------- Visible focus (WCAG 2.4.7 / 2.4.11) ----------
   Only shows for keyboard focus (:focus-visible), not mouse clicks, so it
   doesn't add visual noise for pointer users while staying reliable for
   keyboard users. A 2px solid accent outline, offset so it never touches
   the button/input's own border — no glow, no blur, matches the console
   aesthetic. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent) !important;
  outline-offset: 2px !important;
  box-shadow: none !important;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  border-color: var(--accent) !important;
}

/* Modal panels lose their shadow above — give them a border instead */
#postModal > div,
#deleteModal > div,
#shareModal > div {
  border: 1px solid var(--border);
}

/* ---------- Touch targets (WCAG 2.5.8 — 24x24 CSS px minimum) ---------- */
#menuBtn,
#themeToggle,
#backToTop,
#newPostBtn,
#homeLink,
.post-actions button,
[data-close-modal] {
  min-width: 24px;
  min-height: 24px;
}

/* ---------- Base layout helpers ---------- */
html {
  scroll-padding-top: 5rem;
}

.spy-section,
section[id^="post-"] {
  scroll-margin-top: 5rem;
}

/* ---------- Long-form article typography ---------- */
.article-body {
  font-size: 1rem;
  line-height: 1.75;
}

.article-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.article-body p {
  margin: 0 0 1rem;
}

.article-body h2 {
  font-size: 1.375rem;
  font-weight: 700;
  margin: 1.6rem 0 .6rem;
}

.article-body h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 1.4rem 0 .5rem;
}

.article-body ul {
  list-style: disc;
  padding-left: 1.5rem;
  margin: 0 0 1rem;
}

.article-body ol {
  list-style: decimal;
  padding-left: 1.5rem;
  margin: 0 0 1rem;
}

.article-body li {
  margin: .25rem 0;
}

.article-body blockquote {
  border-left: 3px solid var(--border-strong);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--muted);
  font-style: italic;
}

.article-body strong {
  font-weight: 700;
}

.article-body em {
  font-style: italic;
}

/* ---------- Callout boxes (info / note / warning) ---------- */
.callout {
  border: 1px solid;
  border-left-width: 3px;
  padding: .85rem 1rem;
  margin: 1.1rem 0;
  display: flex;
  gap: .6rem;
  font-size: .95rem;
  background: var(--surface);
}

.callout i {
  font-size: 1.1rem;
  margin-top: .1rem;
}

.callout-info {
  border-color: var(--accent);
  color: var(--text);
}

.callout-note {
  border-color: var(--border-strong);
  color: var(--text);
}

.callout-warning {
  border-color: var(--warning);
  color: var(--text);
}

/* ---------- Code blocks + copy button (always terminal-dark, any theme) ---------- */
.article-body pre {
  position: relative;
  background: #12151b;
  color: #e6e8eb;
  border: 1px solid #232830;
  padding: 1rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: .85rem;
  line-height: 1.6;
  margin: 1.1rem 0;
}

.article-body :not(pre) > code {
  background: var(--surface-2);
  color: var(--accent);
  padding: .12em .4em;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: .88em;
}

.copy-code-btn {
  position: absolute;
  top: .5rem;
  right: .5rem;
  min-height: 24px;
  background: transparent;
  color: #b7bec9;
  border: 1px solid #333a46;
  padding: .35rem .6rem;
  font-family: var(--mono);
  font-size: .7rem;
  cursor: pointer;
}

.copy-code-btn:hover {
  border-color: #22d3ee;
  color: #22d3ee;
}

/* ---------- Tables inside article content ---------- */
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.1rem 0;
  font-size: .9rem;
}

.article-body th,
.article-body td {
  border: 1px solid var(--border);
  padding: .55rem .75rem;
  text-align: left;
}

.article-body th {
  background: var(--surface-2);
  font-weight: 600;
}

/* ---------- Image slideshow ---------- */
.slideshow-container {
  position: relative;
  margin: 1.25rem 0 .5rem;
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--surface-2);
}

.slide {
  display: none;
}

.slide.active {
  display: block;
}

.slide img {
  width: 100%;
  height: auto;
  display: block;
}

.slideshow-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(10, 12, 16, .6);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .25);
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.slideshow-nav:hover {
  background: rgba(10, 12, 16, .85);
}

.slideshow-nav.prev {
  left: .6rem;
}

.slideshow-nav.next {
  right: .6rem;
}

.image-counter {
  position: absolute;
  top: .6rem;
  right: .6rem;
  background: rgba(10, 12, 16, .7);
  color: #fff;
  padding: .15rem .55rem;
  font-family: var(--mono);
  font-size: .72rem;
  z-index: 2;
}

/* Pause/play control for auto-advancing slideshows (WCAG 2.2.2) */
.slideshow-pause {
  position: absolute;
  bottom: .6rem;
  left: .6rem;
  min-width: 24px;
  min-height: 24px;
  background: rgba(10, 12, 16, .7);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .25);
  cursor: pointer;
  font-size: .95rem;
  line-height: 1;
  z-index: 2;
}

.slideshow-pause:hover {
  background: rgba(10, 12, 16, .85);
}

.slideshow-dots {
  text-align: center;
  padding: .5rem 0;
}

.dot {
  display: inline-block;
  height: 6px;
  width: 6px;
  /* Padding expands the clickable/tappable area to ~24px (WCAG 2.5.8)
     while background-clip keeps the visible dot small. */
  padding: 9px;
  margin: 0;
  border: none;
  background: var(--border-strong);
  background-clip: content-box;
  -webkit-appearance: none;
  appearance: none;
  line-height: 0;
  font-size: 0;
  cursor: pointer;
  transition: background .2s;
}

.dot.active {
  background: var(--accent);
}

/* ---------- Table of contents active state ---------- */
.toc-link.active {
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
  background: var(--surface-2);
}

/* ---------- Scrollbar ---------- */
.sidebar-scroll::-webkit-scrollbar {
  width: 8px;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
}

/* ---------- Rich text editor (Quill) — admin post composer ---------- */
#editorToolbar {
  border: 1px solid var(--border-strong);
  border-bottom: 0;
  background: var(--surface-2);
}

#editor {
  min-height: 320px;
  max-height: 55vh;
  overflow-y: auto;
  font-size: 1rem;
  font-family: var(--mono);
  border: 1px solid var(--border-strong);
}

#editor .ql-editor {
  min-height: 320px;
}

.dark .ql-snow .ql-stroke {
  stroke: #b7bec9;
}

.dark .ql-snow .ql-fill {
  fill: #b7bec9;
}

.dark .ql-snow .ql-picker {
  color: #b7bec9;
}

.dark .ql-snow .ql-picker-options {
  background: #171b22;
}

/* ---------- Skip-to-content link ---------- */
.skip-link {
  position: absolute;
  top: -3rem;
  left: 1rem;
  z-index: 100;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: .6rem 1rem;
  font-family: var(--mono);
  font-size: .85rem;
  text-decoration: none;
  transition: top .15s ease;
}

.skip-link:focus {
  top: 1rem;
  outline: 2px solid var(--text) !important;
  outline-offset: 2px !important;
}

.dark .ql-editor.ql-blank::before {
  color: #7d8590;
}
