/**
 * hudayi.space — Editorial Monograph Stylesheet
 * Hand-crafted, quiet, independent magazine aesthetic.
 * Strict compliance:
 * - No gradients, no drop shadows, no glassmorphism, no neon, no pastels.
 * - Ground: warm paper (#F6F4EE) or warm dark (#14130F).
 * - Single corner radius: 2px across everything.
 * - Fonts: Newsreader (headings) + Public Sans (body) + JetBrains Mono (data).
 * - No hover lifting or scaling.
 */

@import './tokens.css';

:root {
  /* Palette aliases mapped to canonical tokens */
  --ground:          var(--hudayi-ground);
  --ground-sunken:   var(--hudayi-ground-sunken);
  --ground-raised:   var(--hudayi-ground-raised);
  --text:            var(--hudayi-text);
  --text-muted:      var(--hudayi-text-muted);
  --text-dim:        var(--hudayi-text-dim);
  --accent:          var(--hudayi-accent);
  --accent-hover:    var(--hudayi-accent-hover);
  --rule:            var(--hudayi-rule);
  --rule-strong:     var(--hudayi-rule-strong);
  --focus-ring:      var(--hudayi-focus-ring);
  --skeleton:        var(--hudayi-skeleton);
  --success:         var(--hudayi-success);
  --warning:         var(--hudayi-warning);
  --danger:          var(--hudayi-danger);

  /* Typography */
  --font-serif: var(--hudayi-font-serif);
  --font-sans:  var(--hudayi-font-sans);
  --font-mono:  var(--hudayi-font-mono);

  /* Scale */
  --text-xs:   var(--hudayi-text-xs);
  --text-sm:   var(--hudayi-text-sm);
  --text-base: var(--hudayi-text-base);
  --text-md:   var(--hudayi-text-md);
  --text-lg:   var(--hudayi-text-lg);
  --text-xl:   var(--hudayi-text-xl);
  --text-2xl:  var(--hudayi-text-2xl);

  --lh-tight:  1.15;
  --lh-normal: 1.4;
  --lh-prose:  1.65;

  --reading-width: var(--hudayi-reading-width, 66ch);
  --container-width: var(--hudayi-container-width, 760px);
  --container-wide:  var(--hudayi-container-wide, 1200px);

  /* Universal Corner Radius: exactly 2px */
  --radius: var(--hudayi-radius, 2px);
}

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

html {
  font-family: var(--font-sans);
  background-color: var(--ground);
  color: var(--text);
  line-height: var(--lh-prose);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--ground);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ── Layout Containers ── */
.container {
  width: 100%;
  max-width: var(--container-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
}

.container-wide {
  width: 100%;
  max-width: var(--container-wide);
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
}

/* ── Top Masthead ── */
.masthead {
  border-bottom: 1px solid var(--rule);
  padding-top: 28px;
  padding-bottom: 18px;
}

.masthead-inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.masthead-brand {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.masthead-brand:hover {
  color: var(--accent);
}

.masthead-nav {
  display: flex;
  align-items: center;
  gap: 20px;
  list-style: none;
}

.masthead-nav a {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
}

.masthead-nav a:hover,
.masthead-nav a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ── Quiet Front Page Hero ── */
.front-intro {
  padding-top: 56px;
  padding-bottom: 40px;
  border-bottom: 1px solid var(--rule);
}

.front-meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

.front-title {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: 400;
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  margin-bottom: 24px;
}

.front-prose {
  font-size: var(--text-base);
  color: var(--text);
  max-width: var(--reading-width);
  margin-bottom: 16px;
}

.front-prose-secondary {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: var(--reading-width);
}

.front-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 24px;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
}

.front-links a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.front-links a:hover {
  color: var(--accent);
}

/* ── Table of Contents Index (The Five Areas) ── */
.toc-section {
  padding-top: 40px;
  padding-bottom: 56px;
}

.section-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

.toc-table {
  width: 100%;
  border-top: 1px solid var(--rule);
  list-style: none;
}

.toc-row {
  border-bottom: 1px solid var(--rule);
  padding: 18px 0;
}

.toc-entry {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: baseline;
  gap: 16px;
  text-decoration: none;
  color: inherit;
}

.toc-entry:hover .toc-entry-title {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.toc-entry-num {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-dim);
}

.toc-entry-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toc-entry-title {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  font-weight: 500;
  line-height: var(--lh-normal);
  color: var(--text);
}

.toc-entry-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: var(--lh-normal);
}

.toc-entry-tag {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Page Header in Area Pages ── */
.page-header {
  padding-top: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 40px;
}

.page-header-meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.page-header-title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 400;
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

.page-header-desc {
  font-size: var(--text-base);
  color: var(--text-muted);
  max-width: var(--reading-width);
}

/* ── Content Sections & Rows ── */
.content-section {
  margin-bottom: 48px;
}

.section-heading {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: 500;
  margin-bottom: 16px;
  color: var(--text);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
}

.prose-block {
  font-size: var(--text-base);
  color: var(--text);
  line-height: var(--lh-prose);
  max-width: var(--reading-width);
  margin-bottom: 24px;
}

.prose-block p {
  margin-bottom: 16px;
}

/* ── Working System Showcase Blocks ── */
.system-card {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background-color: var(--ground-raised);
  padding: 24px;
  margin-bottom: 28px;
}

.system-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.system-card-title {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}

.system-card-meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ── Code and Data Blocks (No fake window chrome) ── */
.code-block {
  background-color: var(--ground-sunken);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--text);
}

.code-block pre {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
}

/* ── Plain Forms (Auth & Query) ── */
.editorial-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 440px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.field-input,
.field-textarea {
  width: 100%;
  background-color: var(--ground-sunken);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text);
  outline: none;
}

.field-input:focus,
.field-textarea:focus {
  border-color: var(--focus-ring);
}

.field-input::placeholder {
  color: var(--text-dim);
}

/* ── Buttons (Sharp 2px radius, no pills, flat colors) ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  line-height: 1.2;
}

.btn-primary {
  background-color: var(--text);
  color: var(--ground);
  border-color: var(--text);
}

.btn-primary:hover {
  background-color: var(--accent);
  border-color: var(--accent);
}

.btn-secondary {
  background-color: transparent;
  color: var(--text);
  border-color: var(--rule-strong);
}

.btn-secondary:hover {
  border-color: var(--text);
}

.btn-accent {
  background-color: var(--accent);
  color: var(--hudayi-ground-raised);
  border-color: var(--accent);
}

.btn-accent:hover {
  background-color: var(--accent-hover);
}

/* ── Functional Feedback Notices ── */
.notice {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
  font-size: var(--text-sm);
  line-height: var(--lh-normal);
}

.notice-success {
  border-color: var(--success);
  background-color: var(--ground-sunken);
  color: var(--success);
}

.notice-error {
  border-color: var(--danger);
  background-color: var(--ground-sunken);
  color: var(--danger);
}

.notice-info {
  border-color: var(--rule-strong);
  background-color: var(--ground-sunken);
  color: var(--text);
}

/* ── Skeletons (Plain grey blocks, zero shimmer wave) ── */
.skeleton-block {
  background-color: var(--skeleton);
  border-radius: var(--radius);
  display: block;
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  background-color: var(--skeleton);
  border-radius: var(--radius);
}

.skeleton-text-short {
  width: 45%;
}

.skeleton-text-long {
  width: 85%;
}

/* ── Empty and Error States ── */
.state-empty,
.state-error {
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  margin-bottom: 24px;
}

.state-empty-title,
.state-error-title {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  margin-bottom: 8px;
  color: var(--text);
}

.state-empty-desc,
.state-error-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 460px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Data Tables ── */
.editorial-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin-bottom: 24px;
  text-align: left;
}

.editorial-table th {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule-strong);
}

.editorial-table td {
  padding: 12px;
  border-bottom: 1px solid var(--rule);
  color: var(--text);
  vertical-align: top;
}

.editorial-table tr:hover td {
  background-color: var(--ground-sunken);
}

/* ── Colophon / Footer ── */
.colophon {
  margin-top: auto;
  border-top: 1px solid var(--rule);
  padding-top: 36px;
  padding-bottom: 48px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.colophon-inner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 24px;
}

.colophon-creds {
  max-width: 420px;
  line-height: var(--lh-normal);
}

.colophon-creds p {
  margin-bottom: 8px;
}

.colophon-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  list-style: none;
}

.colophon-links a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.colophon-links a:hover {
  color: var(--text);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .front-title {
    font-size: var(--text-xl);
  }
  .toc-entry {
    grid-template-columns: 32px 1fr;
  }
  .toc-entry-tag {
    grid-column: 2 / 3;
  }
  .masthead-inner {
    flex-direction: column;
    align-items: flex-start;
  }
  .masthead-nav {
    flex-wrap: wrap;
    gap: 12px;
  }
}

.page-not-found {
  padding-top: var(--hudayi-space-2xl, 64px);
  padding-bottom: var(--hudayi-space-2xl, 64px);
  max-width: var(--reading-width, 66ch);
}

.page-not-found-actions {
  margin-top: var(--hudayi-space-lg, 24px);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
