/* ==========================================================================
   Koharu — Base layer
   Design tokens, reset, and global typography.
   Ported from astro-koharu (src/styles/theme, src/styles/global).
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Typeface stack. 寒蝉全圆体 is loaded asynchronously from the bundled
     subset CSS under assets/fonts/ChillRoundF…/result.css. */
  --font-sans: "寒蝉全圆体", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;

  /* shadcn-style semantic colors (H S% L% triplets) */
  --background: 0 12% 99%;
  --foreground: 0 0% 20%;

  --card: 0 12% 99%;
  --card-foreground: 240 10% 3.9%;

  --popover: 0 12% 99%;
  --popover-foreground: 240 10% 3.9%;

  --primary: 351 77% 62%;
  --primary-foreground: 355.7 100% 97.3%;

  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;

  --muted: 240 4.8% 95.9%;
  --muted-foreground: 0 0% 35%;

  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;

  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;

  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 346.8 77.2% 49.8%;

  --badge-primary: 351 49% 50%;

  --radius: 0.75rem;

  /* Gradients */
  --gradient-bg-start: #fdfbfb;
  --gradient-bg-end: #ebedee;
  --gradient-bg: linear-gradient(180deg, var(--gradient-bg-start) 10%, var(--gradient-bg-end) 100%);
  --gradient-pink: linear-gradient(279deg, #f96676 0%, #e91e63 100%);
  --gradient-shoka-button-start: #ed6ea0;
  --gradient-shoka-button-end: #ec8c69;
  --gradient-shoka-button: linear-gradient(to right, var(--gradient-shoka-button-start) 0, var(--gradient-shoka-button-end) 100%);

  /* Shoka accents */
  --box-bg-shadow: rgba(0, 0, 0, 0.1);
  --grey-1-a5: rgba(253, 253, 253, 0.5);
  --shoka-blue: 201 69% 54%;
  --grey-4: 0 0% 80%;
  --color-pink: #ed6ea0;
  --color-pink-a3: rgba(237, 110, 160, 0.3);

  /* Drives the sun/sparkles in the header's light-dark switch; `currentColor`
     is deliberate — the switch is white over the hero and turns dark once the
     header gains its background. */
  --theme-toggle-color: currentColor;

  /* Named text colors — light mode */
  --color-red: #e74c3c;
  --color-pink-text: #e91e63;
  --color-orange: #f39c12;
  --color-yellow: #d4a017;
  --color-green: #27ae60;
  --color-aqua: #1abc9c;
  --color-blue: #2e86c1;
  --color-purple: #8e44ad;
  --color-grey: #7f8c8d;

  /* Tokens */
  --shadow-card: 0 0.625rem 1.875rem rgba(90, 97, 105, 0.12);
  --shadow-card-darker: 0 0.625rem 1.875rem rgba(90, 97, 105, 0.2);
  --duration-fast: 150ms;
  --duration-tween: 200ms;
  --duration-normal: 250ms;
  --duration-ui: 300ms;
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Layout */
  --content-width: 1400px;
  --header-height: 60px;
  --sider-width: 300px;

  /* The site header background image is injected inline by the theme. */
  color-scheme: light;
}

.dark {
  --background: 216 13% 15%;
  --foreground: 0 0% 95%;

  --card: 216 13% 15%;
  --card-foreground: 0 0% 95%;

  --popover: 216 13% 15%;
  --popover-foreground: 0 0% 95%;

  --primary: 350 77% 70%;
  --primary-foreground: 355.7 100% 97.3%;

  --secondary: 216 13% 22%;
  --secondary-foreground: 0 0% 98%;

  --muted: 216 13% 22%;
  --muted-foreground: 0 0% 63%;

  --accent: 216 13% 22%;
  --accent-foreground: 0 0% 98%;

  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 0 85.7% 97.3%;

  --border: 216 13% 25%;
  --input: 216 13% 25%;
  --ring: 346.8 77.2% 49.8%;

  --badge-primary: 350 77% 70%;

  --gradient-bg-start: #21252b;
  --gradient-bg-end: #000;
  --gradient-bg: linear-gradient(180deg, var(--gradient-bg-start) 10%, var(--gradient-bg-end) 100%);
  --gradient-shoka-button-start: #f18bb3cc;
  --gradient-shoka-button-end: #f0a387cc;
  --gradient-shoka-button: linear-gradient(to right, var(--gradient-shoka-button-start) 0, var(--gradient-shoka-button-end) 100%);

  --box-bg-shadow: rgba(0, 0, 0, 0.5);
  --grey-1-a5: rgba(34, 34, 34, 0.5);
  --shoka-blue: 201 69% 77%;
  --grey-4: 0 0% 40%;
  --color-pink: #f18bb3;

  /* Named text colors — brighter for dark backgrounds */
  --color-red: #f87171;
  --color-pink-text: #f472b6;
  --color-orange: #fbbf24;
  --color-yellow: #facc15;
  --color-green: #4ade80;
  --color-aqua: #2dd4bf;
  --color-blue: #60a5fa;
  --color-purple: #c084fc;
  --color-grey: #9ca3af;

  --shadow-card: 0 0.625rem 1.875rem rgba(0, 0, 0, 0.4);
  --shadow-card-darker: 0 0.625rem 1.875rem rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* --------------------------------------------------------------------------
   2. Reset
   -------------------------------------------------------------------------- */
/* Display face used by the wordmark (.logo-text). */
@font-face {
  font-family: "Bear Days";
  src: url("../fonts/bear-days.woff2") format("woff2");
  font-display: swap;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-color: hsl(var(--border));
}

html {
  tab-size: 2;
  word-break: break-word;
  scrollbar-gutter: stable;
  overflow-y: auto;
  -webkit-text-size-adjust: 100%;
  /*
   * Chrome's tap highlight is a translucent blue rectangle painted over
   * whatever was touched, and it does not follow `border-radius` — so on a
   * phone every round button in the corner flashed a blue square. It is on by
   * default; the computed value here was `rgba(51, 181, 229, 0.4)`, against
   * `rgba(0, 0, 0, 0)` on the source, which gets this from Tailwind's
   * preflight. The toggle buttons already animate a press of their own, so
   * nothing is lost by turning the highlight off.
   */
  -webkit-tap-highlight-color: transparent;
}

/* Below the sidebar breakpoint the reserved gutter is 4-15px of blank page down
   one side of every screen, and there is no sidebar whose appearance it is
   keeping from shifting. The source drops it at the same width
   (`src/styles/global/tailwind.css:65-69`), and 992px is that breakpoint here
   too — the width at which the sider stops being a column. */
@media (max-width: 992px) {
  html {
    scrollbar-gutter: auto;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  /* `100vh` on mobile is the height with the address bar *retracted*, so the
     value changes when that bar slides in and out — and every change re-lays
     out the whole page mid-fling. `dvh` tracks the live viewport. The `vh`
     line stays above as the fallback for anything too old to parse `dvh`. */
  min-height: 100dvh;
  overscroll-behavior-y: none;
  background-color: var(--gradient-bg-start);
  /*
   * The page gradient. It is anchored to the *document*, not to the viewport:
   * the positioning area is `body`'s own box, which is `min-height: 100dvh`
   * and grows with the page, so the ramp is spread over the full scroll height
   * exactly as the source spreads it over `html`'s box.
   *
   * A previous round painted this from a `position: fixed` pseudo-element
   * instead, which re-anchored it to the viewport — the page then alternated
   * between `#fdfbfb` and `#ebedee` within every screenful, and the bottom of
   * the page (where the random-post block and the footer live) came out a
   * uniform light grey on the port while the source had darkened measurably
   * further. Measured at 1440px with no scroll left: the source reads 245,245,245
   * near the top of the viewport and 235,237,238 at its foot; the port read
   * 253,251,251 and then fell off a cliff in the last 200px.
   *
   * `background-attachment: fixed` is *not* what is being restored — that is
   * the mobile repaint trap it was originally moved away from, and it is still
   * avoided. A plain scroll-attached background over `body` is one painted box.
   */
  background-image: linear-gradient(to top, var(--gradient-bg-end) 0, var(--gradient-bg-start) 30%);
  background-repeat: no-repeat;
  background-position: bottom;
  scroll-behavior: smooth;
  letter-spacing: 0.02em;
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin-block-start: 0;
  font-family: var(--font-sans);
  letter-spacing: 0.02em;
  text-wrap: balance;
}

p,
li,
dd {
  text-wrap: pretty;
}

img,
video,
iframe {
  display: block;
  max-inline-size: 100%;
  border-style: none;
}

figure {
  inline-size: fit-content;
  margin-inline: auto;
}

figcaption {
  font-size: 90%;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  font: inherit;
  color: inherit;
}

input,
textarea,
select {
  font: inherit;
  color: inherit;
}

label {
  display: block;
}

pre,
code,
kbd,
samp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

svg {
  fill: currentColor;
}

:disabled,
[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Components with their own display rules must still respect the hidden
   attribute (author styles otherwise beat the UA rule). */
[hidden] {
  display: none !important;
}

hr {
  border-style: solid;
  border-width: 1px 0 0;
  color: inherit;
  height: 0;
  overflow: visible;
  margin-block: 2.5rem;
}

table {
  caption-side: bottom;
  border-collapse: collapse;
}

:target {
  scroll-margin: 5rem;
}

::selection {
  background-color: var(--color-pink-a3);
}

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

/* --------------------------------------------------------------------------
   3. Scrollbars
   -------------------------------------------------------------------------- */
.vertical-scrollbar::-webkit-scrollbar {
  display: block;
  width: 0.25rem;
  background: hsl(var(--background));
}

.vertical-scrollbar::-webkit-scrollbar-thumb {
  background: hsl(var(--primary) / 0.5);
  border-radius: 0.5rem;
}

.scrollbar-hidden {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scrollbar-hidden::-webkit-scrollbar {
  display: none;
}

/* --------------------------------------------------------------------------
   3b. Cross-document view transitions
   --------------------------------------------------------------------------
   WordPress navigates like a normal website — a full document load — so the
   browser can only cross-fade between pages if it is asked to. `navigation: auto`
   is the standard opt-in, and it is what removes the white flash between two
   pages. It sits under `prefers-reduced-motion: no-preference` exactly as the
   source does (`astro-koharu-main/src/styles/global/reset.css:145`), so a reader
   who asked for less motion keeps the plain jump.

   Everything not named below cross-fades as part of the root snapshot. The
   named parts get their own snapshot pairs, which is what makes them hold still
   while the rest of the page changes: the source names the header
   (`Header.astro:26 transition:name="site-header"`), the sidebar
   (`HomeSider.astro:42 transition:name="page-home-sider"`), and the banner
   (`Cover.astro:133 transition:persist="page-cover-banner"` — `persist` is an
   Astro-only directive, so the banner is named here instead, which produces the
   same "it does not move" result across a real navigation).

   A `view-transition-name` must be unique within the document, so the sidebar is
   named only on the desktop copy: the drawer renders a second `.page-sider` and
   two elements sharing a name cancel the whole transition. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  #site-header {
    view-transition-name: site-header;
  }

  .page-sider:not([data-variant="drawer"]) {
    view-transition-name: page-home-sider;
  }

  .hero {
    view-transition-name: page-cover-banner;
  }
}

/* --------------------------------------------------------------------------
   4. Accessibility helpers
   -------------------------------------------------------------------------- */
.screen-reader-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link:focus {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  padding: 0.75rem 1.25rem;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  clip: auto;
  clip-path: none;
  width: auto;
  height: auto;
}

/* Stops the continuous decorative motion this theme ships — the footer sakura
   spin, the category tab shake and the cover wave — while leaving hover,
   dropdown and toggle feedback animated. A blanket `*` override would kill
   everything for the many visitors whose OS reports reduced motion.

   `html.motion-off` is the visitor's own switch in the Settings Center. The
   extra element in each selector is what out-ranks the single-class animation
   declaration it cancels, so neither block needs `!important` there.

   The cover wave used to be in *neither* list, on the reading that the
   source's two off-rules never applied. That reading was wrong for the switch:
   driving the source in a browser, `html.motion-off` sets the `<use>`
   elements' `animation-name` to `none` and their transform stops changing —
   measured before/after at 700ms apart, `x` went from moving to pinned at
   -160. So the source's own switch does stop the wave, and this switch now
   does too (the rule lives beside the wave in pages.css).

   Under `prefers-reduced-motion` the wave still runs, and that part *is*
   the source's behaviour: its `@media` block loses to the animation rule on
   specificity, and the media query is the visitor's OS preference rather than a
   choice they made here. `wave-off` stays the switch that removes it. */
html.motion-off .footer-sakura,
html.motion-off .animate-spin,
html.motion-off .typewriter-cursor,
html.motion-off .flip-tab a:hover,
html.motion-off .sider-avatar img:hover {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .footer-sakura,
  .animate-spin,
  .typewriter-cursor,
  .flip-tab a:hover,
  .sider-avatar img:hover {
    animation: none !important;
  }
}
