:root {
  --ink: #172033;
  --blue: #2563EB;
  --purple: #7C3AED;
  --green: #16A34A;
  --paper: #F6F8FF;
  --white: #FFFFFF;
  --line: rgba(37, 99, 235, 0.2);
  color-scheme: light;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  line-height: 1.5;
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 8px;
  left: 8px;
  padding: 12px 16px;
  border: 2px solid var(--blue);
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.site-header {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--purple);
  color: var(--white);
  font-size: 24px;
  font-weight: 900;
}
.eyebrow { margin: 0; color: var(--purple); font-size: 12px; font-weight: 900; letter-spacing: 0.16em; }
h1 { margin: 0; font-size: clamp(18px, 3.2vw, 28px); line-height: 1.2; letter-spacing: -0.03em; word-break: keep-all; }

.language select {
  min-height: 44px;
  max-width: 150px;
  padding: 0 12px;
  border: 2px solid var(--blue);
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

main { width: min(100%, 1120px); margin: 0 auto; padding: 20px 16px 32px; }
.intro { margin: 0 0 20px; max-width: 760px; font-weight: 700; }

.comic-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.comic-card {
  display: grid;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--white);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.comic-card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(23, 32, 51, 0.14); }
.comic-card:focus-visible, .viewer button:focus-visible, .language select:focus-visible, .game-link:focus-visible {
  outline: 3px solid var(--purple);
  outline-offset: 3px;
}
.comic-card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #E8ECFF;
}
.comic-card .copy { display: grid; gap: 6px; padding: 12px 14px 16px; }
.comic-card .episode {
  justify-self: start;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--green);
  color: var(--white);
  font-size: 13px;
  font-weight: 900;
}
.comic-card:nth-child(even) .episode { background: var(--blue); }
.comic-card .title { font-size: 17px; font-weight: 900; line-height: 1.3; }
.comic-card .summary { font-size: 14px; color: #3b4660; }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 16px 16px max(24px, env(safe-area-inset-bottom));
  font-size: 13px;
  font-weight: 800;
}
.game-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  border: 2px solid var(--blue);
  border-radius: 999px;
  color: var(--blue);
  text-decoration: none;
}

.viewer {
  width: min(100vw - 20px, 920px);
  max-width: none;
  max-height: calc(100dvh - 20px);
  padding: 0;
  border: 3px solid var(--white);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}
.viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.viewer::backdrop { background: rgba(5, 7, 11, 0.8); }
.viewer-header, .viewer-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}
.viewer-header { border-bottom: 1px solid var(--line); }
.viewer-controls { border-top: 1px solid var(--line); }
.viewer-header h2 { margin: 0; font-size: clamp(16px, 2.4vw, 22px); }
.viewer-body { overflow-y: auto; overscroll-behavior: contain; background: var(--white); }
.viewer-body img { display: block; width: 100%; height: auto; }
.viewer button {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px;
  border: 2px solid var(--blue);
  border-radius: 999px;
  background: var(--white);
  color: var(--ink);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}
#viewer-count { font-weight: 900; }

@media (max-width: 520px) {
  .comic-list { grid-template-columns: 1fr 1fr; gap: 10px; }
  .comic-card .copy { padding: 10px; }
  .comic-card .title { font-size: 15px; }
  .comic-card .summary { display: none; }
  .eyebrow { display: none; }
}

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