@font-face { font-family: "Jua"; src: url(fonts/jua-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; font-display: swap; }
@font-face { font-family: "Jua"; src: url(fonts/jua-korean-400-normal.woff2) format("woff2"); font-display: swap; }

:root {
  --bg: #fffaf1;
  --panel: #ffffff;
  --ink: #2c2a3a;
  --muted: #7a7690;
  --line: #e8e1d3;
  --blue: #4f7fc1;
  --blue-dark: #355d99;
  --green: #8fd14f;
  --purple: #7b3fb5;
  --accent: #ff8a3d;
  --chip: #f3eee4;
  --shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
  --t1: #ff6b6b; --t2: #4dabf7; --t3: #51cf66; --t4: #fcc419;
  --t5: #cc5de8; --t6: #ff922b; --t7: #20c997; --t8: #f06595;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Jua", "Malgun Gothic", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

.btn {
  border: 0; border-radius: 14px; padding: 12px 22px;
  background: var(--blue); color: #fff; font-size: 1.1rem;
  box-shadow: var(--shadow); transition: transform 0.08s;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.big { font-size: 1.4rem; padding: 14px 30px; }
.btn.small { font-size: 1rem; padding: 8px 16px; }
.btn.ghost { background: var(--panel); color: var(--ink); border: 2px solid var(--line); }
.btn.accent { background: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- 설정 ---------- */
#setup { max-width: 1200px; margin: 0 auto; padding: 24px 16px 60px; }
.setup-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 2.2rem; font-weight: 400; }
h1 span { color: var(--blue); }
.sub { margin: 6px 0 0; color: var(--muted); }
.start-box { display: flex; gap: 10px; }
.toolbar {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 18px 0; padding: 12px; background: var(--panel); border: 2px solid var(--line); border-radius: 16px;
  position: sticky; top: 8px; z-index: 5;
}
.quick, .opts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.opts label { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--chip); border-radius: 10px; }
.opts select { font: inherit; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--blue); }

.cat { margin-bottom: 22px; }
.cat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 1.35rem; }
.cat-head label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.cat-head .n { color: var(--muted); font-size: 1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.job {
  position: relative; display: flex; flex-direction: column; background: var(--panel);
  border: 3px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
}
.job:hover { transform: translateY(-2px); }
.job.on { border-color: var(--blue); }
.job input { position: absolute; top: 8px; left: 8px; }
.job img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--chip); display: block; }
.job .nm { padding: 6px 10px 8px; line-height: 1.2; }
.job .en { font-size: 1.1rem; }
.job .ko { color: var(--muted); font-size: 0.9rem; }
.job .tag { position: absolute; top: 8px; right: 8px; background: var(--accent); color: #fff; font-size: 0.75rem; padding: 2px 6px; border-radius: 6px; }
.job:not(.on) img { filter: grayscale(0.6) opacity(0.65); }

/* ---------- 규칙 ---------- */
#rules, #end { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.rules-card, .end-card { background: var(--panel); border-radius: 24px; padding: 28px 40px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08); max-width: 960px; width: 100%; }
.rules-card h2, .end-card h2 { text-align: center; font-size: 3.2rem; color: var(--blue-dark); margin: 0 0 10px; font-weight: 400; }
.rules-card ol { font-size: clamp(1.4rem, 3vw, 2.2rem); line-height: 1.5; margin: 0 0 20px; }
.rules-card small { font-size: 0.55em; color: var(--muted); margin-left: 6px; }
.rules-card em { color: #e03131; font-style: normal; }
.rules-card .pts { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.rules-card .pts b { color: var(--blue); }
.rules-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- 선생님 정답표 ---------- */
.sheet-box { position: fixed; inset: 0; z-index: 30; background: rgba(30, 28, 45, 0.6); display: grid; place-items: center; padding: 16px; }
.sheet-card { background: var(--panel); border-radius: 24px; padding: 22px 28px; text-align: center; max-width: 440px; width: 100%; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); }
.sheet-card h3 { margin: 0 0 8px; font-size: 1.6rem; font-weight: 400; }
.sheet-card canvas { width: min(300px, 70vw) !important; height: auto !important; max-height: 52vh; aspect-ratio: 1; image-rendering: pixelated; }
.sheet-card p { margin: 8px 0 14px; color: var(--muted); }
.sheet-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.sheet-btns a { text-decoration: none; }
.end-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

/* ---------- 문제 ---------- */
#quiz { height: 100vh; display: flex; flex-direction: column; padding: 2.2vh 2.5vw; gap: 1.8vh; }
.q-top { display: flex; gap: 2vw; align-items: stretch; flex: 0 0 auto; }
.q-text { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.q-text h2 { margin: 0; font-weight: 400; font-size: clamp(2rem, 6vh, 4.6rem); line-height: 1.1; }
.q-line { margin: 0.6vh 0 0; font-size: clamp(2rem, 6vh, 4.6rem); line-height: 1.2; }
.blank { display: inline-block; min-width: 5.5em; border-bottom: 0.08em solid var(--ink); text-align: center; }
.blank span { color: var(--purple); display: inline-block; }
.blank.show span { animation: pop 0.45s ease-out; }
.q-ko { margin: 0.4vh 0 0; font-size: clamp(1.2rem, 3.6vh, 2.4rem); color: var(--purple); min-height: 1.2em; }
.pic {
  flex: 0 0 auto; height: 30vh; aspect-ratio: 4 / 3; padding: 0; border: 0; border-radius: 20px; overflow: hidden;
  position: relative; background: linear-gradient(135deg, #8ec5fc, #e0c3fc); box-shadow: var(--shadow);
}
.pic-q { position: absolute; inset: 0; display: grid; place-items: center; font-size: 18vh; color: #fff; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.15); }
.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transform: scale(1.08); transition: opacity 0.4s, transform 0.5s; }
.pic.show img { opacity: 1; transform: none; }

.zoom { position: fixed; inset: 0; z-index: 20; background: rgba(30, 28, 45, 0.75); display: grid; place-items: center; cursor: zoom-out; }
.zoom img { max-width: 92vw; max-height: 88vh; border-radius: 24px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4); animation: pop 0.35s ease-out; }

.clues { flex: 1; min-height: 0; display: grid; grid-template-rows: repeat(4, 1fr); gap: 1.5vh; padding: 0 6vw; }
.clue {
  position: relative; border: 3px solid var(--blue-dark); border-radius: 18px; background: var(--blue);
  color: var(--green); font-size: clamp(1.6rem, 5.6vh, 4rem); display: flex; align-items: center; justify-content: center;
  padding: 0 1.2em; box-shadow: var(--shadow); transition: background 0.2s;
}
.clue .face { display: block; }
.clue.open { background: #fff; color: var(--ink); border-color: var(--blue); cursor: default; }
.clue.open .face { animation: flip 0.35s ease-out; }
.clue .badge { position: absolute; left: 0.5em; top: 50%; transform: translateY(-50%); font-size: 0.45em; background: var(--blue); color: #fff; border-radius: 10px; padding: 0.15em 0.5em; display: none; }
.clue.open .badge { display: block; }
.clue.now { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255, 138, 61, 0.35); }

.q-bottom { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; flex: 0 0 auto; }
.teams { display: flex; gap: 8px; flex-wrap: wrap; }
.team {
  border: 0; border-radius: 14px; padding: 6px 14px; color: #fff; font-size: clamp(1rem, 2.6vh, 1.6rem);
  box-shadow: var(--shadow); display: flex; align-items: baseline; gap: 8px; position: relative;
}
.team b { font-size: 1.3em; font-weight: 400; }
.team.won { outline: 4px solid var(--ink); }
.team .plus { position: absolute; top: -1.4em; left: 50%; transform: translateX(-50%); color: var(--accent); font-size: 1.2em; animation: rise 0.9s ease-out forwards; }
.nav { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.nav .btn.small { padding: 8px 12px; }
.progress { color: var(--muted); font-size: 1.2rem; margin-right: 6px; }

/* ---------- 결과 ---------- */
.end-card h2 span { display: inline-block; animation: pop 0.6s ease-out; }
.ranking { display: grid; gap: 10px; margin: 10px auto; max-width: 560px; }
.rank { display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-radius: 16px; color: #fff; font-size: 1.8rem; box-shadow: var(--shadow); }
.rank .medal { width: 1.6em; text-align: center; }
.rank .sc { margin-left: auto; }
.ranking .none { text-align: center; font-size: 1.6rem; color: var(--muted); }

@keyframes pop { 0% { transform: scale(0.3); opacity: 0; } 70% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }
@keyframes flip { 0% { transform: rotateX(90deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes rise { 0% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -1.2em); } }

@media (max-width: 760px) {
  #quiz { height: auto; min-height: 100vh; }
  .q-top { flex-direction: column; }
  .pic { height: auto; width: 100%; }
  .clues { padding: 0; grid-template-rows: none; }
  .clue { min-height: 64px; font-size: 1.4rem; }
  .rules-card { padding: 20px; }
  .rules-card .pts { grid-template-columns: 1fr; }
}
