/* 터치 기기에서는 커서가 없으므로 스포트라이트가 스스로 벽을 돌아다닌다. */
@property --mx { syntax: '<length-percentage>'; inherits: true; initial-value: 50%; }
@property --my { syntax: '<length-percentage>'; inherits: true; initial-value: 30%; }

:root {
  --wall-tile: 114px; /* .wall-row img 크기 + 간격. app.js가 읽어서 벽의 칸 수를 정한다. */
  --pad: 1.25rem;
  interpolate-size: allow-keywords;
  --bg: light-dark(#f3f5f9, #12151b);
  --glass: light-dark(rgba(243, 245, 249, .72), rgba(18, 21, 27, .72));
  --panel: light-dark(#fff, #22262e);
  --line: light-dark(#d8dde6, #383e49);
  --text: light-dark(#1b2230, #f2f4f8);
  --dim: light-dark(#5e6879, #a4abb8);
  --faint: light-dark(#9aa3b2, #6d7584);
  --hero-sub: light-dark(#3d5a75, #cfe3f2);
  --photo-bg: light-dark(#cbd2dd, #8791a3);
  --shadow: light-dark(rgba(30, 50, 80, .14), rgba(0, 0, 0, .35));
  --accent: light-dark(#0b85d0, #1a9fe8);
  --good: light-dark(#138a55, #35c47c);
  --bad: light-dark(#d5393f, #ef5a5f);
  --gold: light-dark(#b07a06, #f0c04a);
  --radius: 10px;
  /* 임계 감쇠 스프링(response .35s)을 표본으로 뽑은 곡선. 튕김 없이 멎는다. */
  --spring: linear(0, .136, .367, .573, .726, .83, .897, .938, .964, .979, .988, .993, .996, .998, 1);
  --settle: 500ms;
  --press: transform var(--settle) var(--spring), background-color .15s ease-out, border-color .15s ease-out, color .15s ease-out;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard Variable', Pretendard, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  line-height: 1.5;
  transition: background-color .3s ease-out, color .3s ease-out;
}

button, input { font: inherit; }

button, .chip {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button {
  padding: .5rem .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: var(--press);
}
button:active:not(:disabled) { transform: scale(.97); transition-duration: 100ms; transition-timing-function: ease-out; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.armed { border-color: var(--bad); background: var(--bad); color: #fff; }

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

.hero {
  padding: 3.5rem 1.25rem 2rem;
  text-align: center;
  background: radial-gradient(closest-side, var(--bg) 45%, transparent);
}
.logo {
  display: block;
  width: 5.5rem;
  margin: 0 auto .75rem;
  filter: brightness(0) invert(.55);
  animation: logo-in .8s var(--spring) backwards;
}
.hero h1 {
  margin: 0;
  font-size: clamp(1.9rem, 6vw, 2.9rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -.02em;
  animation: rise var(--settle) var(--spring) .1s backwards;
}
.hero p { margin: .6rem 0 0; color: var(--hero-sub); animation: rise var(--settle) var(--spring) .18s backwards; }

#wall { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.wall-rows {
  position: absolute;
  inset: -25vh -25vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  transform: translate3d(var(--px, 0), var(--py, 0), 0) rotate(-8deg);
  transition: transform var(--settle) var(--spring);
}
.wall-row { display: flex; width: max-content; animation: wall var(--time) linear infinite; }
.wall-row:nth-child(even) { animation-direction: reverse; }
.wall-row img {
  width: calc(var(--wall-tile) - 10px);
  height: calc(var(--wall-tile) - 10px);
  margin-right: 10px;
  border-radius: 18px;
  object-fit: cover;
  object-position: 50% 15%;
}
/* 벽을 덮는 막에 커서 위치만큼 구멍을 내서 그 주변의 얼굴만 또렷하게 보인다. */
#wall::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg);
  opacity: .82;
  mask-image: radial-gradient(circle 15rem at var(--mx) var(--my), transparent 25%, #000 100%);
}

@keyframes logo-in { from { opacity: 0; transform: scale(.8) rotate(-12deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } }
@keyframes wall { to { transform: translateX(-50%); } }
@keyframes roam {
  0%, 100% { --mx: 25%; --my: 20%; }
  33% { --mx: 75%; --my: 40%; }
  66% { --mx: 40%; --my: 75%; }
}

#howToButton {
  margin-top: .75rem;
  background: var(--glass);
  animation: rise var(--settle) var(--spring) .24s backwards;
}

#howTo {
  width: calc(100% - 1.5rem);
  max-width: 34rem;
  max-height: 86dvh;
  padding: 1.5rem;
  overflow-y: auto;
  border: 0;
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 60px var(--shadow);
  transition: opacity .25s ease-out, transform var(--settle) var(--spring);
}
@starting-style {
  #howTo[open] { opacity: 0; transform: translateY(14px) scale(.97); }
}
#howTo::backdrop { background: rgba(10, 14, 22, .5); }
#howTo.not-board .board-only { display: none; }
#howTo h2 { margin: 0; font-size: 1.4rem; letter-spacing: -.01em; }
#howTo p { margin: .35rem 0 0; }
#howTo ul { margin: 1rem 0 0; padding-left: 1.1rem; font-size: .92rem; }
#howTo li { margin-bottom: .55rem; }
#howTo li b, .how-gold b, #howTo em { color: var(--accent); font-style: normal; font-weight: 700; }
#howTo .tile b { font-size: .95rem; }

.how-demo { display: flex; align-items: center; justify-content: center; gap: .6rem; margin-top: 1rem; }
.how-demo .tile, .how-gold .tile { flex: none; width: 6rem; }
.how-typed { color: var(--dim); font-size: .8rem; font-weight: 700; text-align: center; white-space: nowrap; }
.how-gold { display: flex; align-items: center; gap: .8rem; margin-top: .5rem; padding: .8rem; border-radius: 14px; background: color-mix(in srgb, var(--gold) 12%, transparent); }
.how-gold p { flex: 1; font-size: .88rem; }
.how-gold strong { color: var(--gold); }

#howTo form { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: 1rem; }
.how-hide { color: var(--dim); font-size: .85rem; cursor: pointer; }
#closeHowTo { border: 0; background: var(--accent); color: #fff; font-weight: 800; }

#setup {
  max-width: 760px;
  margin: 0 auto 2rem;
  padding: 1.5rem var(--pad) 0;
  border-radius: 20px;
  box-shadow: 0 12px 40px var(--shadow);
}

#game { max-width: 1240px; margin: 0 auto; padding: 0 .75rem 1.5rem; transition: opacity .3s ease-out, transform var(--settle) var(--spring); }
@starting-style {
  #game { opacity: 0; transform: translateY(12px); }
}

fieldset {
  margin: 0 0 1.25rem;
  padding: 0;
  border: 0;
  animation: rise var(--settle) var(--spring) calc(.3s + var(--i, 0) * 40ms) backwards;
}
legend { padding: 0; margin-bottom: .5rem; font-size: .95rem; font-weight: 700; }
legend small { margin-left: .4rem; color: var(--dim); font-size: .8rem; font-weight: 400; }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; }
.chip span {
  display: block;
  padding: .45rem .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: .95rem;
  font-weight: 600;
  transition: var(--press);
}
.chip:active span { transform: scale(.96); transition-duration: 100ms; transition-timing-function: ease-out; }
.chip input:checked + span { border-color: transparent; background: var(--school, var(--accent)); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
#view .chip span { padding: .15rem .6rem; font-size: .8rem; }

@media (hover: hover) {
  button:hover:not(:disabled) { border-color: var(--accent); }
  .chip:hover span { border-color: var(--school, var(--accent)); }
}

#bar, #setup {
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
}

.start {
  position: sticky;
  bottom: 0;
  margin: 0 calc(var(--pad) * -1);
  padding: .75rem var(--pad) 1rem;
  border-radius: 0 0 20px 20px;
  background: linear-gradient(transparent, var(--bg) 40%);
}
.start button {
  width: 100%;
  padding: .85rem;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  box-shadow: 0 6px 20px rgba(26, 159, 232, .3);
}
.start button:disabled { background: var(--panel); color: var(--dim); box-shadow: none; }

#theme {
  position: fixed;
  top: .7rem;
  right: .7rem;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem .95rem;
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: .9rem;
  font-weight: 800;
  box-shadow: 0 6px 18px var(--shadow);
}

.school-actions { display: flex; gap: .4rem; margin-bottom: .5rem; }
.school-actions button { padding: .2rem .7rem; font-size: .8rem; }

#bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  margin: 0 -.75rem .5rem;
  padding: .75rem 9rem .6rem .75rem;
}
#answer { position: relative; flex: 1 1 220px; }
#view { display: flex; flex-basis: 100%; flex-wrap: wrap; gap: .35rem .75rem; }
#view .chips { gap: .35rem; }

#progress { flex-basis: 100%; height: 3px; overflow: hidden; border-radius: 2px; background: var(--line); }
#progress span {
  display: block;
  height: 100%;
  background: var(--good);
  transform: scaleX(var(--done, 0));
  transform-origin: left;
  transition: transform var(--settle) var(--spring);
}

#input {
  width: 100%;
  padding: .6rem .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
  transition: border-color .15s ease-out, box-shadow .2s ease-out;
}
#input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(26, 159, 232, .3); }
#input.shake { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(239, 90, 95, .3); animation: shake .24s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(4px); } }

#score, #timer { font-size: 1.1rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
#timer { color: var(--dim); }

#status {
  position: absolute;
  top: 50%;
  right: .6rem;
  max-width: 60%;
  margin: 0;
  padding: 0 .25rem;
  overflow: hidden;
  background: var(--panel);
  color: var(--dim);
  font-size: .8rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
  translate: 0 -50%;
  transition: color .15s ease-out;
}
#status[data-kind="good"] { color: var(--good); }
#status[data-kind="bad"] { color: var(--bad); }
#status[data-kind="special"] { color: var(--gold); font-weight: 700; }

#result {
  padding: 1.75rem 1.5rem;
  margin: .75rem 0 1rem;
  border-radius: 14px;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 12px 36px var(--shadow);
  transition: opacity .3s ease-out, filter .3s ease-out, transform var(--settle) var(--spring);
}
@starting-style {
  #result { opacity: 0; filter: blur(8px); transform: scale(.96); }
}
#result h2 { margin: 0; font-size: 1.9rem; line-height: 1.15; letter-spacing: -.02em; }
#result p { margin: .35rem 0 1.1rem; color: var(--dim); }
#statsSummary:not([hidden]) { margin: 1rem 0 0; font-size: .875rem; }
#stats { margin-top: .75rem; text-align: left; }
#stats summary { cursor: pointer; color: var(--accent); font-size: .875rem; font-weight: 700; text-align: center; }
#stats table { width: 100%; margin-top: .6rem; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
#stats th { color: var(--dim); font-size: .75rem; font-weight: 600; text-align: left; }
#stats th, #stats td { padding: .3rem .4rem; border-bottom: 1px solid var(--line); }
#stats td img { width: 1.6rem; height: 1.6rem; margin-right: .4rem; border-radius: 6px; object-fit: cover; object-position: 50% 15%; vertical-align: middle; }
#stats tr.special td { color: var(--gold); font-weight: 700; }
#again { margin-right: .25rem; background: var(--accent); border-color: transparent; color: #fff; }

#board details { margin-bottom: .9rem; }
#board details::details-content {
  block-size: 0;
  overflow: hidden;
  transition: block-size .3s ease-out, content-visibility .3s allow-discrete;
}
#board details[open]::details-content { block-size: auto; }
#board summary { display: block; cursor: pointer; list-style: none; touch-action: manipulation; user-select: none; -webkit-tap-highlight-color: transparent; }
#board summary::-webkit-details-marker { display: none; }
#board h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  margin: 0 0 .4rem;
  padding: .6rem;
  border-radius: var(--radius);
  background: var(--school);
  color: #fff;
  font-size: 1.2rem;
  letter-spacing: -.01em;
  transition: transform var(--settle) var(--spring);
}
#board summary:active h2 { transform: scale(.99); transition-duration: 100ms; transition-timing-function: ease-out; }
#board h2::after { content: '▾'; transition: rotate .2s ease-out; }
#board details:not([open]) h2 { margin-bottom: 0; }
#board details:not([open]) h2::after { rotate: -90deg; }
#board h2 img { height: 1.9rem; }
#board h2 span { font-size: .9rem; font-weight: 600; font-variant-numeric: tabular-nums; opacity: .9; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: .4rem; }

.tile {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: center;
  transition: border-color .2s ease-out, box-shadow .2s ease-out;
}
.face { background: var(--photo-bg); }
.face:has(img.blank) { background: none; }
.face img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  object-position: 50% 15%;
  transition: filter .35s ease-out, opacity .35s ease-out;
}
.face img.cutout, .face img.shadow, .face img.blank { object-fit: contain; }
.face img.blank { padding: 20%; opacity: .5; filter: brightness(0) invert(.55); }
.face img.shadow { filter: brightness(0); }
.tile small {
  display: block;
  margin-top: .25rem;
  padding: 0 .25rem;
  color: var(--dim);
  font-size: .75rem;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile b { display: block; padding: 0 .25rem .35rem; color: var(--faint); font-size: 1.05rem; font-weight: 800; transition: color .2s ease-out; }

.band { display: block; font-size: .9rem; font-style: italic; font-weight: 800; letter-spacing: .02em; }
.band.STRIKER { background: #ffdede; color: #e23b35; }
.band.SPECIAL { background: #cfe2f5; color: #1673d6; }
.band.NPC { background: #d9dce3; color: #4a5160; }

.hide-label .tile:not(.found, .missed) :is(small, .band) { visibility: hidden; }

.tile.found { border-color: var(--good); box-shadow: 0 0 0 1px var(--good); animation: found .3s ease-out; }
.tile.found b { color: var(--text); }
.family { display: block; color: var(--dim); font-size: .7em; font-weight: 600; }
.tile.special {
  position: relative;
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 14px color-mix(in srgb, var(--gold) 55%, transparent);
  animation: special .6s ease-out;
}
.tile.special b, .tile.special .family { color: var(--gold); }
.tile.special::before { content: '✦'; position: absolute; top: .15rem; right: .3rem; z-index: 1; color: var(--gold); text-shadow: 0 0 6px var(--panel); }
.tile.special::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 40%, rgba(255, 255, 255, .75) 50%, transparent 60%);
  pointer-events: none;
  translate: 100% 0;
  animation: shine .9s ease-out;
}
.tile.missed { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
.tile.missed b { color: var(--bad); }
@keyframes found { 40% { transform: scale(1.04); } }
@keyframes special { 40% { transform: scale(1.08); } }
@keyframes shine { from { translate: -100% 0; } to { translate: 100% 0; } }

#stage { display: flex; justify-content: center; }
#stage .tile { width: min(320px, 80vw, 42dvh); transition: border-color .2s ease-out, box-shadow .2s ease-out, opacity .2s ease-out, transform var(--settle) var(--spring); }
@starting-style {
  #stage .tile { opacity: 0; transform: scale(.97); }
}
#stage .tile b { font-size: 1.6rem; }
#stage .tile small { font-size: .85rem; }

#choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; max-width: 480px; margin: .75rem auto 0; }
#choices button { min-height: 3.25rem; padding: .6rem .5rem; font-size: 1.05rem; }
#choices .right { border-color: var(--good); background: var(--good); color: light-dark(#fff, #0c2417); }
#choices .wrong { border-color: var(--bad); background: var(--bad); color: #fff; }

footer { padding: 1.25rem; color: var(--dim); font-size: .8rem; text-align: center; }
footer p { margin: .15rem 0; }
footer a { color: inherit; }

@media (hover: none) {
  #wall::after { animation: roam 16s ease-in-out infinite; }
}

@media (pointer: coarse) {
  .chip span { padding: .6rem .95rem; }
  button { min-height: 2.5rem; }
  #view .chip span { padding: .3rem .65rem; }
}

@media (max-width: 640px) {
  :root { --wall-tile: 84px; --pad: 1rem; }

  #themeLabel { display: none; }
  #theme { top: .55rem; right: .5rem; }

  .hero { padding: 3rem 1rem 1.5rem; }
  #howTo { padding: 1.1rem; }
  .how-demo .tile, .how-gold .tile { width: 4.75rem; }
  .logo { width: 4rem; }
  #setup { margin-inline: .6rem; }

  #game { padding: 0 .5rem 1.5rem; }
  #bar { margin-inline: -.5rem; padding: .55rem .5rem .45rem; gap: .35rem .5rem; }
  #answer { flex: 0 0 calc(100% - 3rem); } /* 오른쪽 위 테마 버튼 자리를 비운다. */
  #score, #timer { font-size: .95rem; }
  #bar button { min-height: 2.1rem; padding: .2rem .6rem; font-size: .85rem; }
  #view { gap: .3rem; }
  #view .chips { flex: 1 1 100%; flex-wrap: nowrap; gap: .3rem; }
  #view .chip { flex: 1 1 auto; }
  #view .chip span { text-align: center; white-space: nowrap; }

  #board details { margin-bottom: .6rem; }
  #board h2 { gap: .4rem; padding: .35rem; font-size: 1rem; }
  #board h2 img { height: 1.4rem; }
  #board h2 span { font-size: .8rem; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: .25rem; }
  .tile { border-radius: 8px; }
  .tile small { margin-top: .1rem; font-size: .6rem; }
  .tile b { padding: 0 .15rem .2rem; font-size: .75rem; line-height: 1.2; overflow-wrap: anywhere; }
  .band { font-size: .6rem; letter-spacing: 0; }
  .face img.blank { padding: 24%; }
  #stats table { font-size: .75rem; }
  #stats th, #stats td { padding: .25rem .2rem; }
  #stats td img { width: 1.3rem; height: 1.3rem; margin-right: .25rem; }
  #stage .band { font-size: .9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition-property: opacity, color, background-color, border-color !important;
    transition-duration: 150ms !important;
  }
  button:active, .chip:active span { transform: none !important; }
}

@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  :root { --glass: var(--bg); }
}

@media (prefers-contrast: more) {
  :root { --line: light-dark(#6b7280, #8a93a3); --dim: light-dark(#3f4754, #d0d5de); }
}
