:root {
  --bg: #f7f6f3;
  --fg: #1d1d1f;
  --muted: #77767a;
  --line: #d9d7d1;
  --surface: #ffffff;
  --accent: #1f5fbf;
  --ok: #1d8a4a;
  --ng: #c23b3b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --fg: #ecebe8;
    --muted: #96959a;
    --line: #36363a;
    --surface: #1f1f22;
    --accent: #7aa7ec;
    --ok: #5cc98a;
    --ng: #ef7b7b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  line-height: 1.5;
}
button, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--fg);
  background: var(--fg);
  color: var(--bg);
  padding: 0.45em 1.1em;
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: default; }
button.link {
  border: none;
  background: none;
  color: var(--accent);
  padding: 0.2em 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
input:not([type]) {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0.45em 0.6em;
  min-width: 0;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); font-size: 0.85rem; }

.hero { background: #fbd7d7; }
.hero h1 { margin: 0 auto; max-width: 1100px; }
.hero img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 5;
  object-fit: cover;
  object-position: 50% 48%;
}

.rules {
  padding: 1rem clamp(16px, 4vw, 40px) 1.5rem;
  border-bottom: 1px solid var(--line);
}
.rules summary {
  cursor: pointer;
  font-weight: 600;
  width: fit-content;
}
.rules a { display: block; max-width: 1100px; margin: 0.75rem auto 0; }
.rules img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; border: 1px solid var(--line); background: #fff; }

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding: 0.75rem clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
}
.progress { font-variant-numeric: tabular-nums; color: var(--muted); }
.filter { margin-left: auto; font-size: 0.9rem; cursor: pointer; }

main { padding: 1.5rem clamp(16px, 4vw, 40px) 4rem; }
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1.5rem 1.25rem;
}
@media (max-width: 1000px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.grid button {
  all: unset;
  display: block;
  width: 100%;
  cursor: pointer;
}
.grid button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.thumb {
  display: block;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.grid button:hover .thumb { border-color: var(--fg); }
.meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 0.35rem;
  font-variant-numeric: tabular-nums;
}
.meta b { font-size: 1rem; }
.meta .lock { color: var(--ng); font-size: 0.8rem; margin-left: 0.5rem; margin-right: auto; }
.solved .meta b::after { content: " 正解"; color: var(--ok); font-size: 0.8rem; font-weight: 600; }
.solved .thumb { border-color: var(--ok); }
.empty { color: var(--muted); }

dialog {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  padding: 0;
}
dialog::backdrop { background: rgb(0 0 0 / 0.6); }

.quiz {
  width: min(1280px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
}
.quiz { overflow-y: auto; }
.quiz-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.quiz-head h2 { margin: 0 0.25rem; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.nav {
  background: none;
  color: var(--fg);
  border: 1px solid transparent;
  padding: 0.15em 0.6em;
  font-size: 1.1rem;
}
.nav:hover:not(:disabled) { border-color: var(--line); }
.close { margin-left: auto; }

.img-wrap {
  max-height: 72dvh;
  overflow: auto;
  background: var(--surface);
  cursor: zoom-in;
  display: flex;
}
.img-wrap img { margin: auto; width: 100%; max-height: 72dvh; aspect-ratio: 16 / 9; object-fit: contain; display: block; }
.img-wrap.zoom { cursor: zoom-out; }
.img-wrap.zoom img { width: auto; max-width: none; max-height: none; }

.answer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--line);
}
.answer input { flex: 1; }
.result { margin: 0; padding: 0 0.75rem 0.75rem; min-height: 2.25em; font-weight: 600; }
.result:empty { min-height: 0; padding: 0; }
.correct { color: var(--ok); }
.wrong { color: var(--ng); }
.result.correct::before { content: "○ "; }
.result.wrong.judged::before { content: "× "; }
.explanation {
  border-top: 1px solid var(--line);
  padding: 1rem 0.75rem 1.25rem;
}
.explanation h3 { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--muted); font-weight: 600; letter-spacing: 0.08em; }
.explanation-text { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 72ch; }
.explanation-text:empty { display: none; }
.explanation-text a { color: var(--accent); }
.explanation-images { display: grid; gap: 0.75rem; margin-top: 0.75rem; }
.explanation-images:empty { display: none; }
.explanation-images img { display: block; max-width: 100%; max-height: 72dvh; border: 1px solid var(--line); }
.shake { animation: shake 0.3s; }
@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.name-dialog { width: min(360px, calc(100vw - 32px)); }
.name-dialog form { display: flex; flex-direction: column; gap: 0.5rem; padding: 1rem; }
.name-dialog .row { display: flex; justify-content: flex-end; gap: 1rem; align-items: center; margin-top: 0.25rem; }
.name-dialog .result { padding: 0; }

@media (max-width: 520px) {
  .grid { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
  .filter { margin-left: 0; }
}
