:root {
  color-scheme: light;
  --ink: #17342e;
  --muted: #6a7d76;
  --paper: #f5f1e8;
  --card: #fffdf7;
  --green: #2d765f;
  --green-dark: #1f5d4a;
  --green-soft: #dcece4;
  --red: #b34d49;
  --line: rgba(23, 52, 46, .14);
  --shadow: 0 22px 70px rgba(35, 62, 52, .13);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(150, 202, 165, .32), transparent 34rem),
    radial-gradient(circle at 90% 95%, rgba(247, 207, 127, .20), transparent 28rem),
    var(--paper);
  font-family: "Yu Gothic UI", "Hiragino Sans", system-ui, sans-serif;
}
button { font: inherit; }
[hidden] { display: none !important; }

.shell { width: min(1180px, 100%); margin: 0 auto; padding: clamp(1rem, 4vw, 3rem); }
.eyebrow { margin: 0 0 .5rem; color: var(--green); font-size: .72rem; font-weight: 900; letter-spacing: .17em; }
h1, h2 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-weight: 600; }

.start-screen {
  width: min(630px, 100%);
  min-height: calc(100vh - clamp(2rem, 8vw, 6rem));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.start-meta { display: flex; gap: .8rem; align-items: center; color: var(--muted); }
.start-meta strong { padding: .3rem .55rem; border-radius: 99px; color: var(--green-dark); background: var(--green-soft); }
.start-screen h1 { max-width: 12em; margin: 1.3rem 0 .8rem; font-size: clamp(2.25rem, 7vw, 4.8rem); line-height: 1.16; }
.intro { margin: 0; color: var(--muted); font-size: clamp(1rem, 2.3vw, 1.2rem); line-height: 1.9; }
.streak { display: grid; gap: .15rem; margin: 2.2rem 0 1.3rem; color: var(--muted); font-size: .78rem; }
.streak strong { color: var(--ink); font-size: 1.2rem; }
.revive { margin: -.4rem 0 1.3rem; color: var(--muted); font-size: .85rem; line-height: 1.7; }
.revive a { color: var(--green-dark); font-weight: 800; }
.primary-button {
  min-width: min(320px, 100%);
  min-height: 54px;
  padding: .8rem 1.5rem;
  border: 0;
  border-radius: 14px;
  color: white;
  background: var(--green);
  box-shadow: 0 12px 30px rgba(45, 118, 95, .23);
  cursor: pointer;
  font-weight: 900;
  letter-spacing: .04em;
}
.primary-button:hover:not(:disabled) { background: var(--green-dark); transform: translateY(-1px); }
.primary-button:disabled { opacity: .48; cursor: default; box-shadow: none; }
.error-message { max-width: 38rem; color: var(--red); }

.game-header { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.game-header h1 { font-size: clamp(1.7rem, 4vw, 3rem); }
.game-stats { display: flex; gap: .6rem; }
.game-stats > div { min-width: 100px; padding: .75rem .9rem; border: 1px solid var(--line); border-radius: 13px; background: rgba(255, 253, 247, .78); text-align: right; }
.game-stats span { display: block; color: var(--muted); font-size: .68rem; font-weight: 800; }
.game-stats strong { display: block; margin-top: .1rem; font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.comparison { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(.8rem, 2.2vw, 1.5rem); }
.comparison figure { position: relative; min-width: 0; margin: 0; }
.image-stage { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: #dfe9e3; box-shadow: var(--shadow); cursor: crosshair; touch-action: pan-x pan-y pinch-zoom; }
.image-stage:focus-visible { outline: 3px solid #f0b454; outline-offset: 3px; }
.image-stage img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.frame-layer { position: absolute; inset: 0; pointer-events: none; }
.answer-frame { position: absolute; translate: -50% -50%; aspect-ratio: 1; border: 4px solid #fff9cf; border-radius: 50%; box-shadow: 0 0 0 3px var(--red), 0 4px 16px rgba(0,0,0,.3); }
.answer-frame.active { animation: breathe 1.3s ease-in-out infinite; }
.answer-frame.fixed, .answer-frame.revealed { border-color: white; box-shadow: 0 0 0 3px var(--green-dark), 0 4px 16px rgba(0,0,0,.25); }
.answer-frame.revealed { box-shadow: 0 0 0 3px var(--red), 0 4px 16px rgba(0,0,0,.25); }
.answer-frame.fixed::after, .answer-frame.revealed::after { content: attr(data-label); position: absolute; top: -9px; left: 50%; translate: -50% -100%; min-width: 24px; height: 24px; padding: 0 5px; border-radius: 99px; color: white; background: var(--green-dark); font-size: .72rem; font-weight: 900; line-height: 24px; text-align: center; }
.answer-frame.revealed::after { background: var(--red); }
@keyframes breathe { 50% { scale: 1.07; } }
.comparison figcaption { padding-top: .65rem; text-align: center; color: var(--muted); font-size: .83rem; font-weight: 800; }
.zoom-button { position: absolute; right: .7rem; bottom: 2.4rem; border: 1px solid var(--line); border-radius: 99px; padding: .35rem .65rem; background: rgba(255,255,255,.9); color: var(--ink); cursor: pointer; font-size: .72rem; font-weight: 800; }

.answer-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1.35rem; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 253, 247, .88); box-shadow: 0 10px 30px rgba(35, 62, 52, .08); }
.answer-bar p { margin: 0; color: var(--muted); }
.answer-bar .primary-button { min-width: 190px; }

.result-panel { margin-top: 1.3rem; padding: clamp(1.25rem, 4vw, 2rem); border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.result-panel h2 { font-size: clamp(1.6rem, 4vw, 2.5rem); }
.result-summary { color: var(--muted); }
.result-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .7rem; margin: 1.2rem 0; }
.result-stats div { padding: .85rem; border-radius: 12px; background: #eef2eb; }
.result-stats dt { color: var(--muted); font-size: .7rem; font-weight: 800; }
.result-stats dd { margin: .15rem 0 0; font-size: 1.2rem; font-weight: 900; }
.result-standing { margin: 0 0 1.2rem; color: var(--muted); font-weight: 800; }
.discovery-list { margin: 0; padding-left: 1.4rem; color: var(--muted); line-height: 1.9; }
.result-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-top: 1.4rem; }
.secondary-link { color: var(--green-dark); font-weight: 800; }
.share-status { min-height: 1.5em; margin: .8rem 0 0; color: var(--muted); white-space: pre-line; }
.diff-flash { position: absolute; inset: 0; opacity: 0; pointer-events: none; animation: diff-flash 1.2s ease-in-out .4s 5 alternate both; }
@keyframes diff-flash { 0%, 25% { opacity: 1; } 75%, 100% { opacity: 0; } }

dialog { width: min(94vw, 900px); padding: 0; overflow: hidden; border: 0; border-radius: 18px; background: #e6ece7; box-shadow: 0 30px 100px rgba(0,0,0,.4); }
dialog::backdrop { background: rgba(10, 26, 22, .78); backdrop-filter: blur(8px); }
dialog img { display: block; width: 100%; max-height: 90vh; object-fit: contain; touch-action: pan-x pan-y pinch-zoom; }
dialog button { position: absolute; z-index: 2; top: .7rem; right: .7rem; width: 42px; height: 42px; border: 0; border-radius: 50%; background: white; color: var(--ink); cursor: pointer; font-size: 1.4rem; }

@media (max-width: 700px) {
  .shell { padding: 1rem; }
  .game-header { align-items: stretch; flex-direction: column; }
  .game-stats > div { flex: 1; text-align: left; }
  .comparison { grid-template-columns: 1fr; }
  .answer-bar { position: sticky; z-index: 10; bottom: .6rem; align-items: stretch; flex-direction: column; }
  .answer-bar.finished { position: static; }
  .answer-bar .primary-button { width: 100%; }
  .result-stats { grid-template-columns: 1fr; }
}

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

.archive { width: min(720px, 100%); }
.archive h1 { margin-bottom: .6rem; font-size: clamp(2rem, 6vw, 3.2rem); }
.archive-list { display: grid; gap: .6rem; margin: 1.6rem 0; padding: 0; list-style: none; }
.archive-list a { display: grid; grid-template-columns: 4.5rem 1fr auto; gap: .8rem; align-items: center; padding: .9rem 1.1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); text-decoration: none; }
.archive-list a:hover, .archive-list a:focus-visible { border-color: var(--green); }
.archive-list strong { color: var(--green-dark); }
.archive-status { color: var(--muted); font-size: .85rem; font-weight: 800; }
.archive-list a.played .archive-status { color: var(--green-dark); }
.archive-final { grid-column: 1 / -1; color: var(--muted); font-size: .8rem; }
.archive-message { color: var(--muted); }
@media (max-width: 480px) {
  .archive-list a { grid-template-columns: 3.5rem 1fr; }
  .archive-status { grid-column: 2; }
}
