/* =========================================================
   HueForge 非公式日本語サイト
   Light (Editorial / B案) + Dark (Craftsman / A案) 統合版
   自動検出 + 右上トグル
   ========================================================= */

/* ---------- Palettes & font vars ---------- */
:root {
  /* Light palette (default) */
  --paper:        #f6f1e8;
  --paper-deep:   #ede6d6;
  --sumi:         #2a2520;
  --sumi-soft:    #5a5048;
  --accent:       #c8462f;         /* 朱赤 */
  --accent-d:     #a3361f;
  --accent-soft:  rgba(200, 70, 47, 0.3);
  --link:         var(--accent);
  --link-hover:   var(--accent-d);

  /* Surface tokens */
  --bg:           var(--paper);
  --bg-alt:       var(--paper-deep);
  --text:         var(--sumi);
  --text-soft:    var(--sumi-soft);
  --guard-bg:     rgba(246, 241, 232, 0.85);
  --guard-border: var(--accent);

  /* Hero video treatment */
  --video-filter: brightness(1.15) saturate(1.05) contrast(0.95);
  --hero-overlay: linear-gradient(180deg, rgba(246, 241, 232, 0.15) 0%, rgba(246, 241, 232, 0.40) 100%);
  --hero-vignette: radial-gradient(ellipse at center, rgba(246, 241, 232, 0.0) 0%, rgba(246, 241, 232, 0.25) 100%);

  /* Fonts */
  --font-display: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-body:    "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --font-label:   "Zen Kaku Gothic New", system-ui, sans-serif;

  /* hugo-scroll theme overrides */
  --section-light-bg-color:   var(--bg) !important;
  --section-light-text-color: var(--text) !important;
  --section-dark-bg-color:    var(--bg-alt) !important;
  --section-dark-text-color:  var(--text) !important;

  --highlight:                 var(--accent) !important;
  --highlight-contrast:        #fff !important;
  --highlight-inverse:         var(--sumi) !important;
  --highlight-inverse-contrast:#fff !important;

  --cover-text-color:                           var(--text) !important;
  --cover-title-text-shadow:                    none !important;
  --cover-title-and-description-guard-bg-color: var(--guard-bg) !important;
}

/* Dark palette: applied when explicit data-theme="dark" OR (no explicit setting AND OS prefers dark) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:           #1a1410;
    --bg-alt:       #12100d;
    --text:         #cfc4b3;
    --text-soft:    #8a8275;
    --accent:       #ff7a3d;
    --accent-d:     #ffc87a;
    --accent-soft:  rgba(245, 183, 110, 0.35);
    --link:         #f5b76e;
    --link-hover:   #ff7a3d;
    --guard-bg:     rgba(18, 16, 13, 0.55);
    --guard-border: rgba(245, 183, 110, 0.35);

    --video-filter: brightness(0.85) saturate(1.15) sepia(0.15) hue-rotate(-8deg);
    --hero-overlay: linear-gradient(180deg, rgba(26, 20, 16, 0.35) 0%, rgba(26, 20, 16, 0.85) 100%);
    --hero-vignette: radial-gradient(ellipse at center, rgba(26, 20, 16, 0.15) 0%, rgba(18, 16, 13, 0.7) 100%);

    --font-display: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
    --font-body:    "Noto Sans JP", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
    --font-label:   "Unica One", "Zen Old Mincho", sans-serif;

    --section-light-bg-color:   var(--bg) !important;
    --section-light-text-color: var(--text) !important;
    --section-dark-bg-color:    var(--bg-alt) !important;
    --section-dark-text-color:  var(--text) !important;
    --highlight-contrast:       #1a1410 !important;
    --highlight-inverse:        #f5b76e !important;
    --highlight-inverse-contrast:#1a1410 !important;
    --cover-title-text-shadow:  0 2px 10px rgba(0,0,0,0.85), 0 0 28px rgba(255,122,61,0.15) !important;
  }
}

/* Manual override: explicit dark */
:root[data-theme="dark"] {
  --bg:           #1a1410;
  --bg-alt:       #12100d;
  --text:         #cfc4b3;
  --text-soft:    #8a8275;
  --accent:       #ff7a3d;
  --accent-d:     #ffc87a;
  --accent-soft:  rgba(245, 183, 110, 0.35);
  --link:         #f5b76e;
  --link-hover:   #ff7a3d;
  --guard-bg:     rgba(18, 16, 13, 0.55);
  --guard-border: rgba(245, 183, 110, 0.35);

  --video-filter: brightness(0.85) saturate(1.15) sepia(0.15) hue-rotate(-8deg);
  --hero-overlay: linear-gradient(180deg, rgba(26, 20, 16, 0.35) 0%, rgba(26, 20, 16, 0.85) 100%);
  --hero-vignette: radial-gradient(ellipse at center, rgba(26, 20, 16, 0.15) 0%, rgba(18, 16, 13, 0.7) 100%);

  --font-display: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-body:    "Noto Sans JP", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --font-label:   "Unica One", "Zen Old Mincho", sans-serif;

  --section-light-bg-color:   var(--bg) !important;
  --section-light-text-color: var(--text) !important;
  --section-dark-bg-color:    var(--bg-alt) !important;
  --section-dark-text-color:  var(--text) !important;
  --highlight-contrast:       #1a1410 !important;
  --highlight-inverse:        #f5b76e !important;
  --highlight-inverse-contrast:#1a1410 !important;
  --cover-title-text-shadow:  0 2px 10px rgba(0,0,0,0.85), 0 0 28px rgba(255,122,61,0.15) !important;
}

/* ---------- Base typography ---------- */
body {
  font-family: var(--font-body);
  font-feature-settings: "palt" 1;
  letter-spacing: 0.02em;
  line-height: 1.85;
  color: var(--text);
  background-color: var(--bg);
  transition: background-color 0.4s ease, color 0.4s ease;
}

html,
body {
  max-width: 100%;
  overflow-x: clip;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.4;
  color: var(--text);
}

p { color: var(--text); }
strong, b { color: var(--accent); font-weight: 700; }

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft);
  transition: color 0.2s ease, border-color 0.2s ease;
}
a:hover { color: var(--link-hover); border-bottom-color: var(--link-hover); }

/* ---------- Hero ---------- */
#site-head {
  position: relative;
  overflow: hidden;
  transition: background-color 0.4s ease;
}
/* Fallback bg only when no video (withCenteredImage class added by theme) */
#site-head.withCenteredImage {
  background-color: var(--bg) !important;
}

#site-head video {
  filter: var(--video-filter);
  left: 0;
  right: auto;
  width: 100%;
  max-width: none;
  transition: filter 0.5s ease;
}

#site-head::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -50;
  background: var(--hero-vignette), var(--hero-overlay);
  pointer-events: none;
}

#site-head .blog-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.6rem, 5.5vw, 4.4rem);
  letter-spacing: 0.04em;
  color: var(--text);
  white-space: nowrap;
}

#site-head .blog-description {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: clamp(0.95rem, 1.8vw, 1.5rem);
  color: var(--text-soft);
  letter-spacing: 0.04em;
}

:root[data-theme="dark"] #site-head .blog-title,
:root:not([data-theme="light"]) #site-head .blog-title {
  /* dark mode heading gets subtle ember glow */
}

#site-head .title-and-description-guard {
  background-color: var(--guard-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-sizing: border-box;
  max-width: calc(100% - 32px);
  border-radius: 4px;
  padding: 1.4em 2em;
  border-top: 1px solid var(--guard-border);
  border-bottom: 1px solid var(--guard-border);
}

#blog-logo {
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.15));
}

/* ---------- Nav buttons ---------- */
#site-head a.btn.site-menu {
  font-family: var(--font-label) !important;
  font-weight: 500 !important;
  letter-spacing: 0.15em;
  text-transform: none;
  color: var(--text) !important;
  background-color: color-mix(in srgb, var(--bg) 75%, transparent) !important;
  border: 1px solid var(--text) !important;
  border-radius: 2px;
  text-shadow: none;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

#site-head a.btn.site-menu:hover,
#site-head a.btn.site-menu:focus {
  background-color: var(--text) !important;
  color: var(--bg) !important;
  border-color: var(--text) !important;
}

/* Dark mode: only accent color differs for buttons (sizes/spacing unified) */
:root[data-theme="dark"] #site-head a.btn.site-menu {
  border-color: var(--link) !important;
}
:root[data-theme="dark"] #site-head a.btn.site-menu:hover,
:root[data-theme="dark"] #site-head a.btn.site-menu:focus {
  background-color: var(--link) !important;
  color: var(--bg) !important;
  border-color: var(--link) !important;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #site-head a.btn.site-menu {
    border-color: var(--link) !important;
  }
  :root:not([data-theme="light"]) #site-head a.btn.site-menu:hover,
  :root:not([data-theme="light"]) #site-head a.btn.site-menu:focus {
    background-color: var(--link) !important;
    color: var(--bg) !important;
    border-color: var(--link) !important;
  }
}

/* ---------- Section content ---------- */
.post-content h2,
.post-content h3,
section h2,
section h3 {
  position: relative;
  padding-bottom: 0.4em;
  margin-top: 2em;
  color: var(--text);
}
.post-content h2::after,
section h2::after {
  content: "";
  display: block;
  width: 2.8em;
  height: 2px;
  background: var(--accent);
  margin-top: 0.5em;
}
:root[data-theme="dark"] .post-content h2::after,
:root[data-theme="dark"] section h2::after {
  background: linear-gradient(90deg, var(--accent) 0%, var(--link) 60%, transparent 100%);
}

.post-content img,
section img {
  border-radius: 2px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  max-width: 100%;
}
:root[data-theme="dark"] .post-content img,
:root[data-theme="dark"] section img {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--accent-soft);
}

.post-content ol,
.post-content ul,
section ol,
section ul { padding-left: 1.5em; }
.post-content ol li,
section ol li { margin-bottom: 0.5em; }
.post-content ol li::marker,
section ol li::marker { color: var(--accent); }

/* ---------- Footer ---------- */
.site-footer {
  background-color: var(--bg-alt);
  color: var(--text-soft);
  font-family: var(--font-body);
  letter-spacing: 0.05em;
}
:root[data-theme="dark"] .site-footer {
  border-top: 1px solid var(--accent-soft);
}

/* ---------- Scroll arrow ---------- */
#header-arrow {
  color: var(--accent) !important;
  opacity: 0.7;
}
#header-arrow:hover { opacity: 1; }

/* ---------- Language switcher ---------- */
#site-languages .btn-lang {
  background-color: color-mix(in srgb, var(--accent) 15%, transparent) !important;
  color: var(--text) !important;
  border: 1px solid var(--accent-soft);
}
#site-languages .btn-lang:hover,
#site-languages .btn-lang.active {
  background-color: var(--accent) !important;
  color: var(--highlight-contrast) !important;
}

/* ---------- Theme toggle button ---------- */
#theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100000;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  color: var(--text);
  border: 1px solid var(--accent-soft);
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s ease, background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
#theme-toggle:hover {
  transform: translateY(-1px) rotate(-8deg);
  color: var(--accent);
  border-color: var(--accent);
}
#theme-toggle svg { display: block; }

/* Show sun in dark mode (to go to light), moon in light mode (to go to dark) */
#theme-toggle .icon-sun { display: none; }
#theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] #theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] #theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) #theme-toggle .icon-moon { display: none; }
}

/* ---------- Hero entrance animation ---------- */
@keyframes hf-rise {
  from { opacity: 0; transform: translateY(14px); filter: blur(4px); }
  to   { opacity: 1; transform: translateY(0);    filter: blur(0); }
}

#blog-logo,
#site-head .title-and-description-guard,
#site-head a.btn.site-menu {
  opacity: 0;
  animation: hf-rise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
#blog-logo                              { animation-delay: 0.05s; }
#site-head .title-and-description-guard { animation-delay: 0.25s; }
#site-head a.btn.site-menu              { animation-delay: 0.55s; }
#site-head a.btn.site-menu:nth-of-type(2) { animation-delay: 0.65s; }
#site-head a.btn.site-menu:nth-of-type(3) { animation-delay: 0.75s; }
#site-head a.btn.site-menu:nth-of-type(4) { animation-delay: 0.85s; }

@media (prefers-reduced-motion: reduce) {
  #blog-logo,
  #site-head .title-and-description-guard,
  #site-head a.btn.site-menu {
    animation: none;
    opacity: 1;
  }
}

/* ---------- Responsive ---------- */
/* When sticky top nav is active (< 1130px), push toggle below it + reserve nav right-padding */
@media (max-width: 1130px) {
  .fixed-nav {
    box-sizing: border-box;
    left: 0;
    right: 0;
    width: 100% !important;
    max-width: 100%;
    padding-right: 56px !important;
  }
  #theme-toggle { top: 0.4rem; width: 38px; height: 38px; }
}
@media (max-width: 900px) {
  #site-head .title-and-description-guard {
    max-width: calc(100% - 24px);
    padding: 1.1rem 1.2rem;
  }

  #site-head .blog-title {
    font-size: clamp(1.6rem, 5.6vw, 2.8rem);
    letter-spacing: 0.02em;
    line-height: 1.2;
    white-space: normal;
    text-wrap: balance;
  }
}
@media (max-width: 768px) {
  #site-head .title-and-description-guard {
    padding: 1rem 1.1rem;
  }

  #site-head .blog-title {
    font-size: clamp(1.3rem, 6.2vw, 1.85rem);
  }

  #theme-toggle { width: 36px; height: 36px; top: 0.3rem; right: 0.4rem; }
}
