/* Explicit data-theme wins over prefers-color-scheme; without JS the system applies. */

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

html {
  --font: "IBM Plex Sans", "IBM Plex Sans KR", "IBM Plex Sans JP", "Segoe UI",
    "Noto Sans CJK KR", "Noto Sans CJK JP", "Noto Sans KR", "Noto Sans JP",
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic",
    "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
  --radius: 8px;
}

:root {
  color-scheme: light;
  --bg: #f5f7fc;
  --card: #ffffff;
  --ink: #17203a;
  --muted: #4d5772;
  --line: #dfe5f2;
  --accent: #1f6fb0;
  --accent-contrast: #ffffff;
  --hover: #eef4fb;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b1020;
    --card: #141c33;
    --ink: #eef2fb;
    --muted: #a7b3d2;
    --line: #243052;
    --accent: #6cc4ef;
    --accent-contrast: #0b1020;
    --hover: #192743;
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fc;
  --card: #ffffff;
  --ink: #17203a;
  --muted: #4d5772;
  --line: #dfe5f2;
  --accent: #1f6fb0;
  --accent-contrast: #ffffff;
  --hover: #eef4fb;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1020;
  --card: #141c33;
  --ink: #eef2fb;
  --muted: #a7b3d2;
  --line: #243052;
  --accent: #6cc4ef;
  --accent-contrast: #0b1020;
  --hover: #192743;
}

html:not([lang="en"]) [data-lang="en"],
html:not([lang="ja"]) [data-lang="ja"],
html:not([lang="ko"]) [data-lang="ko"] {
  display: none;
}

html[lang="en"] #lang-switcher [data-set-lang="en"],
html[lang="ja"] #lang-switcher [data-set-lang="ja"],
html[lang="ko"] #lang-switcher [data-set-lang="ko"],
html[data-theme-pref="system"] #theme-switcher [data-set-theme="system"],
html[data-theme-pref="light"] #theme-switcher [data-set-theme="light"],
html[data-theme-pref="dark"] #theme-switcher [data-set-theme="dark"] {
  background: var(--accent);
  color: var(--accent-contrast);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--ink);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
}

main {
  flex: 0 0 auto;
  background: var(--bg);
}

h1,
h2,
p,
ul {
  margin: 0;
}

:focus {
  outline: none;
}

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

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 3;
  padding: 0.5rem 0.8rem;
  background: var(--accent);
  color: var(--accent-contrast);
  text-decoration: none;
}

.skip:focus {
  top: 0.75rem;
}

.wrap {
  width: min(1080px, calc(100% - 3rem));
  margin-inline: auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  min-height: 3.25rem;
  padding: 0.4rem 0;
}

.brand {
  font-family: var(--font);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
}

.brand a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: inherit;
  text-decoration: none;
}

.brand img {
  height: 2.5rem;
  width: auto;
  display: block;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-left: auto;
}

.segment {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.segment button {
  border-radius: 5px;
  padding: 0.25rem 0.6rem;
  min-height: 2rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}

#theme-switcher button {
  width: 5.25rem;
}

.segment button:hover {
  background: var(--hover);
  color: var(--ink);
}

.mobile-controls {
  display: none;
}

.mobile-menu {
  position: relative;
}

.mobile-trigger {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.mobile-trigger:hover,
.mobile-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.menu-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 4;
  min-width: 8.5rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.menu-panel[hidden] {
  display: none;
}

.menu-panel button {
  display: block;
  width: 100%;
  padding: 0.4rem 0.65rem;
  border-radius: 4px;
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
}

.menu-panel button:hover {
  background: var(--hover);
}

.menu-panel button[aria-pressed="true"] {
  color: var(--accent);
  font-weight: 600;
}

.intro {
  background: var(--bg);
}

.lead {
  max-width: 44rem;
  padding: 2.5rem 0 1.25rem;
  font-size: 1.25rem;
  line-height: 1.55;
  color: var(--ink);
  font-weight: 500;
  text-wrap: pretty;
}

.project-wrap {
  padding-top: 0;
}

.projects {
  list-style: none;
  padding: 0 0 2rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.projects > li {
  display: flex;
  min-width: 0;
}

.card {
  --card-accent: #17715a;
  --card-tint: rgba(50, 157, 114, 0.16);
  --card-edge: rgba(23, 113, 90, 0.3);
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
  width: 100%;
  padding: 1.5rem;
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--card-tint), transparent 65%), var(--card);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.projects > li:nth-child(2) .card {
  --card-accent: var(--accent);
  --card-tint: rgba(56, 159, 214, 0.15);
  --card-edge: rgba(56, 159, 214, 0.3);
}

html[data-theme="dark"] .projects > li:first-child .card {
  --card-accent: #85dfbc;
  --card-tint: rgba(57, 165, 120, 0.19);
  --card-edge: rgba(133, 223, 188, 0.3);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .projects > li:first-child .card {
    --card-accent: #85dfbc;
    --card-tint: rgba(57, 165, 120, 0.19);
    --card-edge: rgba(133, 223, 188, 0.3);
  }
}

.card:hover,
.card:focus-visible {
  border-color: var(--card-accent);
  box-shadow: 0 12px 28px rgba(16, 24, 58, 0.13);
  transform: translateY(-3px);
}

html[data-theme="dark"] .card:hover,
html[data-theme="dark"] .card:focus-visible {
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}

.kind {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--card-accent);
}

.card h2 {
  font-size: 1.45rem;
  line-height: 1.35;
  font-weight: 600;
}

.host {
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.desc {
  line-height: 1.7;
  text-wrap: pretty;
}

[data-lang="ja"],
[data-lang="ko"] {
  line-break: strict;
  overflow-wrap: anywhere;
}

[data-lang="ko"] {
  word-break: keep-all;
}

.open {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  margin-top: auto;
  padding-top: 0.7rem;
  font-weight: 600;
  color: var(--card-accent);
}

.open::after {
  content: "\2192";
  margin-left: 0.4rem;
  transition: transform 0.18s ease;
}

.card:hover .open::after,
.card:focus-visible .open::after {
  transform: translateX(3px);
}

.site-footer {
  padding: 0 0 2rem;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.95rem;
}

.site-footer .wrap {
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.site-footer a {
  color: var(--muted);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.site-footer p + p {
  margin-top: 0.5rem;
}

.site-footer a:hover {
  color: var(--ink);
}

@media (min-width: 800px) {
  .projects {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .wrap {
    width: min(100% - 2rem, 1080px);
  }

  .header-inner {
    gap: 0.3rem;
    min-height: 0;
    padding: 0.3rem 0;
  }

  .brand {
    display: flex;
    align-items: center;
    font-size: 1.05rem;
  }

  .brand img {
    height: 2rem;
  }

  .controls {
    flex-wrap: nowrap;
  }

  .segment {
    display: none;
  }

  .mobile-controls {
    display: flex;
    gap: 0.35rem;
  }

  .lead {
    padding: 1.75rem 0;
    font-size: 1.05rem;
  }

  .card h2 {
    font-size: 1.22rem;
  }

  .kind {
    font-size: 0.76rem;
  }
}

@media (max-width: 360px) {
  .card {
    padding: 1.1rem;
  }

  .card h2 {
    font-size: 1.1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }

  .card:hover,
  .card:focus-visible {
    transform: none;
  }

  .open::after {
    transition: none;
  }
}
