/* Harugalpi v2 Unified Stylesheet
   - Preserves DESIGN.md tokens, Gowun Batang Regular (@font-face), 44px touch targets
   - Fixes WCAG 2.1 AA 1.4.11 control border contrast (>= 3:1 via --border-control)
   - Fixes mobile 2-row header grid, responsive phone/monitor device icon, disclosure chevron, hover/active states */

@font-face {
  font-family: "Gowun Batang";
  src: url("/assets/reader-body.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #F8F6F0;
  --surface: #EFECE4;
  --text: #303634;
  --muted: #526168;
  --link: #344E5A;
  --line: rgba(48, 54, 52, 0.14);
  --border-control: #748085; /* >= 3.8:1 contrast against #F8F6F0 (WCAG 1.4.11 AA) */
  --btn: #E4EBED;
  --btn-hover: #D5E0E4;
  --btn-text: #303634;
  --focus: #4C6875;
  --art-filter: none;
  --radius: 6px;
  --font-serif: "Gowun Batang", "Batang", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #303638;
    --surface: #3A4245;
    --text: #EEEAE1;
    --muted: #C1C9C9;
    --link: #C4DDE4;
    --line: rgba(238, 234, 225, 0.16);
    --border-control: #8D9A9F; /* >= 3.6:1 contrast against #303638 */
    --btn: #4A5D66;
    --btn-hover: #586E78;
    --btn-text: #EEEAE1;
    --focus: #B4D4E0;
    --art-filter: brightness(0.86) saturate(0.92);
  }
}

:root[data-theme="dark"] {
  --bg: #303638;
  --surface: #3A4245;
  --text: #EEEAE1;
  --muted: #C1C9C9;
  --link: #C4DDE4;
  --line: rgba(238, 234, 225, 0.16);
  --border-control: #8D9A9F;
  --btn: #4A5D66;
  --btn-hover: #586E78;
  --btn-text: #EEEAE1;
  --focus: #B4D4E0;
  --art-filter: brightness(0.86) saturate(0.92);
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); font-family: var(--font-serif); }
body {
  margin: 0 auto;
  max-width: 1120px;
  padding: 1rem 1.25rem 3.5rem;
  line-height: 1.85;
}

a { color: var(--link); text-underline-offset: 0.2em; }
a:hover { opacity: 0.85; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: var(--radius); }

.hg-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

.hg-skip-link {
  position: absolute; left: -9999px; top: 0.5rem;
  background: var(--btn); color: var(--btn-text);
  padding: 0.6rem 1rem; border-radius: var(--radius); text-decoration: none; z-index: 100;
}
.hg-skip-link:focus { left: 1rem; }

/* Responsive Header Grid: Row 1 always keeps Brand <-> Controls on mobile; Desktop puts Tagline inline */
.hg-header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "brand controls"
    "tagline tagline";
  align-items: center;
  column-gap: 1rem;
  row-gap: 0.2rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line);
}
@media (min-width: 860px) {
  .hg-header {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "brand tagline controls";
    row-gap: 0;
  }
}
.hg-brand {
  grid-area: brand;
  font-size: 1.3rem; color: var(--text); text-decoration: none;
  min-height: 44px; display: inline-flex; align-items: center;
}
.hg-tagline { grid-area: tagline; margin: 0; font-size: 0.9rem; color: var(--muted); }
.hg-controls { grid-area: controls; display: flex; align-items: center; gap: 0.35rem; }
.hg-account-link {
  min-height: 44px; padding: 0 0.55rem; display: inline-flex; align-items: center;
  text-decoration: none; font-size: 0.92rem; color: var(--muted);
}
.hg-account-link:hover { color: var(--text); text-decoration: underline; }

.hg-theme-group { display: inline-flex; align-items: center; gap: 0.1rem; }
.hg-theme-group button {
  width: 44px; height: 44px; border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.hg-theme-group button:hover { color: var(--text); }
.hg-theme-group svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.hg-theme-group [aria-pressed="true"] {
  color: var(--text); background: var(--btn); border-color: var(--border-control);
}
.hg-icon-desktop { display: none; }
@media (min-width: 1024px) {
  .hg-icon-phone { display: none; }
  .hg-icon-desktop { display: block; }
}

/* Entry Layout */
.hg-entry { padding-top: 1.8rem; }
.hg-back-home { margin: 0 0 0.6rem; font-size: 0.92rem; }
.hg-back-home a { min-height: 44px; display: inline-flex; align-items: center; text-decoration: none; }
.hg-date { margin: 0 0 0.45rem; font-size: 17px; color: var(--muted); }
.hg-title { margin: 0 0 1.5rem; font-size: clamp(1.75rem, 3.2vw, 2.25rem); font-weight: 400; line-height: 1.35; }
.hg-entry-grid { display: grid; grid-template-columns: 1fr; gap: 2rem; align-items: start; }
@media (min-width: 960px) {
  .hg-entry-grid { grid-template-columns: 1.05fr 1fr; gap: 3rem; }
}
.hg-art { display: block; width: 100%; height: auto; border-radius: var(--radius); filter: var(--art-filter); }
.hg-reading { font-size: 1.25rem; line-height: 1.95; max-width: 38ch; }
.hg-reading p { margin: 0 0 1rem; }

/* Single Companion Disclosure with Visible Custom Chevron */
.hg-disclosure {
  margin: 1.25rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.hg-disclosure summary {
  list-style: none;
  cursor: pointer; min-height: 44px; padding: 0.35rem 0;
  display: flex; align-items: center; gap: 0.5rem;
  color: var(--text); font-size: 0.98rem;
}
.hg-disclosure summary::-webkit-details-marker { display: none; }
.hg-chevron {
  width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7;
  flex-shrink: 0; transition: transform 150ms ease;
}
.hg-disclosure[open] .hg-chevron { transform: rotate(180deg); }
.hg-disclosure-body { padding: 0.25rem 0 1rem; }
.hg-companion-reason { margin: 0 0 0.65rem; font-size: 0.94rem; color: var(--muted); }
.hg-poem { margin: 0.6rem 0; padding-left: 1rem; border-left: 2px solid var(--border-control); }
.hg-credit { margin: 0.5rem 0 0; font-size: 0.86rem; color: var(--muted); }

/* Optional Quiet Reflection Prompt */
.hg-pause-card {
  margin: 1.25rem 0; padding: 0.95rem 1.1rem;
  background: var(--surface); border-radius: var(--radius);
}
.hg-pause-prompt { margin: 0 0 0.5rem; font-size: 0.98rem; }
.hg-text-btn {
  min-height: 44px; padding: 0 0.25rem; background: transparent; border: 0;
  color: var(--link); font: inherit; font-size: 0.9rem; text-decoration: underline; cursor: pointer;
}
.hg-pause-status { display: block; font-size: 0.88rem; color: var(--muted); }

/* Unified Action Row (DESIGN.md: Empathy + Write) */
.hg-write-block { margin: 1.5rem 0 1.25rem; }
.hg-question { margin: 0 0 0.65rem; font-size: 1rem; color: var(--text); }
.hg-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: center; }
.hg-btn-primary, .hg-btn-subtle, .hg-chip {
  min-height: 44px; padding: 0 1rem; border-radius: var(--radius);
  font: inherit; font-size: 0.95rem; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
}
.hg-btn-primary {
  background: var(--btn); color: var(--btn-text);
  border: 1px solid var(--border-control);
}
.hg-btn-primary:hover { background: var(--btn-hover); opacity: 1; }
.hg-btn-subtle {
  background: transparent; color: var(--text);
  border: 1px solid var(--border-control);
}
.hg-btn-subtle:hover { background: var(--surface); opacity: 1; }
.hg-btn-subtle[aria-pressed="true"], .hg-chip[aria-pressed="true"] {
  background: var(--btn); color: var(--btn-text); border-color: var(--focus);
}
.hg-bookmark-icon { width: 15px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.hg-btn-subtle[aria-pressed="true"] .hg-bookmark-icon { fill: currentColor; }
.hg-write-hint { margin: 0.5rem 0 0; font-size: 0.88rem; color: var(--muted); }
.hg-inline-link { margin-left: 0.5rem; font-size: 0.84rem; }
.hg-evergreen-badge { margin: 1rem 0; font-size: 0.9rem; color: var(--muted); }

/* Light 1-Line Wallpaper Links (Lower visual weight than primary actions) */
.hg-downloads { margin-top: 1.2rem; padding-top: 0.9rem; border-top: 1px solid var(--line); }
.hg-download-label { font-size: 0.88rem; color: var(--muted); margin-right: 0.75rem; }
.hg-download-links { display: inline-flex; flex-wrap: wrap; gap: 0.9rem; align-items: center; }
.hg-download-links a { min-height: 44px; display: inline-flex; align-items: center; font-size: 0.92rem; }
.hg-save-status { margin: 0.25rem 0 0; font-size: 0.86rem; color: var(--muted); }

/* Related Past Entry Section (Clean, no chips cluttering Home) */
.hg-related { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--line); }
.hg-related-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.hg-related-head h2 { margin: 0; font-size: 1.15rem; font-weight: 400; }
.hg-more-link { min-height: 44px; display: inline-flex; align-items: center; font-size: 0.92rem; text-decoration: none; }
.hg-rec-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 760px) { .hg-rec-grid { grid-template-columns: 1fr 1fr; } }
.hg-rec-card {
  display: flex; gap: 1rem; align-items: center; padding: 0.95rem;
  background: var(--surface); border: 1px solid transparent; border-radius: var(--radius);
  text-decoration: none; color: var(--text); min-height: 92px;
}
.hg-rec-card:hover { border-color: var(--border-control); opacity: 1; }
.hg-rec-card img { width: 108px; height: 72px; object-fit: cover; border-radius: var(--radius); flex-shrink: 0; filter: var(--art-filter); }
.hg-rec-copy strong { display: block; font-size: 1.05rem; font-weight: 400; margin-bottom: 0.15rem; }
.hg-rec-copy p { margin: 0; font-size: 0.9rem; color: var(--muted); }

.hg-day-nav {
  margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.hg-day-nav a { min-height: 44px; display: inline-flex; align-items: center; text-decoration: none; font-size: 0.94rem; }

/* Archive */
.hg-archive-head { padding: 1.8rem 0 1rem; }
.hg-archive-head h1 { margin: 0 0 0.4rem; font-weight: 400; }
.hg-archive-desc { color: var(--muted); margin: 0 0 1rem; }
.hg-chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.hg-chip { background: transparent; color: var(--muted); border: 1px solid var(--border-control); padding: 0 0.85rem; }
.hg-search-bar { margin-top: 1rem; }
.hg-search-bar input {
  width: 100%; max-width: 420px; min-height: 44px; padding: 0.5rem 0.9rem;
  font: inherit; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-control); border-radius: var(--radius);
}
.hg-archive-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.75rem; }
.hg-archive-row {
  display: flex; gap: 1rem; align-items: center; padding: 0.95rem;
  background: var(--surface); border: 1px solid transparent; border-radius: var(--radius);
  text-decoration: none; color: var(--text);
}
.hg-archive-row:hover { border-color: var(--border-control); opacity: 1; }
.hg-archive-row img { width: 120px; height: 80px; object-fit: cover; border-radius: var(--radius); flex-shrink: 0; filter: var(--art-filter); }
.hg-archive-date { font-size: 0.85rem; color: var(--muted); display: block; }
.hg-archive-title { margin: 0.1rem 0; font-size: 1.1rem; font-weight: 400; }
.hg-archive-copy p { margin: 0; font-size: 0.92rem; color: var(--muted); }
.hg-empty { color: var(--muted); padding: 1.5rem 0; }

/* Status & Admin */
.hg-status-page { padding: 3rem 0; max-width: 680px; }
.hg-status-page h1 { font-weight: 400; }
.hg-admin { padding-top: 1.8rem; }
.hg-caution { padding: 0.85rem 1rem; background: var(--surface); border-left: 3px solid var(--focus); border-radius: var(--radius); font-size: 0.92rem; }
.hg-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 0.9rem; margin: 1.5rem 0 2rem; }
.hg-kpi { background: var(--surface); padding: 1rem; border-radius: var(--radius); }
.hg-kpi span { display: block; font-size: 0.85rem; color: var(--muted); }
.hg-kpi strong { font-size: 1.55rem; font-weight: 400; }
.hg-table-wrap { overflow-x: auto; margin-bottom: 2rem; }
.hg-table { width: 100%; border-collapse: collapse; min-width: 480px; }
.hg-table th, .hg-table td { text-align: left; padding: 0.65rem; border-bottom: 1px solid var(--line); }
.hg-hint-list { padding-left: 1.2rem; }

/* Footer */
.hg-footer { margin-top: 3.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); display: grid; gap: 0.45rem; }
.hg-footer-nav, .hg-footer-sub { display: flex; flex-wrap: wrap; gap: 1.2rem; }
.hg-footer-nav a, .hg-footer-sub a {
  min-height: 44px; display: inline-flex; align-items: center; text-decoration: none;
  font-size: 0.92rem; color: var(--muted);
}
.hg-footer-nav a[aria-current="page"] { color: var(--text); text-decoration: underline; }
.hg-footer-sub a { font-size: 0.84rem; }
.hg-reaction-notice, .hg-admin-note { margin: 0.4rem 0 0; font-size: 0.82rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
