/* ================================
   ExamArchive – common.css
   Global foundation styles (STABLE)
   ================================ */

/* ================================
   THEME TOKENS (DEFAULT: LIGHT)
   ================================ */
:root {
  --red: #d32f2f;
  --red-soft: #fdeaea;

  --bg: #ffffff;
  --bg-soft: #f7f7f7;
  --surface: #ffffff;

  --text: #111111;
  --text-muted: #666666;

  --border: #e0e0e0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 10px rgba(0,0,0,0.08);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --max-width: 1100px;

  --night-filter-strength: 0;
}

/* ================================
   DARK THEME
   ================================ */
body[data-theme="dark"] {
  --bg: #121212;
  --bg-soft: #1e1e1e;
  --surface: #1a1a1a;

  --text: #eaeaea;
  --text-muted: #aaaaaa;
  --border: #2a2a2a;

  --red: #ff5252;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.5);
}

/* ================================
   AMOLED THEME
   ================================ */
body[data-theme="amoled"] {
  --bg: #000000;
  --bg-soft: #000000;
  --surface: #000000;

  --text: #ffffff;
  --text-muted: #bbbbbb;
  --border: #1a1a1a;

  --red: #ff5252;

  --shadow-sm: none;
  --shadow-md: none;
}

/* ================================
   NIGHT MODE – FILTER (SAFE)
   ================================ */
body {
  filter: none;
}

body[data-night="on"] {
  filter:
    sepia(calc(0.6 * var(--night-filter-strength)))
    saturate(calc(1.4 + var(--night-filter-strength)))
    brightness(calc(1 - (0.15 * var(--night-filter-strength))))
    hue-rotate(-12deg);
}

/* Background fix for night */
body[data-theme="light"][data-night="on"] {
  background-color: #f3efe6;
}

body[data-theme="dark"][data-night="on"],
body[data-theme="amoled"][data-night="on"] {
  background-color: var(--bg);
}

/* ================================
   NIGHT LAYER (NON-INTRUSIVE)
   ================================ */
#night-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: transparent;
}

/* ================================
   RESET (HORIZONTAL SAFETY)
   ================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden; /* 🔥 critical */
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden; /* 🔥 fixes mobile right-gap */
}

/* ================================
   BASE
   ================================ */
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

main {
  position: relative;
  z-index: 0;
}

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

a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

a:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ================================
   LAYOUT HELPERS
   ================================ */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem;
}

.section {
  margin: 1.5rem 0;
}

.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  min-height: calc(100vh - 200px);
}

/* ================================
   TYPOGRAPHY
   ================================ */
h1, h2, h3, h4 {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

p {
  margin: 0.5rem 0;
  color: var(--text-muted);
}

/* ================================
   CARDS
   ================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card + .card {
  margin-top: 1rem;
}

/* ================================
   UTILITIES
   ================================ */
.text-muted { color: var(--text-muted); }

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-col { display: flex; flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-wrap { flex-wrap: wrap; }

.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.gap-lg { gap: 1.5rem; }

.full-width { width: 100%; }
.text-center { text-align: center; }

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

.sr-only-focusable:focus {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 10000;
  padding: 0.75rem 1rem;
  background: var(--red);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: var(--shadow-md);
}

/* ================================
   BUTTONS (CANONICAL)
   ================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn:hover {
  background: var(--bg-soft);
}

.btn:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

.btn.btn-red {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.btn.btn-red:active {
  transform: scale(0.97);
}

/* ================================
   MEDIA QUERIES
   ================================ */
@media (max-width: 768px) {
  .container {
    padding: 0.75rem;
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }

  .btn,
  button,
  a[role="button"] {
    min-height: 44px;
    min-width: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
   }
