:root {
  color-scheme: light;
  --paper: #f7f6f2;
  --paper-deep: #eeece6;
  --surface: #ffffff;
  --ink: #26271f;
  --muted: #6b6c64;
  --line: #e2e0d9;
  --accent: #8d4e39;
  --accent-deep: #753f2e;
  --accent-wash: rgba(141, 78, 57, 0.06);
  --success: #3f7a57;
  --pre-bg: #232420;
  --pre-text: #f5f3ed;
  --pre-border: transparent;
  --font-sans: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Consolas, "D2Coding", monospace;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #121212;
    --paper-deep: #1e1e1e;
    --surface: #1a1a1a;
    --ink: #ededed;
    --muted: #a3a3a3;
    --line: #2a2a2a;
    --accent: #df8a73;
    --accent-deep: #e89e8b;
    --accent-wash: rgba(223, 138, 115, 0.1);
    --success: #8fc7a3;
    --pre-bg: #0d0d0d;
    --pre-text: #ededed;
    --pre-border: #2a2a2a;
  }
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #121212;
  --paper-deep: #1e1e1e;
  --surface: #1a1a1a;
  --ink: #ededed;
  --muted: #a3a3a3;
  --line: #2a2a2a;
  --accent: #df8a73;
  --accent-deep: #e89e8b;
  --accent-wash: rgba(223, 138, 115, 0.1);
  --success: #8fc7a3;
  --pre-bg: #0d0d0d;
  --pre-text: #ededed;
  --pre-border: #2a2a2a;
}

html.is-theme-transitioning,
html.is-theme-transitioning *,
html.is-theme-transitioning *::before,
html.is-theme-transitioning *::after {
  transition: background-color 250ms ease, border-color 250ms ease, color 250ms ease, fill 250ms ease, stroke 250ms ease !important;
  transition-delay: 0s !important;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

*[hidden] {
  display: none !important;
}

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

button,
input {
  font: inherit;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

::selection {
  color: var(--paper);
  background: var(--accent);
}

.site-shell {
  width: min(880px, calc(100% - 64px));
  margin-inline: auto;
}

.visually-hidden,
.skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link:focus {
  position: fixed;
  z-index: 999;
  top: 12px;
  left: 12px;
  padding: 8px 16px;
  color: var(--paper);
  background: var(--ink);
  border-radius: var(--radius);
}

/* Header & Navigation */
.site-header {
  position: relative;
  z-index: 10;
}

.site-header__inner {
  position: relative;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
}

.site-brand {
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-header__actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 24px;
}

.site-nav > a {
  padding: 8px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  transition: color 150ms ease;
}

.site-nav > a:hover,
.site-nav > a.is-active {
  color: var(--ink);
}

.site-nav > a.is-active {
  font-weight: 600;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  color: var(--ink);
  background: var(--paper-deep);
}

.theme-toggle__icon {
  width: 18px;
  height: 18px;
}

.theme-toggle__icon--sun {
  display: none;
}

.theme-toggle__icon--moon {
  display: block;
}

@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;
  }
}

[data-theme="dark"] .theme-toggle__icon--sun {
  display: block;
}

[data-theme="dark"] .theme-toggle__icon--moon {
  display: none;
}

.menu-toggle {
  display: none;
}

/* Site Footer */
.site-footer {
  margin-top: auto;
}

.site-footer__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

/* Home Layout */
.home-main {
  display: flex;
  flex: 1;
  align-items: center;
  padding-block: 48px 96px;
}

.home-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  align-items: end;
  gap: 72px;
}

.home-copy h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(56px, 9vw, 80px);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.1;
}

.home-copy__description {
  margin: 24px 0 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.6;
}

.home-shortcuts {
  border-top: 1px solid var(--line);
}

.home-shortcut {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.home-shortcut__copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.home-shortcut__copy strong {
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  transition: color 150ms ease;
}

.home-shortcut__arrow {
  color: var(--muted);
  transition: color 150ms ease, transform 150ms ease;
}

.home-shortcut:hover .home-shortcut__copy strong,
.home-shortcut:hover .home-shortcut__arrow {
  color: var(--accent);
}

.home-shortcut:hover .home-shortcut__arrow {
  transform: translateX(3px);
}

/* Page Hero */
.page-hero {
  padding-block: 56px 40px;
}

.page-hero h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(30px, 5vw, 40px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.3;
}

/* Blog Archive & Post List */
.blog-archive {
  padding-bottom: 80px;
}

.blog-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.category-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.filter-pill:hover {
  color: var(--ink);
  border-color: var(--muted);
}

.filter-pill.is-active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.search-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 150ms ease;
}

.search-field:focus-within {
  border-color: var(--accent);
}

.search-field input {
  width: 160px;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--ink);
  font-size: 14px;
  outline: none;
}

.search-field input::placeholder {
  color: var(--muted);
}

.search-field kbd {
  padding: 0 6px;
  background: var(--paper-deep);
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.post-grid {
  border-top: 1px solid var(--line);
}

.post-card {
  border-bottom: 1px solid var(--line);
}

.post-card__link {
  display: block;
  padding-block: 24px;
}

.post-card__category {
  display: block;
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.post-card h2 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: -0.02em;
  transition: color 150ms ease;
}

.post-card:hover h2 {
  color: var(--accent);
}

.post-card__link > p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 15px;
}

.post-card__footer {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.empty-state p {
  margin: 0;
}

/* Article Shell (Single Post) */
.article-shell {
  width: min(680px, calc(100% - 64px));
  margin-inline: auto;
  padding-block: 40px 80px;
}

.article-back {
  margin-bottom: 40px;
}

.article-header {
  padding-bottom: 32px;
  border-bottom: 1px solid var(--line);
}

.article-header__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.article-header__meta [data-post-category] {
  color: var(--accent);
  font-weight: 600;
}

.article-header h1 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: clamp(28px, 5vw, 38px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.3;
}

.article-header__description {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 17px;
}

.article-body {
  padding-top: 16px;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.85;
}

.article-body h2,
.article-body h3 {
  color: var(--ink);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.4;
}

.article-body h2 {
  margin: 40px 0 12px;
  font-size: 23px;
}

.article-body h3 {
  margin: 32px 0 8px;
  font-size: 19px;
}

.article-body p {
  margin-block: 16px;
}

.article-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.article-body blockquote {
  margin: 28px 0;
  padding: 2px 0 2px 20px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.article-body code {
  background: var(--paper-deep);
  color: var(--ink);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: var(--font-mono);
}

.article-body pre {
  background: var(--pre-bg);
  color: var(--pre-text);
  border: 1px solid var(--pre-border);
  padding: 20px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 24px 0;
  line-height: 1.6;
  font-size: 14px;
}

.article-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.article-body ul,
.article-body ol {
  padding-left: 24px;
  margin-block: 16px;
}

.article-body li {
  margin-block: 6px;
}

.article-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

/* SNS & Links */
.social-section {
  padding-bottom: 80px;
}

.social-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.social-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.social-card:hover {
  border-color: var(--brand, var(--ink));
  background: color-mix(in srgb, var(--brand, var(--ink)) 5%, var(--surface));
}

.social-card__mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius);
  color: var(--brand, var(--ink));
  background: color-mix(in srgb, var(--brand, var(--muted)) 14%, transparent);
}

.social-card__mark svg {
  width: 22px;
  height: 22px;
}

.social-card__copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.social-card__copy strong {
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
}

.social-card__username {
  color: var(--muted);
  font-size: 13px;
}

.social-card__description {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.social-card__action {
  color: var(--muted);
  justify-self: end;
  transition: color 150ms ease;
}

.social-card:hover .social-card__action {
  color: var(--brand, var(--ink));
}

.social-card__action svg {
  display: block;
  width: 15px;
  height: 15px;
}

.social-card--split {
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: stretch;
  gap: 0;
  padding: 0;
  overflow: hidden;
  cursor: default;
}

.social-card--split > .social-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-width: 0;
  padding: 20px;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.social-card--split > .social-card + .social-card {
  border-left: 1px solid var(--line);
}

.social-card--split > .social-card:hover {
  background: color-mix(in srgb, var(--brand, var(--ink)) 8%, transparent);
}

.social-card--split .social-card__action {
  position: absolute;
  top: 20px;
  right: 20px;
}

.social-card--split .social-card__copy {
  margin-top: auto;
}

.social-card--split .social-card__username {
  overflow-wrap: anywhere;
}

.social-card.is-copied {
  border-color: var(--success);
  background: var(--surface);
}

.social-card--split > .social-card.is-copied {
  background: transparent;
}

.social-card.is-copied .social-card__username,
.social-card.is-copied .social-card__action {
  color: var(--success);
}

/* SNS layout */
body[data-page="sns"] main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: 16px 32px;
}

body[data-page="sns"] .page-hero { padding-block: 0 24px; }
body[data-page="sns"] .social-section { padding-bottom: 0; }

.social-grid.bento {
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: 180px 124px 108px 108px;
  grid-template-areas:
    "dc dc dc dc dc gh gh gh gh gh gh gh"
    "os os os os os os os yt yt yt yt yt"
    "st st st st st st st yt yt yt yt yt"
    "x  x  x  ma ma ma tt tt tt tt tt tt";
}

/* Order follows site-config.js */
.bento > .social-card:nth-child(1) { grid-area: gh; }
.bento > .social-card:nth-child(2) { grid-area: x; }
.bento > .social-card:nth-child(3) { grid-area: yt; }
.bento > .social-card:nth-child(4) { grid-area: st; }
.bento > .social-card:nth-child(5) { grid-area: os; }
.bento > .social-card:nth-child(6) { grid-area: tt; }
.bento > .social-card:nth-child(7) { grid-area: dc; }
.bento > .social-card:nth-child(8) { grid-area: ma; }

.bento > .social-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding-block: 16px;
}

/* Top tier: GitHub, YouTube, Discord */
.bento > .social-card:is(:nth-child(1), :nth-child(3)) {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px;
}

.bento > .social-card:is(:nth-child(1), :nth-child(3), :nth-child(7)) {
  background: color-mix(in srgb, var(--brand, var(--ink)) 7%, var(--surface));
}

.bento > .social-card:nth-child(7) {
  padding: 0;
}

.bento > .social-card:is(:nth-child(1), :nth-child(3)) .social-card__action {
  position: absolute;
  top: 20px;
  right: 20px;
}

.bento > .social-card:is(:nth-child(1), :nth-child(3), :nth-child(7)) .social-card__mark {
  width: 52px;
  height: 52px;
}

.bento > .social-card:is(:nth-child(1), :nth-child(3), :nth-child(7)) .social-card__mark svg {
  width: 28px;
  height: 28px;
}

.bento > .social-card:is(:nth-child(1), :nth-child(3), :nth-child(7)) strong {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.bento > .social-card:is(:nth-child(1), :nth-child(3), :nth-child(7)) .social-card__username {
  font-size: 14px;
}

/* Middle tier: osu! */
.bento > .social-card:nth-child(5) {
  grid-template-columns: 52px minmax(0, 1fr) 16px;
}

.bento > .social-card:nth-child(5) .social-card__mark {
  width: 52px;
  height: 52px;
}

.bento > .social-card:nth-child(5) .social-card__mark svg {
  width: 28px;
  height: 28px;
}

.bento > .social-card:nth-child(5) strong {
  font-size: 18px;
  font-weight: 650;
}

/* Small tier: X, Mail */
.bento > .social-card:is(:nth-child(2), :nth-child(8)) {
  grid-template-columns: 36px minmax(0, 1fr) 15px;
  gap: 10px;
  padding: 14px;
}

.bento > .social-card:is(:nth-child(2), :nth-child(8)) .social-card__mark {
  width: 36px;
  height: 36px;
}

.bento > .social-card:is(:nth-child(2), :nth-child(8)) .social-card__mark svg {
  width: 18px;
  height: 18px;
}

.bento > .social-card:is(:nth-child(2), :nth-child(8)) strong {
  font-size: 15px;
}

@media (max-width: 720px) {
  body[data-page="sns"] main { justify-content: flex-start; }

  .social-grid.bento {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(5, auto);
    grid-template-areas:
      "dc dc"
      "gh yt"
      "os os"
      "st tt"
      "x  ma";
  }

  .bento > .social-card:nth-child(n):not(.social-card--split) {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }

  .bento > .social-card:nth-child(n) .social-card__action {
    position: absolute;
    top: 16px;
    right: 16px;
  }

  .bento > .social-card:nth-child(5) {
    gap: 16px;
    padding: 20px;
  }

  .bento > .social-card--split > .social-card {
    padding: 16px;
  }

  .bento > .social-card--split strong {
    font-size: 18px;
  }

  .bento > .social-card--split .social-card__action {
    top: 16px;
    right: 16px;
  }
}

/* 404 & Not Found */
.not-found {
  flex: 1;
  padding-block: 96px;
  text-align: center;
}

.not-found h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(56px, 10vw, 80px);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.1;
}

.not-found p {
  margin: 8px 0 24px;
  color: var(--muted);
  font-size: 16px;
}

/* Common Buttons & Links */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.button--outline {
  border-color: var(--line);
  background: transparent;
  color: var(--ink);
}

.button--outline:hover {
  border-color: var(--muted);
}

.text-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  transition: color 150ms ease;
}

.text-link:hover {
  color: var(--ink);
}

/* Responsive Styles */
@media (max-width: 720px) {
  .site-shell,
  .article-shell {
    width: calc(100% - 40px);
  }

  .site-header__inner {
    min-height: 64px;
  }

  .site-header__actions {
    gap: 4px;
  }

  .theme-toggle {
    width: 40px;
    height: 40px;
  }

  .menu-toggle {
    position: relative;
    z-index: 7;
    display: flex;
    width: 40px;
    height: 40px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
  }

  .menu-toggle span {
    display: block;
    width: 18px;
    height: 1.5px;
    background: var(--ink);
    transition: transform 180ms ease;
  }

  .menu-toggle[aria-expanded="true"] span:first-child {
    transform: translateY(3.25px) rotate(45deg);
  }

  .menu-toggle[aria-expanded="true"] span:last-child {
    transform: translateY(-3.25px) rotate(-45deg);
  }

  .site-nav {
    position: absolute;
    z-index: 20;
    inset: calc(100% - 4px) 0 auto auto;
    width: min(200px, calc(100vw - 40px));
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 6px 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    visibility: hidden;
  }

  .site-nav.is-open {
    visibility: visible;
  }

  .site-nav > a {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
    font-size: 15px;
  }

  .site-nav > a:last-child {
    border-bottom: 0;
  }

  .home-main {
    padding-block: 32px 56px;
  }

  .home-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 40px;
  }

  .page-hero {
    padding-block: 32px 28px;
  }

  .social-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .blog-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-field input {
    width: 100%;
  }

  .search-field kbd {
    display: none;
  }

  .not-found {
    padding-block: 64px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
