/* ==========================================================================
   GraphonoMath — Editorial Master Stylesheet
   Balanced Scholarly Aesthetic with Dual-Theme (Light / Dark) & Accessibility
   ========================================================================== */

:root {
  /* Default: Warm Editorial Light Theme */
  --bg-base: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-surface-hover: #e2e8f0;
  
  --border-subtle: #e2e8f0;
  --border-medium: #cbd5e1;
  --border-focus: #0284c7;
  
  --text-main: #0f172a;
  --text-heading: #0f172a;
  --text-muted: #475569;
  --text-faint: #64748b;
  
  --accent-primary: #0284c7;
  --accent-primary-hover: #0369a1;
  --accent-amber: #d97706;
  --accent-glow: rgba(2, 132, 199, 0.12);
  
  --card-shadow: 0 2px 10px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.02);
  --card-shadow-hover: 0 12px 28px rgba(0, 0, 0, 0.08), 0 4px 10px rgba(0, 0, 0, 0.03);
  
  --font-serif: "Newsreader", "Charis SIL", "Georgia", "Cambria", serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;
  --font-glyphs: "Noto Sans", "Noto Serif", "Segoe UI Historic", "Segoe UI Symbol", sans-serif;

  --user-scale: 1; /* Scaled dynamically by A- and A+ controls */
}

/* Balanced Dark Mode (Slate / Twilight, NOT pitch black) */
[data-theme="dark"] {
  --bg-base: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-elevated: #273549;
  --bg-surface-hover: #334155;
  
  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-medium: rgba(255, 255, 255, 0.18);
  --border-focus: #38bdf8;
  
  --text-main: #f8fafc;
  --text-heading: #ffffff;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  
  --accent-primary: #38bdf8;
  --accent-primary-hover: #7dd3fc;
  --accent-amber: #f59e0b;
  --accent-glow: rgba(56, 189, 248, 0.16);
  
  --card-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  --card-shadow-hover: 0 12px 30px rgba(0, 0, 0, 0.45);
}

/* Accessibility: Screen Reader Only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Accessibility: Skip to Content */
.skip-link {
  position: absolute;
  top: -60px;
  left: 20px;
  background: var(--accent-primary);
  color: #fff;
  padding: 10px 18px;
  font-weight: 700;
  border-radius: 6px;
  z-index: 9999;
  transition: top 0.2s ease;
  text-decoration: none;
}
.skip-link:focus {
  top: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.68;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}

:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color 0.15s ease, opacity 0.15s ease;
}
a:hover {
  color: var(--accent-primary-hover);
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
  width: 100%;
}

/* Header & Site Navigation */
header.site-header {
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 74px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
}

.brand-glyph {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-primary), #0369a1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
  font-family: var(--font-glyphs);
  box-shadow: 0 2px 10px var(--accent-glow);
}

.brand-text h1 {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-heading);
}

.brand-text span {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  display: block;
}

nav.nav-links {
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav-link {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  transition: color 0.15s ease;
}
.nav-link:hover {
  color: var(--text-heading);
}

/* Theme Toggle Button */
.theme-toggle-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  border-radius: 20px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
  color: var(--text-main);
}
.theme-toggle-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

/* User Profile Badge */
.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-name {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-surface-elevated);
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-subtle);
}

/* Universal Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-primary-hover);
  color: #fff;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-medium);
}
.btn-secondary:hover {
  background: var(--bg-surface-hover);
  color: var(--text-heading);
}

.btn-danger {
  background: #dc2626;
  color: #fff;
}
.btn-danger:hover {
  background: #b91c1c;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 6px;
}

/* Universal Card */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 26px;
  box-shadow: var(--card-shadow);
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

/* Form Controls */
.form-group {
  margin-bottom: 20px;
  width: 100%;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 7px;
}

.form-control {
  width: 100%;
  display: block;
  padding: 11px 15px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea.form-control {
  font-family: var(--font-mono);
  font-size: 13px;
  min-height: 250px;
  line-height: 1.6;
  resize: vertical;
}

/* Auth Pages (Login & Register) - Perfectly Centered & Aligned */
.auth-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 280px);
  padding: 40px 16px;
  width: 100%;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.auth-card form {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.auth-card .form-group {
  width: 100%;
  margin-bottom: 20px;
  text-align: left;
}

.auth-card .form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 8px;
  text-align: left;
}

.auth-card .form-control {
  width: 100% !important;
  box-sizing: border-box !important;
  display: block;
  padding: 13px 16px;
  background-color: var(--bg-surface-elevated);
  border: 1.5px solid var(--border-medium);
  border-radius: 10px;
  color: var(--text-main);
  font-size: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.auth-card .form-control::placeholder {
  color: var(--text-faint);
  opacity: 0.75;
}

.auth-card .form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  background-color: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.auth-header {
  text-align: center;
  margin-bottom: 26px;
}

.auth-glyph {
  font-size: 42px;
  color: var(--accent-primary);
  margin-bottom: 8px;
  font-family: var(--font-glyphs);
}

.auth-header h2 {
  font-size: 23px;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.3px;
}

.auth-header p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

.auth-btn-full {
  width: 100% !important;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 10px;
  margin-top: 6px;
}

/* Flash Messages */
.flash-messages {
  margin: 20px 0;
}
.flash {
  padding: 13px 18px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.flash.success { background: rgba(16, 185, 129, 0.12); color: #059669; border: 1px solid rgba(16, 185, 129, 0.3); }
.flash.error { background: rgba(239, 68, 68, 0.12); color: #dc2626; border: 1px solid rgba(239, 68, 68, 0.3); }
.flash.info { background: rgba(2, 132, 199, 0.12); color: #0284c7; border: 1px solid rgba(2, 132, 199, 0.3); }

/* AdSense Slot */
.adsense-slot {
  margin: 28px auto;
  text-align: center;
  background: var(--bg-surface-elevated);
  border: 1px dashed var(--border-medium);
  padding: 16px;
  border-radius: 8px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Hero Section */
.hero-section {
  padding: 50px 0 32px;
  text-align: center;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 36px;
}

.hero-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent-primary);
  background: rgba(2, 132, 199, 0.1);
  border: 1px solid rgba(2, 132, 199, 0.25);
  padding: 4px 14px;
  border-radius: 20px;
  margin-bottom: 16px;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1.18;
  margin-bottom: 14px;
  color: var(--text-heading);
}

.hero-subtitle {
  font-size: 17px;
  color: var(--text-muted);
  max-width: 720px;
  margin: 0 auto;
  line-height: 1.6;
}

/* Category Filters */
.category-bar {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 14px;
  margin-bottom: 32px;
}

.category-chip {
  padding: 7px 16px;
  border-radius: 20px;
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-medium);
  white-space: nowrap;
  transition: all 0.15s ease;
}

.category-chip.active, .category-chip:hover {
  background: var(--accent-primary);
  color: #fff;
  font-weight: 600;
  border-color: var(--accent-primary);
}

/* Articles Grid */
.articles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 26px;
  margin-bottom: 70px;
}

.article-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--card-shadow);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease, border-color 0.25s ease;
}

.article-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-medium);
  box-shadow: var(--card-shadow-hover);
}

.card-image-link {
  display: block;
  overflow: hidden;
  height: 190px;
  background: var(--bg-surface-elevated);
}

.card-cover-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}
.article-card:hover .card-cover-image {
  transform: scale(1.03);
}

.card-header-glyph {
  height: 120px;
  background: linear-gradient(135deg, var(--bg-surface-elevated), var(--bg-surface));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 54px;
  color: var(--accent-primary);
  font-family: var(--font-glyphs);
  border-bottom: 1px solid var(--border-subtle);
}

.card-body {
  padding: 22px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 10px;
}

.card-category {
  color: var(--accent-primary);
  font-weight: 600;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 600;
  line-height: 1.32;
  margin-bottom: 12px;
}
.card-title a {
  color: var(--text-heading);
}
.card-title a:hover {
  color: var(--accent-primary);
}

.card-excerpt {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 16px;
  flex: 1;
}

/* Card Tags */
.card-tags-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tag-badge-sm {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(2, 132, 199, 0.08);
  color: var(--accent-primary);
  border: 1px solid rgba(2, 132, 199, 0.2);
  transition: all 0.15s ease;
}
.tag-badge-sm:hover {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-subtle);
  padding-top: 14px;
  font-size: 12px;
  color: var(--text-faint);
}

/* ==========================================================================
   Article Detail View Page
   ========================================================================== */
.article-full {
  max-width: 820px;
  margin: 32px auto 80px;
}

.article-header {
  text-align: center;
  margin-bottom: 36px;
}

.article-hero-media {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 24px;
  box-shadow: var(--card-shadow);
  background: var(--bg-surface-elevated);
}

.article-featured-image {
  width: 100%;
  max-height: 480px;
  object-fit: cover;
  display: block;
}

.article-glyph-large {
  font-size: 64px;
  color: var(--accent-primary);
  margin-bottom: 12px;
  font-family: var(--font-glyphs);
}

.article-title-main {
  font-family: var(--font-serif);
  font-size: 40px;
  font-weight: 700;
  line-height: 1.22;
  margin-bottom: 16px;
  color: var(--text-heading);
  letter-spacing: -0.5px;
}

.article-meta-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 13px;
  color: var(--text-faint);
  flex-wrap: wrap;
}

/* Minimalist Controls Toolbar Directly Under Title */
.article-compact-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.compact-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: 20px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.compact-btn:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: translateY(-1px);
}

.audio-toggle-btn {
  min-width: 95px;
  justify-content: center;
}

.audio-toggle-btn.playing {
  border-color: var(--accent-primary);
  background: rgba(2, 132, 199, 0.12);
  color: var(--accent-primary);
}

.font-scaler-group {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: 20px;
  padding: 2px 4px;
}

.font-step-btn {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 16px;
  color: var(--text-muted);
}
.font-step-btn:hover {
  background: var(--bg-surface-elevated);
  color: var(--accent-primary);
  transform: none;
}

.font-scale-indicator {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-primary);
  padding: 0 4px;
  min-width: 44px;
  text-align: center;
  user-select: none;
}

/* Scalable Article Typography */
.article-content {
  font-family: var(--font-serif);
  font-size: calc(19px * var(--user-scale));
  line-height: 1.84;
  color: var(--text-main);
  transition: font-size 0.2s ease;
}

.article-content h2 {
  font-family: var(--font-sans);
  font-size: calc(26px * var(--user-scale));
  font-weight: 700;
  color: var(--text-heading);
  margin: 44px 0 18px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 10px;
  letter-spacing: -0.3px;
}

.article-content h3 {
  font-family: var(--font-sans);
  font-size: calc(21px * var(--user-scale));
  font-weight: 600;
  color: var(--text-heading);
  margin: 32px 0 14px;
}

.article-content p {
  margin-bottom: 24px;
}

.article-content ul, .article-content ol {
  margin: 0 0 26px 30px;
}
.article-content li {
  margin-bottom: 10px;
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 32px 0;
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg-surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--card-shadow);
}

.article-content th, .article-content td {
  padding: 12px 16px;
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.article-content th {
  background: var(--bg-surface-elevated);
  color: var(--text-heading);
  font-weight: 600;
}

.article-content code {
  font-family: var(--font-mono);
  background: var(--bg-surface-elevated);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--accent-primary);
  border: 1px solid var(--border-subtle);
}

/* Article Tags Section Below Content */
.article-tags-section {
  margin-top: 40px;
  padding: 18px 22px;
  background: var(--bg-surface-elevated);
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.tags-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-heading);
}

.tags-cloud {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag-badge {
  font-size: 13px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 16px;
  background: var(--bg-surface);
  color: var(--accent-primary);
  border: 1px solid var(--border-medium);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: all 0.15s ease;
}
.tag-badge:hover {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

/* Comments Section */
.comments-section {
  max-width: 820px;
  margin: 60px auto;
  border-top: 1px solid var(--border-subtle);
  padding-top: 40px;
}

.comments-title {
  font-size: 23px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text-heading);
}

.comment-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 18px 22px;
  margin-bottom: 18px;
  box-shadow: var(--card-shadow);
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.comment-author {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-heading);
}

.comment-date {
  font-size: 12px;
  color: var(--text-faint);
}

.comment-body {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
}

.comment-footer {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.comment-form textarea {
  width: 100%;
  padding: 14px;
  border-radius: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  resize: vertical;
  min-height: 110px;
  margin-bottom: 14px;
}

.comment-form textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Site Footer */
footer.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  padding: 36px 0;
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
  transition: background-color 0.25s ease;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.footer-links a {
  color: var(--text-muted);
  font-size: 12px;
}
.footer-links a:hover {
  color: var(--accent-primary);
}

/* Responsive */
@media (max-width: 768px) {
  .hero-title {
    font-size: 30px;
  }
  .article-title-main {
    font-size: 28px;
  }
  .header-inner {
    height: auto;
    padding: 14px 0;
    flex-wrap: wrap;
    gap: 12px;
  }
}
