:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --text: #1c1d22;
  --muted: #5b5e6b;
  --border: #dcdde3;
  --accent: #4338ca;
  --accent-soft: #eef0ff;
  --error-bg: #fff1f1;
  --error-text: #9b1c1c;
  --wide-gap: 1.5rem;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  line-height: 1.6;
}

[lang="ja"] {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
}

[hidden] { display: none !important; }

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

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

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

/* Header */
.site-header {
  padding: 0.75rem 1rem 0.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-title {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 700;
}

.theme-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  max-width: 32rem;
}

.theme-button {
  min-height: 48px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  font-size: 1.0625rem;
  font-weight: 600;
}

.theme-button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.site-note {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

/* Loading and errors */
.status {
  margin: 1rem;
  color: var(--muted);
}

.error-region {
  margin: 1rem;
  padding: 1rem;
  border: 1px solid var(--error-text);
  border-radius: 0.5rem;
  background: var(--error-bg);
  color: var(--error-text);
  overflow-wrap: anywhere;
}

.error-region h2 {
  margin: 0 0 0.5rem;
  font-size: 1.0625rem;
}

.error-region ul {
  margin: 0;
  padding-left: 1.25rem;
}

/* Card grid */
.grid-panel {
  padding: 1rem;
  min-width: 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(9rem, 100%), 1fr));
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card-button {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  width: 100%;
  min-height: 44px;
  padding: 0.375rem;
  border: 2px solid transparent;
  border-radius: 0.5rem;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
  text-align: left;
}

.card-button img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 200 / 290;
  border-radius: 0.25rem;
  background: var(--border);
}

.card-button .card-label {
  font-size: 0.9375rem;
  line-height: 1.4;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.card-button[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent);
}

.image-error {
  margin: 0;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

/* Detail */
.detail-panel {
  padding: 1rem;
  background: var(--surface);
  min-width: 0;
}

.back-button {
  min-height: 48px;
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--accent);
  font-size: 1.0625rem;
  font-weight: 600;
}

.detail-image {
  display: block;
  width: 100%;
  max-width: 16rem;
  height: auto;
  aspect-ratio: 200 / 290;
  margin-bottom: 1rem;
  border-radius: 0.375rem;
  background: var(--border);
}

.detail-name {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.4;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.detail-name:focus { outline: none; }

.unofficial {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0 0.5rem;
  border-radius: 1rem;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 600;
  vertical-align: middle;
}

.detail-name-ja {
  margin: 0.25rem 0 0;
  font-size: 1.0625rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.detail-ruby {
  display: block;
  font-size: 0.875rem;
}

.detail-stats {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 1rem;
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: var(--bg);
  font-size: 1rem;
}

.detail-stats dt { color: var(--muted); }
.detail-stats dd { margin: 0; overflow-wrap: anywhere; }

.detail-effects h3,
.detail-source h3 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1.0625rem;
}

.effect-text {
  margin: 0 0 0.875rem;
  font-size: 1.25rem; /* 20px at default browser font size */
  line-height: 1.85;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.detail-source {
  margin-top: 1.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.9375rem;
  color: var(--muted);
}

.detail-source p { margin: 0.25rem 0; overflow-wrap: anywhere; }

.detail-source a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
}

/* Narrow: one panel at a time */
@media (max-width: 899.98px) {
  body[data-view="grid"] .detail-panel { display: none; }
  body[data-view="detail"] .grid-panel { display: none; }
  .detail-panel { min-height: 60vh; }
}

/* Wide: grid left, independently scrolling detail right */
@media (min-width: 900px) {
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }

  .back-button { display: none; }

  .detail-panel {
    position: sticky;
    top: 0;
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
    border-left: 1px solid var(--border);
  }

  .detail {
    padding-bottom: 2rem;
  }
}

@media (min-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
}
