:root {
  color-scheme: light;
  --bg: oklch(97% 0.008 245);
  --surface: oklch(99% 0.006 245);
  --surface-2: oklch(94% 0.012 245);
  --text: oklch(22% 0.018 245);
  --muted: oklch(47% 0.025 245);
  --line: oklch(84% 0.018 245);
  --accent: oklch(61% 0.13 220);
  --accent-strong: oklch(52% 0.16 225);
  --gold: oklch(78% 0.13 82);
  --success: oklch(62% 0.14 150);
  --danger: oklch(58% 0.16 28);
  --shadow: 0 18px 50px oklch(32% 0.03 245 / 0.14);
  --radius: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: oklch(17% 0.018 245);
  --surface: oklch(22% 0.02 245);
  --surface-2: oklch(27% 0.023 245);
  --text: oklch(94% 0.01 245);
  --muted: oklch(74% 0.022 245);
  --line: oklch(35% 0.03 245);
  --accent: oklch(70% 0.14 220);
  --accent-strong: oklch(76% 0.13 220);
  --gold: oklch(80% 0.13 82);
  --success: oklch(72% 0.14 150);
  --danger: oklch(68% 0.16 28);
  --shadow: 0 18px 50px oklch(10% 0.02 245 / 0.42);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, oklch(96% 0.014 220 / 0.82), transparent 38%),
    linear-gradient(180deg, var(--bg), var(--surface-2));
}

:root[data-theme="dark"] body {
  background:
    linear-gradient(135deg, oklch(29% 0.05 220 / 0.36), transparent 40%),
    linear-gradient(180deg, var(--bg), oklch(14% 0.02 245));
}

a {
  color: inherit;
}

img {
  display: block;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid oklch(74% 0.14 220 / 0.72);
  outline-offset: 3px;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  white-space: nowrap;
  padding: 10px 14px;
  background: color-mix(in oklch, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}

.site-header::-webkit-scrollbar {
  display: none;
}

.brand,
.site-nav,
.site-search,
.language-switcher {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.brand {
  gap: 9px;
  text-decoration: none;
  font-weight: 850;
}

.brand-mark {
  display: block;
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-name {
  font-size: 1rem;
}

.site-nav {
  gap: 6px;
}

.nav-link,
.lang-link,
.theme-toggle,
.site-search button,
.primary-action,
.archive-search button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 750;
  transition: background-color 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out, transform 180ms ease-out;
}

.nav-link {
  padding: 8px 11px;
  font-size: 0.9rem;
}

.nav-link.active,
.lang-link.active {
  background: var(--accent);
  border-color: var(--accent);
  color: oklch(98% 0.006 245);
}

.site-search {
  gap: 6px;
}

.site-search input,
.archive-search input {
  width: 180px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 9px 10px;
}

.site-search button,
.theme-toggle,
.lang-link,
.archive-search button {
  min-height: 38px;
  padding: 8px 11px;
}

.language-switcher {
  gap: 5px;
}

.lang-link {
  min-width: 42px;
  text-align: center;
}

main {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 26px 0 48px;
}

.hero-panel,
.work-hero,
.archive-hero,
.static-page,
.game-shell,
.gallery-section,
.home-section,
.mode-strip {
  margin-bottom: 24px;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 20px;
  align-items: stretch;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 14px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2.25rem;
  line-height: 1.05;
}

h2 {
  font-size: 1.45rem;
  line-height: 1.16;
}

p {
  line-height: 1.65;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  background: var(--accent);
  border-color: var(--accent);
  color: oklch(98% 0.006 245);
}

.primary-action:hover,
.nav-link:hover,
.archive-card:hover,
.game-tab:hover {
  transform: translateY(-1px);
}

.hero-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(48px, 1fr));
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.hero-board span {
  aspect-ratio: 3 / 4;
  border-radius: 7px;
  background:
    linear-gradient(145deg, var(--gold), color-mix(in oklch, var(--gold), var(--accent) 26%));
  border: 1px solid color-mix(in oklch, var(--gold), var(--line) 38%);
}

.hero-board span:nth-child(2n) {
  background: linear-gradient(145deg, var(--surface), var(--accent));
}

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

.mode-summary {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.mode-summary h2 {
  margin-bottom: 8px;
}

.mode-summary p {
  margin-bottom: 0;
  color: var(--muted);
}

.page-kicker {
  margin: 34px 0 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin-bottom: 0;
}

.section-head a {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

.archive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(154px, 1fr));
  gap: 14px;
}

.archive-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}

.archive-card {
  display: grid;
  gap: 9px;
  align-content: start;
  min-height: 248px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 8px 22px oklch(22% 0.02 245 / 0.06);
  transition: transform 180ms ease-out, border-color 180ms ease-out;
}

.archive-card:hover {
  border-color: var(--accent);
}

.archive-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
}

.archive-card span {
  font-size: 0.94rem;
  font-weight: 750;
  line-height: 1.25;
}

.archive-hero {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.archive-search {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.archive-search input {
  width: min(420px, 100%);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 26px;
}

.pagination a,
.pagination span,
.pagination strong {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
}

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface);
}

.work-hero {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 20px;
  align-items: end;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.work-hero img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 7px;
  background: var(--surface-2);
}

.work-hero-copy p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

.game-shell {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.game-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.game-tab {
  min-height: 78px;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
}

.game-tab.active {
  border-color: var(--accent);
  background: color-mix(in oklch, var(--accent) 16%, var(--surface));
}

.game-tab span {
  display: block;
  font-weight: 850;
  margin-bottom: 4px;
}

.game-tab small {
  display: block;
  color: var(--muted);
  line-height: 1.35;
}

.game-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.game-options label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 750;
}

.game-options select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 7px 10px;
  font-weight: 800;
}

.select-option {
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.select-option span {
  color: var(--text);
}

.toggle-option {
  cursor: pointer;
}

.toggle-option input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

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

.game-stats {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
}

.game-stats span {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
}

.game-stats strong {
  color: var(--text);
}

.game-message {
  display: grid;
  place-items: center;
  min-height: 50px;
  margin-bottom: 12px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 1.08rem;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
}

.game-message[data-tone="success"] {
  border-color: color-mix(in oklch, var(--success) 45%, var(--line));
  background: color-mix(in oklch, var(--success) 14%, var(--surface));
  color: color-mix(in oklch, var(--success) 78%, var(--text));
}

.game-message[data-tone="danger"] {
  border-color: color-mix(in oklch, var(--danger) 48%, var(--line));
  background: color-mix(in oklch, var(--danger) 13%, var(--surface));
  color: color-mix(in oklch, var(--danger) 78%, var(--text));
}

.memory-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}

.memory-card {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  padding: 0;
  perspective: 900px;
  overflow: hidden;
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  transition: transform 200ms ease-out;
}

.card-back {
  isolation: isolate;
  background:
    linear-gradient(145deg, oklch(20% 0.035 245 / 0.9), oklch(33% 0.055 220 / 0.88)),
    linear-gradient(145deg, var(--gold), color-mix(in oklch, var(--gold), var(--accent) 24%));
  color: oklch(91% 0.03 82 / 0.84);
  font-weight: 900;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.card-back::before,
.card-back::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.card-back::before {
  inset: 0;
  z-index: 0;
  background: var(--work-cover, url("/cover.jpeg")) center / cover no-repeat;
  opacity: 0.16;
  filter: saturate(0.85) contrast(1.12);
}

.card-back::after {
  top: 50%;
  left: 50%;
  z-index: 1;
  width: 48%;
  aspect-ratio: 1;
  border-radius: 24%;
  background: url("/logo-mark.png") center / contain no-repeat;
  opacity: 0.42;
  filter: drop-shadow(0 10px 18px oklch(10% 0.02 245 / 0.22));
  transform: translate(-50%, -50%);
}

.card-front {
  transform: rotateY(180deg);
  background: var(--surface-2);
}

.memory-card.flipped .card-back,
.memory-card.matched .card-back {
  transform: rotateY(180deg);
}

.memory-card.flipped .card-front,
.memory-card.matched .card-front,
.memory-card.revealed .card-front {
  transform: rotateY(0deg);
}

.card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-front span:not(.name-card) {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 6px;
  background: oklch(20% 0.02 245 / 0.82);
  color: oklch(97% 0.006 245);
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.18;
}

.name-card {
  padding: 10px;
  font-weight: 850;
  line-height: 1.25;
  text-align: center;
}

.memory-card.matched {
  border-color: var(--success);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--success) 35%, transparent);
}

.memory-card.not-matched {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--danger) 35%, transparent);
}

.memory-board[data-mode="wrong"] {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.memory-board[data-mode="puzzle"] {
  display: block;
}

.puzzle-layout {
  display: grid;
  gap: 14px;
}

.puzzle-targets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.puzzle-target {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.puzzle-target h3 {
  margin-bottom: 8px;
  font-size: 0.92rem;
  line-height: 1.2;
}

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(var(--puzzle-size), minmax(0, 1fr));
  gap: 4px;
  aspect-ratio: 1;
}

.puzzle-slot,
.puzzle-piece {
  width: 100%;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background-color: var(--surface);
  background-repeat: no-repeat;
  padding: 0;
}

.puzzle-slot {
  border-style: dashed;
  background-color: color-mix(in oklch, var(--surface), var(--surface-2) 50%);
}

.puzzle-slot.filled {
  border-style: solid;
}

.puzzle-slot.drag-over {
  border-color: var(--accent);
  background-color: color-mix(in oklch, var(--accent) 16%, var(--surface));
}

.puzzle-tray {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.puzzle-piece {
  box-shadow: inset 0 0 0 1px oklch(100% 0 0 / 0.18);
  cursor: grab;
}

.puzzle-piece.dragging {
  opacity: 0.55;
  cursor: grabbing;
}

.puzzle-drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  width: 68px;
  aspect-ratio: 1;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background-repeat: no-repeat;
  box-shadow: 0 12px 30px oklch(10% 0.02 245 / 0.35);
  pointer-events: none;
}

.puzzle-piece.selected {
  border-color: var(--accent);
  outline: 3px solid color-mix(in oklch, var(--accent) 58%, transparent);
  outline-offset: 2px;
}

.gallery-section {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.character-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}

.gallery-item {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}

.gallery-item img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

.gallery-item figcaption {
  padding: 7px;
  font-size: 0.78rem;
  font-weight: 750;
  line-height: 1.2;
}

.static-page {
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.static-page h1 {
  margin-bottom: 12px;
}

.static-lede {
  color: var(--muted);
  font-size: 1.05rem;
}

.static-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.static-section h2 {
  margin-bottom: 10px;
}

.static-section p:last-child,
.static-section ul:last-child {
  margin-bottom: 0;
}

.static-section ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.65;
}

.static-section li + li {
  margin-top: 7px;
}

.static-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 0;
}

.static-links a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--accent-strong);
  background: var(--surface-2);
  text-decoration: none;
  font-weight: 750;
}

.site-footer {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 34px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.footer-links {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  white-space: nowrap;
  padding-bottom: 8px;
}

.footer-links a {
  color: var(--accent-strong);
  text-decoration: none;
  font-weight: 700;
}

@media (width <= 820px) {
  main,
  .site-footer {
    width: min(100% - 18px, 1180px);
  }

  .hero-panel,
  .work-hero {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .hero-board {
    grid-template-columns: repeat(4, minmax(42px, 1fr));
  }

  .mode-strip,
  .game-tabs {
    grid-template-columns: 1fr;
  }

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

  .game-options {
    align-items: stretch;
    flex-direction: column;
  }

  .game-options label {
    justify-content: space-between;
  }

  .memory-board {
    grid-template-columns: repeat(3, minmax(78px, 1fr));
    justify-content: stretch;
  }

  .memory-board[data-mode="wrong"] {
    grid-template-columns: repeat(3, minmax(78px, 1fr));
  }

  .puzzle-targets {
    grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
  }

  .puzzle-tray {
    grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  }

  .site-search input {
    width: 146px;
  }
}

@media (width <= 460px) {
  h1 {
    font-size: 1.85rem;
  }

  .archive-grid,
  .archive-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .archive-card {
    min-height: 214px;
  }

  .memory-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .memory-board[data-mode="wrong"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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