/* ===== 짝꿍 매칭 게임 — 알록달록 테마 ===== */
:root {
  --ink: #1f2340;
  --ink-soft: #4a4f73;
  --bg1: #fff4d6;
  --bg2: #e3f1ff;
  --white: #ffffff;
  --red: #ff5a5f;
  --orange: #ff9f1c;
  --yellow: #ffd23f;
  --green: #2ec4b6;
  --lime: #8ac926;
  --blue: #3a86ff;
  --purple: #8338ec;
  --pink: #ff4fa3;
  --line: #e4e6f2;
  --radius: 18px;
  --shadow: 0 6px 0 rgba(31, 35, 64, .12), 0 10px 24px rgba(31, 35, 64, .10);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Noto Sans KR', system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1) 0%, #ffe9f3 45%, var(--bg2) 100%) fixed;
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, .jua, button, .btn { font-family: 'Jua', 'Noto Sans KR', sans-serif; font-weight: 400; }
h1 { font-size: clamp(30px, 6vw, 52px); margin: 0 0 6px; }
h2 { font-size: clamp(24px, 4vw, 34px); margin: 0 0 12px; }
h3 { font-size: 22px; margin: 0 0 8px; }
p { line-height: 1.55; }
input, textarea, select { font: inherit; color: var(--ink); }

#app { min-height: 100dvh; }

/* ---------- 버튼 ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  font-size: 20px; line-height: 1.1;
  padding: 14px 22px; border-radius: 16px;
  background: var(--blue); color: #fff;
  box-shadow: 0 5px 0 rgba(0,0,0,.18);
  transition: transform .08s, box-shadow .08s, filter .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.btn:disabled { background: #b9bccf !important; color: #fff !important; cursor: not-allowed; transform: none; box-shadow: 0 5px 0 rgba(0,0,0,.08); }
.btn.big { font-size: 26px; padding: 18px 32px; border-radius: 20px; }
.btn.small { font-size: 16px; padding: 9px 14px; border-radius: 12px; box-shadow: 0 3px 0 rgba(0,0,0,.18); }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.orange { background: var(--orange); }
.btn.purple { background: var(--purple); }
.btn.pink { background: var(--pink); }
.btn.yellow { background: var(--yellow); color: var(--ink); }
.btn.white { background: #fff; color: var(--ink); border: 2px solid var(--line); }
.btn.ghost { background: rgba(255,255,255,.7); color: var(--ink); box-shadow: none; border: 2px solid rgba(31,35,64,.12); }

/* ---------- 공통 레이아웃 ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 16px 16px 48px; }
.card-box {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 18px;
}
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }
.empty {
  text-align: center; padding: 40px 16px; color: var(--ink-soft);
  background: rgba(255,255,255,.7); border-radius: var(--radius); border: 3px dashed #d4d7ea;
}

/* ---------- 상단 바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: rgba(255,255,255,.88); backdrop-filter: blur(8px);
  border-bottom: 3px solid rgba(31,35,64,.06);
}
.logo { font-family: 'Jua', sans-serif; font-size: 24px; display: flex; align-items: center; gap: 6px; color: var(--ink); white-space: nowrap; }
.me-badge {
  border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--pink), var(--orange));
  color: #fff; font-size: 20px; padding: 10px 16px; border-radius: 999px;
  box-shadow: 0 4px 0 rgba(0,0,0,.15);
  max-width: 60vw; overflow: hidden; text-overflow: ellipsis;
}
.me-badge small { font-size: 15px; opacity: .95; margin-left: 4px; }

/* ---------- 시작 화면 ---------- */
.hero { text-align: center; padding: 28px 12px 10px; }
.hero .bounce { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
.num-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  max-width: 980px; margin: 18px auto;
}
.num-btn {
  border: 0; cursor: pointer; border-radius: 20px; aspect-ratio: 1 / 1;
  color: #fff; font-family: 'Jua', sans-serif; font-size: 34px;
  box-shadow: 0 6px 0 rgba(0,0,0,.18);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform .08s;
  padding: 6px;
}
.num-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.num-btn .nm { font-family: 'Noto Sans KR', sans-serif; font-weight: 700; font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.teacher-door { position: fixed; right: 14px; bottom: 14px; z-index: 30; }
@media (max-width: 520px) {
  .num-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 9px; }
  .num-btn { font-size: 26px; border-radius: 16px; }
}

/* ---------- 학생 게임 목록 ---------- */
.game-list { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.game-tile {
  border: 0; cursor: pointer; text-align: left;
  border-radius: 22px; padding: 20px; color: #fff; min-height: 150px;
  box-shadow: 0 7px 0 rgba(0,0,0,.16);
  display: flex; flex-direction: column; gap: 8px;
  transition: transform .1s;
}
.game-tile:hover { transform: translateY(-3px) rotate(-.5deg); }
.game-tile:active { transform: translateY(4px); }
.game-tile .t { font-family: 'Jua', sans-serif; font-size: 27px; line-height: 1.2; word-break: keep-all; overflow-wrap: anywhere; }
.game-tile .meta { font-size: 16px; font-weight: 700; opacity: .95; }
.game-tile .best { margin-top: auto; background: rgba(255,255,255,.95); color: var(--ink); border-radius: 12px; padding: 8px 12px; font-weight: 700; font-size: 16px; }

/* ---------- 표 ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 17px; }
.tbl th { background: #f3f4fb; color: var(--ink); text-align: left; padding: 10px 12px; font-family: 'Jua', sans-serif; font-weight: 400; font-size: 18px; white-space: nowrap; }
.tbl th:first-child { border-radius: 12px 0 0 12px; }
.tbl th:last-child { border-radius: 0 12px 12px 0; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.best td { background: #fff7d1; font-weight: 700; }
.tbl tr.sub td { color: var(--ink-soft); font-size: 15px; }
.tbl tr.me td { background: #ffe1ef; font-weight: 900; }
.tag { display: inline-block; font-size: 13px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--yellow); color: var(--ink); white-space: nowrap; }
.tag.blue { background: #d6e6ff; }
.tag.green { background: #ccf3ee; }

/* ---------- 게임 화면 ---------- */
.game-screen { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.game-top {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; min-height: 44px;
  background: rgba(255,255,255,.9); border-bottom: 2px solid rgba(31,35,64,.06);
}
.game-top .exit { border: 0; background: #eef0fa; color: var(--ink); font-size: 18px; width: 34px; height: 34px; border-radius: 10px; cursor: pointer; flex: none; }
.game-top .gtitle { font-family: 'Jua', sans-serif; font-size: 17px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.chips { display: flex; gap: 6px; align-items: center; flex: none; }
.chip { font-family: 'Jua', sans-serif; font-size: 15px; padding: 5px 10px; border-radius: 999px; color: #fff; white-space: nowrap; animation: chipIn .25s ease-out; }
.chip.combo { background: var(--pink); }
.chip.speed { background: var(--orange); }
.chip.score { background: var(--purple); font-size: 17px; padding: 6px 12px; min-width: 64px; text-align: center; }
.chip.score.bump { animation: bump .35s ease-out; }
@keyframes chipIn { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); background: var(--green); } 100% { transform: scale(1); } }

.test-banner {
  flex: none; background: repeating-linear-gradient(45deg, #ffe066, #ffe066 14px, #ffd23f 14px, #ffd23f 28px);
  color: #3a2a00; font-family: 'Jua', sans-serif; text-align: center; font-size: 17px; padding: 6px 10px;
}
.speedbar { flex: none; height: 5px; background: transparent; }
.speedbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--orange), var(--yellow)); transform-origin: left; }

.board-wrap { flex: 1; min-height: 0; position: relative; }
.board {
  position: absolute; inset: 0; overflow: auto;
  display: grid; padding: 10px;
  justify-content: center; align-content: center;
}
.board.scroll { align-content: start; }
.board.shake { animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-12px); } 40% { transform: translateX(10px); }
  60% { transform: translateX(-7px); } 80% { transform: translateX(5px); }
}

.mcard {
  position: relative; border: 0; cursor: pointer; padding: 0;
  border-radius: 16px; background: #fff; color: var(--ink);
  box-shadow: 0 5px 0 rgba(31,35,64,.14), 0 8px 16px rgba(31,35,64,.08);
  transition: transform .1s, box-shadow .1s, opacity .3s;
  border: 4px solid transparent; overflow: hidden;
}
.mcard.k-term { background: #fffaf0; border-color: #ffe2a8; }
.mcard.k-ans  { background: #f2f8ff; border-color: #c9defd; }
.mcard:hover { transform: translateY(-2px); }
.mcard .txt {
  position: absolute; inset: 6px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.mcard .txt > span {
  display: block; max-width: 100%; text-align: center;
  font-weight: 700; line-height: 1.2;
  word-break: keep-all; overflow-wrap: anywhere;
}
.mcard.sel { border-color: var(--purple); background: #efe4ff; transform: translateY(-4px) scale(1.03); box-shadow: 0 8px 0 rgba(131,56,236,.35); }
.mcard.wrong { border-color: var(--red); background: #ffe3e3; animation: wiggle .35s; }
.mcard.right { border-color: var(--green); background: #d9fbf6; animation: popOut .5s ease-in forwards; pointer-events: none; }
.mcard.gone { visibility: hidden; pointer-events: none; }
.mcard.hint { animation: hintShake 1.2s ease-in-out infinite; border-color: var(--yellow); }
.mcard .hint-ico {
  position: absolute; top: 2px; right: 4px; font-size: 18px; z-index: 2;
  animation: glow 1s ease-in-out infinite alternate;
}
.mcard .hint-letter {
  position: absolute; left: 4px; bottom: 3px; right: 4px; z-index: 2;
  font-family: 'Jua', sans-serif; font-size: 13px; color: #6b4e00;
  background: #fff3b0; border-radius: 8px; padding: 1px 6px; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
@keyframes hintShake { 0%,60%,100% { transform: rotate(0); } 10% { transform: rotate(-4deg) scale(1.03); } 20% { transform: rotate(4deg) scale(1.03); } 30% { transform: rotate(-3deg); } 40% { transform: rotate(2deg); } }
@keyframes glow { from { transform: scale(1); filter: drop-shadow(0 0 0 #ffd23f); } to { transform: scale(1.25); filter: drop-shadow(0 0 6px #ffd23f); } }
@keyframes popOut { 0% { transform: scale(1); opacity: 1; } 40% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(.2); opacity: 0; } }

.start-panel {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto;
}
.start-panel .inner { background: #fff; color: var(--ink); border-radius: 26px; box-shadow: var(--shadow); padding: 26px; max-width: 560px; width: 100%; text-align: center; }
.rules { text-align: left; background: #f6f7fd; border-radius: 14px; padding: 12px 16px; margin: 14px 0 18px; font-size: 16px; color: var(--ink); }
.rules li { margin: 4px 0; }

/* 떠오르는 효과 */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.float-pts {
  position: fixed; font-family: 'Jua', sans-serif; font-size: 30px; color: var(--green);
  text-shadow: 0 2px 0 #fff, 0 0 8px #fff; animation: floatUp 1s ease-out forwards; transform: translate(-50%, -50%);
}
.float-pts.neg { color: var(--red); }
@keyframes floatUp { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -70px; } }
.combo-pop {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%);
  font-family: 'Jua', sans-serif; font-size: clamp(34px, 8vw, 72px); white-space: nowrap;
  color: #fff; -webkit-text-stroke: 2px rgba(31,35,64,.25);
  text-shadow: 0 5px 0 rgba(0,0,0,.18);
  animation: comboPop .9s cubic-bezier(.2,1.4,.4,1) forwards;
}
.combo-pop.speed { top: 56%; font-size: clamp(26px, 6vw, 48px); }
.combo-pop.reset { font-size: clamp(22px, 5vw, 38px); color: var(--red); -webkit-text-stroke: 0; text-shadow: 0 2px 0 #fff, 0 0 10px #fff; }
@keyframes comboPop {
  0% { transform: translate(-50%, -50%) scale(.3) rotate(-8deg); opacity: 0; }
  30% { transform: translate(-50%, -50%) scale(1.15) rotate(3deg); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(.95); opacity: 0; }
}
.confetti { position: fixed; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* 결과 화면 */
.result { text-align: center; }
.result .score-big { font-family: 'Jua', sans-serif; font-size: clamp(40px, 9vw, 80px); color: var(--purple); margin: 8px 0; }
.result .combo-line { font-family: 'Jua', sans-serif; font-size: clamp(22px, 4vw, 32px); color: var(--pink); }
.lb { list-style: none; padding: 0; margin: 0; text-align: left; }
.lb li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 14px; margin-bottom: 6px; background: #f6f7fd; font-size: 19px; color: var(--ink); }
.lb li .rk { font-family: 'Jua', sans-serif; width: 56px; flex: none; }
.lb li .sc { margin-left: auto; font-weight: 900; }
.lb li.me { background: linear-gradient(90deg, #ffd6ea, #fff1c2); outline: 3px solid var(--pink); }
.notice { background: #fff3c4; color: #4a3900; border-radius: 14px; padding: 14px; font-weight: 700; }

/* ---------- 교사 화면 ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { border: 0; cursor: pointer; font-size: 18px; padding: 10px 14px; border-radius: 12px; background: #eef0fa; color: var(--ink); }
.tab.on { background: var(--purple); color: #fff; }
.teacher-game {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 14px; border-radius: 16px; background: #fff; border: 2px solid var(--line); margin-bottom: 10px;
}
.teacher-game .info { flex: 1 1 240px; min-width: 0; }
.teacher-game .info .t { font-family: 'Jua', sans-serif; font-size: 22px; word-break: keep-all; overflow-wrap: anywhere; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-family: 'Jua', sans-serif; font-size: 19px; margin-bottom: 6px; }
.input, .textarea, .select {
  width: 100%; border: 3px solid #dfe2f1; border-radius: 14px; padding: 12px 14px; background: #fff; color: var(--ink); font-size: 18px; outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--blue); }
.textarea { min-height: 180px; resize: vertical; line-height: 1.6; font-family: 'Noto Sans KR', monospace; }
.textarea.names { min-height: 320px; }
.parse-status { font-weight: 700; padding: 8px 12px; border-radius: 12px; display: inline-block; }
.parse-status.ok { background: #d6f7ef; color: #0c5c4f; }
.parse-status.bad { background: #ffe0e0; color: #8a1116; }
.parse-status.warn { background: #fff1c2; color: #5b4300; }
.errlist { margin: 8px 0 0; padding-left: 20px; color: #a1141a; font-weight: 700; }

.edit-tbl td { padding: 4px 6px; }
.cell-input {
  width: 100%; border: 2px solid transparent; background: transparent; border-radius: 10px;
  padding: 8px 10px; font-size: 17px; color: var(--ink); min-width: 120px;
}
.cell-input:hover { background: #f4f6ff; }
.cell-input:focus { border-color: var(--blue); background: #fff; outline: none; }
.cell-input.empty-cell { background: #fff0f0; border-color: #ffb3b3; }
.edit-tbl tr.err td { background: #fff0f0; color: #8a1116; }
.del-btn { border: 0; cursor: pointer; width: 36px; height: 36px; border-radius: 10px; background: #ffe3e3; color: #b3141b; font-size: 18px; font-weight: 900; }
.del-btn:hover { background: var(--red); color: #fff; }

.chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 70px; gap: 10px; align-items: center; font-size: 16px; }
.bar-row .lbl { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar { height: 30px; border-radius: 10px; background: #f0f1f8; overflow: hidden; }
.bar-row .bar > i { display: block; height: 100%; border-radius: 10px; transition: width .6s cubic-bezier(.2,1,.3,1); }
.bar-row .val { font-weight: 900; text-align: right; }
@media (max-width: 560px) { .bar-row { grid-template-columns: 96px 1fr 56px; font-size: 14px; } }

.seg { display: inline-flex; background: #eef0fa; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; cursor: pointer; padding: 8px 12px; border-radius: 9px; background: transparent; color: var(--ink); font-size: 16px; }
.seg button.on { background: #fff; color: var(--purple); box-shadow: 0 2px 6px rgba(0,0,0,.1); }

.saved-ind { font-weight: 700; color: #0c7a68; font-size: 16px; }

/* ---------- 팝업 (항상 뚜렷한 대비) ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 22, 45, .62);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fadeIn .15s;
}
.modal {
  background: #ffffff; color: #1f2340;
  border-radius: 24px; padding: 24px; width: 100%; max-width: 460px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); border: 4px solid #1f2340;
  animation: modalIn .22s cubic-bezier(.2,1.3,.4,1);
  max-height: calc(100dvh - 32px); overflow: auto;
}
.modal, .modal * { color: #1f2340; }
.modal h3 { font-size: 26px; margin: 0 0 10px; color: #1f2340; }
.modal p { font-size: 18px; margin: 0 0 14px; color: #2b2f52; }
.modal .input { border-color: #9aa0c7; background: #fff; color: #1f2340; font-size: 24px; letter-spacing: 6px; text-align: center; }
.modal .err { color: #c4121a !important; font-weight: 900; min-height: 24px; margin: 8px 0 0; font-size: 17px; }
.modal .btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.modal .btn { color: #ffffff; }
.modal .btn.white { color: #1f2340; background: #eef0fa; border: 2px solid #c9cde4; }
.modal .btn.yellow { color: #1f2340; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* 토스트 */
#toast-root { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1f2340; color: #ffffff; padding: 12px 18px; border-radius: 14px; font-weight: 700; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: fadeIn .2s; max-width: 90vw; text-align: center; }
.toast.bad { background: #c4121a; }

.spinner { width: 36px; height: 36px; border: 5px solid #e1e3f3; border-top-color: var(--purple); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
