/* ねこけん ミニゲーム 共通スタイル */
:root {
  color-scheme: light;
  --bg: #fafbfc;
  --bg-deep: #eef2f6;
  --card: #ffffff;
  --ink: #202d3c;
  --ink-soft: #3a4a5c;
  --muted: #526276;
  --line: #dfe5eb;
  --line-strong: #b6c5d6;
  --accent: #1757be;
  --accent-ink: #11479c;
  --accent-soft: #d9e6f8;
  --accent-softer: #edf5fb;
  --ok: #286447;
  --ok-soft: #e8f3ec;
  --ng: #a63730;
  --ng-soft: #fbe6e3;
  --black-cell: #2c3b4e;
  --done: #536478;
  --cross: #697e96;
  --radius: 14px;
  --shadow: 0 3px 8px rgba(35, 57, 84, .04);
  --shadow-hover: 0 14px 30px rgba(35, 57, 84, .07);
  --font: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, system-ui, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent-ink); }

button { font: inherit; color: inherit; }

.site-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 0;
  width: min(960px, calc(100% - 32px));
  margin: 0 auto 20px;
  border-bottom: 1px solid var(--line);
}
.site-header .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: .06em;
  white-space: nowrap;
}
.site-header .logo small { font-size: .78rem; font-weight: 600; color: var(--muted); letter-spacing: .04em; }
.site-header .logo img { width: 36px; height: 36px; flex: none; image-rendering: pixelated; }
.site-header .back {
  margin-left: auto;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  padding: 6px 4px;
  white-space: nowrap;
}
.site-header .back:hover { color: var(--accent); }

main {
  flex: 1;
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  padding: 0 0 40px;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  border-top: 1px solid var(--line);
  font-size: .7rem;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 20px 0;
}
.scroll-top {
  border: 0; background: transparent; color: var(--muted); font: inherit;
  min-width: 32px; min-height: 32px; cursor: pointer;
}
.scroll-top:hover { color: var(--accent); }

h1 { font-size: 1.45rem; margin: 8px 0 4px; font-weight: 800; letter-spacing: .02em; }
h2 { font-size: 1.05rem; margin: 28px 0 12px; color: var(--ink); font-weight: 750; }
.lead { color: var(--muted); margin: 0 0 16px; font-size: .92rem; line-height: 1.9; }

/* ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-size: .9rem;
  text-decoration: none;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--line-strong); }
.btn:active { background: var(--bg-deep); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--card); }
.btn:disabled { opacity: .45; cursor: default; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}
.toolbar .spacer { flex: 1; }
.segmented {
  display: inline-flex;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--card);
}
.segmented .btn { border: 0; border-radius: 0; min-width: 64px; }

.segmented .btn:focus-visible { outline-offset: -4px; }
.segmented .btn[aria-pressed="true"]:focus-visible { outline-color: white; }

/* カード一覧 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.puzzle-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr));
  gap: 12px;
}
.puzzle-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  padding: 12px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
}
.puzzle-item:hover, .stage:hover { border-color: var(--line-strong); box-shadow: var(--shadow-hover); }
.puzzle-item:focus-visible, .stage:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.puzzle-heading { display: flex; gap: 8px; align-items: center; flex: 1; }
.puzzle-item .thumb {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  overflow: hidden; border: 1px solid var(--line-strong); border-radius: 7px;
  background-color: var(--accent-softer); color: var(--accent-ink); font-weight: 800;
}
.thumb.unknown {
  background-image: linear-gradient(to right, #b5cadc80 1px, transparent 1px),
                    linear-gradient(to bottom, #b5cadc80 1px, transparent 1px);
  background-size: 8px 8px;
}
.thumb canvas { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.puzzle-item .name { font-weight: 700; font-size: .96rem; line-height: 1.4; }
.puzzle-item .meta { font-size: .78rem; color: var(--muted); }
.puzzle-status {
  align-self: flex-start; color: var(--muted); padding: 1px 7px;
  background: var(--bg-deep); border-radius: 5px; font-size: .78rem;
  font-variant-numeric: tabular-nums;
}
.puzzle-status.started { color: var(--accent-ink); background: var(--accent-softer); border-inline-start: 3px solid var(--accent); }
.puzzle-status.done { color: var(--ok); background: var(--ok-soft); font-weight: 700; }
.stats {
  width: 100%; border-collapse: collapse; border-top: 1px solid var(--line);
  font-size: .78rem; line-height: 1.55; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.stats th, .stats td { padding: 1px 3px; text-align: right; font-weight: 400; }
.stats thead th { padding-top: 6px; }
.stats tbody th { text-align: left; }
.stats tbody td { color: var(--ink); font-weight: 650; }
.stats tbody tr:nth-child(even) { background: var(--bg); }

.timer { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: .95rem; }

/* モーダル */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(32, 45, 60, .35);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
  animation: fade .2s ease-out;
}
.modal {
  background: var(--card);
  border-radius: 16px;
  padding: 24px 20px 20px;
  width: min(360px, 100%);
  text-align: center;
  box-shadow: 0 10px 40px rgba(32, 45, 60, .2);
  animation: pop .25s ease-out;
}
.modal h2 { margin: 0 0 8px; color: var(--accent-ink); font-size: 1.4rem; }
.modal p { margin: 4px 0; color: var(--ink-soft); }
.modal .actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.modal .art { display: block; margin: 14px auto; padding: 8px; border: 1px solid var(--line); }
.modal:has(.art) .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.modal:has(.art) .actions .primary { grid-column: 1 / -1; }
@media (max-height: 540px) {
  .modal { max-height: calc(100dvh - 32px); overflow: auto; }
}

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--card);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 200;
  pointer-events: none;
  animation: fade .2s ease-out;
}

.hidden { display: none !important; }
.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;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.howto { margin-top: 22px; padding: 12px 16px; font-size: .9rem; color: var(--ink-soft); }
.howto summary { cursor: pointer; font-weight: 700; color: var(--ink); }
.howto ul { margin: 8px 0 0; padding-left: 1.2em; }
.game-settings {
  display: flex; flex-wrap: wrap; gap: 4px 16px; min-inline-size: 0;
  padding: 8px 14px 12px; margin: 16px auto 0; max-width: 560px;
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink-soft); font-size: .85rem;
}
.game-settings legend { padding: 0 5px; font-weight: 700; }
.game-settings label { display: inline-flex; align-items: center; gap: 5px; }
.game-settings input { margin: 0; accent-color: var(--accent); }
@media (max-width: 480px) {
  .site-header { padding-block: 12px; margin-bottom: 12px; }
  .puzzle-list { gap: 9px; }
}

:root {
  --bg:#f7f7f2; --bg-deep:#e9ede8; --card:#fffef9; --ink:#213b4a;
  --ink-soft:#344f5d; --muted:#526574; --line:#cdd7d2; --line-strong:#8baba9;
  --accent:#245d72; --accent-ink:#214e60; --accent-soft:#c9e1df; --accent-softer:#e3eeeb;
  --radius:9px; --shadow:none;
}
.site-header {flex-wrap:wrap}
.site-header .logo img {object-fit:contain}
.btn,.segmented {border-radius:6px}
.game-card .visual {background:#eddfb8}
.game-card .visual.cw {background:#e0ddee}
.game-card .visual.bo {background:#d4e7df}
.game-card .visual.pb {background:#ead8df}
.game-card .visual svg {filter:none}
.puzzle-item .thumb {background-color:var(--tile,#eddfb8)}
body:has(.cw-cell),body:has(#cw-input) {--tile:#e0ddee}
.scroll-top {min-height:44px}
@media(max-width:480px){
  main .games {gap:6px;margin-top:8px}
  main .game-body {padding:7px 10px}
  main .game-body p {margin:2px 0 4px;line-height:1.4}
  main .game-foot {padding-top:2px}
}
