:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1d2433;
  --muted: #6b7488;
  --brand: #4f6df5;
  --brand-dark: #3a53d0;
  --ok: #1fa971;
  --warn: #f08c00;
  --bad: #e03131;
  --line: #dfe4f0;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Pretendard', 'Malgun Gothic', 'Apple SD Gothic Neo', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { height: 16px; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 18px; }
.narrow { max-width: 560px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 10px rgba(30, 50, 100, .08);
  margin-bottom: 16px;
}

.btn {
  border: 0;
  background: var(--brand);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { background: #b7bfd6; cursor: not-allowed; }
.btn.sec { background: #e8ecf8; color: var(--ink); }
.btn.sec:hover { background: #d9dff2; }
.btn.ok { background: var(--ok); }
.btn.bad { background: var(--bad); }
.btn.warn { background: var(--warn); }
.btn.big { font-size: 1.3em; padding: 14px 28px; border-radius: 14px; }
.btn.small { padding: 5px 10px; font-size: .85em; border-radius: 8px; }

input[type=text], input[type=password], input[type=number], select, textarea {
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
textarea { width: 100%; min-height: 110px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-weight: 700; margin-bottom: 4px; }

.msg { padding: 10px 14px; border-radius: 10px; margin: 10px 0; }
.msg.err { background: #ffe3e3; color: #a51111; }
.msg.info { background: #e7f0ff; color: #1b3d99; }
.msg.ok { background: #d3f9e5; color: #0b6b43; }

/* 아바타 */
.av {
  width: 56px; height: 56px; border-radius: 50%;
  object-fit: cover; background: #dde3f3; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; color: #3a4463; font-size: 22px;
}
.av.lg { width: 120px; height: 120px; font-size: 52px; }
.av.xl { width: 220px; height: 220px; font-size: 96px; }
.av.sm { width: 40px; height: 40px; font-size: 16px; }

/* 학생 카드 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.person {
  background: #fff; border: 3px solid transparent; border-radius: 14px;
  padding: 10px 6px; text-align: center; cursor: default;
  box-shadow: 0 1px 6px rgba(30, 50, 100, .1);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-weight: 700; word-break: keep-all;
}
button.person { cursor: pointer; font-family: inherit; font-size: inherit; color: inherit; }
button.person:hover { border-color: #b9c5fb; }
.person.sel { border-color: var(--brand); background: #eef1ff; }
.person.off { opacity: .45; }
.person small { color: var(--muted); font-weight: 400; }
.person .av { width: 84px; height: 84px; font-size: 34px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; background: #e8ecf8; font-size: .85em; margin: 2px; }
.pill.on { background: var(--brand); color: #fff; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .85em; }

/* 상단 바 */
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: 10px 18px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.topbar a { padding: 8px 14px; border-radius: 10px; text-decoration: none; color: var(--ink); font-weight: 700; }
.topbar a.on { background: var(--brand); color: #fff; }

/* 학생 화면 */
.s-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.opt { display: block; width: 100%; text-align: left; border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 14px; margin: 6px 0; cursor: pointer; font-size: 1em; }
.opt.on { border-color: var(--brand); background: #eef1ff; font-weight: 800; }
.qbox { margin-bottom: 22px; }
.qbox h3 { font-size: 1.1em; }

.big-timer { font-size: 3.2em; font-weight: 900; text-align: center; color: var(--brand); }
.big-timer.low { color: var(--bad); }

/* 진행 화면(큰 화면) */
.stage-title { font-size: 2.6em; font-weight: 900; text-align: center; margin: 4px 0 14px; }
.feats { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.feat {
  background: #fff; border: 4px solid transparent; border-radius: 18px; padding: 18px 20px;
  box-shadow: 0 2px 10px rgba(30, 50, 100, .1); text-align: left; font-family: inherit; color: inherit;
}
button.feat { cursor: pointer; }
button.feat:hover { border-color: #b9c5fb; }
.feat.sel { border-color: var(--brand); background: #eef1ff; }
.feat .q { color: var(--muted); font-size: 1.05em; }
.feat .a { font-size: 1.9em; font-weight: 900; margin: 2px 0; }
.feat .n { color: var(--brand-dark); font-weight: 700; }
.feat.free { background: #fff8e1; }
.tag-again { background: var(--warn); color: #fff; border-radius: 6px; padding: 1px 8px; font-size: .8em; margin-left: 6px; }

.reveal { text-align: center; }
.reveal .name { font-size: 3em; font-weight: 900; }

.top5 { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.top5 .t { background: #fff; border-radius: 12px; padding: 8px 14px; display: flex; gap: 8px; align-items: center; box-shadow: 0 1px 6px rgba(30,50,100,.1); font-weight: 700; }

.final-first { text-align: center; margin: 10px 0 24px; }
.final-first .crown { font-size: 3em; }
.final-first .av { width: 260px; height: 260px; font-size: 110px; border: 8px solid gold; }
.final-first .name { font-size: 3.4em; font-weight: 900; }
.final-first .score { font-size: 2.2em; color: var(--brand-dark); font-weight: 800; }
.final-list .item { display: flex; align-items: center; gap: 16px; background: #fff; border-radius: 14px; padding: 10px 18px; margin: 8px auto; max-width: 720px; box-shadow: 0 1px 6px rgba(30,50,100,.1); font-size: 1.4em; font-weight: 700; }
.final-list .rank { width: 60px; text-align: center; color: var(--brand-dark); font-weight: 900; }
.final-list .score { margin-left: auto; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d2433; color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 20; }

@media (max-width: 700px) {
  body { font-size: 16px; }
  .stage-title { font-size: 1.8em; }
}
