:root {
  --navy: #1f2a4d;
  --ink: #2b3561;
  --pink: #ff7eb3;
  --sky: #5ab8f0;
  --sun: #ffc93c;
  --mint: #5fd3a6;
  --card: #fffdf8;
  --ui: "Jua", "Malgun Gothic", sans-serif;
  --word: "Lexend", "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #1b2140; overflow: hidden; }
body { font-family: var(--ui); color: var(--navy); }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* 1600×900 무대를 창에 맞춰 줄이고 가운데에 둔다 */
#wrap { position: fixed; inset: 0; }
#stage {
  position: absolute; left: 50%; top: 50%; width: 1600px; height: 900px;
  transform: translate(-50%, -50%) scale(var(--s, 1)); transform-origin: center;
  overflow: hidden; border-radius: 6px; background: #bfe6fb;
}
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* 위쪽 HUD */
#hud { position: absolute; left: 18px; right: 18px; top: 14px; display: flex; gap: 10px; align-items: center; pointer-events: none; }
#hud .spacer { flex: 1; }
.pill {
  background: rgba(255, 255, 255, .9); border: 3px solid var(--navy); border-radius: 999px;
  padding: 4px 18px; font-size: 26px; line-height: 34px; box-shadow: 0 4px 0 rgba(31, 42, 77, .25);
}
.pill.btn { pointer-events: auto; padding: 4px 12px; }
.pill.btn.off, .ghost.off { opacity: .45; text-decoration: line-through; }
.pill.score { font-family: var(--word); font-weight: 700; min-width: 150px; text-align: right; }
.pill.progress { position: relative; width: 210px; overflow: hidden; padding: 0; height: 46px; }
#hudBar { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #8be0ff, #5fd3a6); transition: width .3s; }
#hudLeft { position: relative; display: block; text-align: center; line-height: 40px; }

/* 아래 입력 칸 */
#inputbar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: stretch;
}
#typed {
  width: 760px; height: 66px; background: #fff; border: 4px solid var(--navy); border-radius: 18px;
  display: flex; align-items: center; padding: 0 22px; font-family: var(--word); font-weight: 700; font-size: 36px;
  box-shadow: 0 6px 0 rgba(31, 42, 77, .3); white-space: pre; overflow: hidden;
}
#typed.wrong { animation: shake .35s; border-color: #e5484d; background: #ffecee; }
#typed.right { border-color: #2fb37a; }
#typedHint { color: #a3a9c2; font-family: var(--ui); font-weight: 400; font-size: 28px; margin-left: 6px; }
.caret { width: 3px; height: 40px; background: var(--navy); margin-left: 2px; animation: blink 1s steps(1) infinite; }
.side {
  width: 112px; background: rgba(255, 255, 255, .92); border: 3px solid var(--navy); border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
}
.side b { font-family: var(--word); font-size: 30px; }
.side small { font-size: 16px; margin-top: 4px; color: #59607f; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

/* 첫 화면 */
.screen { position: absolute; inset: 0; }
#home {
  display: flex; gap: 40px; padding: 48px 56px; align-items: center;
  background: linear-gradient(90deg, rgba(255,255,255,.0) 0%, rgba(255,255,255,0) 40%), url("art/title.webp") center / cover;
}
.home-left { flex: 1; align-self: stretch; display: flex; flex-direction: column; }
.logo {
  margin: 0; font-family: var(--word); font-weight: 700; font-size: 118px; line-height: 1; letter-spacing: -2px;
  color: #fff; -webkit-text-stroke: 7px var(--navy); paint-order: stroke fill; text-shadow: 0 8px 0 var(--navy);
}
.logo span:first-child { color: var(--sky); }
.logo span:last-child { color: var(--pink); }
.tagline { margin: 12px 0 18px 6px; font-size: 40px; color: #fff; -webkit-text-stroke: 5px var(--navy); paint-order: stroke fill; }
.howto {
  list-style: none; margin: 0; padding: 18px 24px; background: rgba(255, 253, 248, .92); border: 3px solid var(--navy);
  border-radius: 22px; font-size: 25px; line-height: 1.55;
}
kbd { font-family: var(--word); font-size: .8em; border: 2px solid var(--navy); border-bottom-width: 4px; border-radius: 8px; padding: 0 8px; background: #fff; }
/* 첫 화면 점수판 */
.board { margin-top: 16px; background: rgba(255, 253, 248, .94); border: 3px solid var(--navy); border-radius: 22px; padding: 10px 18px 8px; }
.board-head { display: flex; align-items: center; gap: 10px; font-size: 26px; }
.board-head b { margin-right: auto; }
.mini-seg { display: flex; border: 2px solid var(--navy); border-radius: 12px; overflow: hidden; }
.mini-seg button { border: 0; background: #fff; font-size: 18px; padding: 3px 12px; }
.mini-seg button + button { border-left: 2px solid var(--navy); }
.mini-seg button.on { background: var(--sun); }
.board ol { list-style: none; margin: 6px 0 0; padding: 0; }
.board li { display: flex; align-items: center; gap: 12px; font-size: 21px; line-height: 33px; border-top: 1px dashed #d5d9ea; }
.board li:first-child { border-top: 0; }
.board li b { width: 34px; text-align: center; font-family: var(--word); }
.board li .nm { flex: 1; font-family: var(--word); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .sc { font-family: var(--word); font-weight: 700; color: #e0457b; width: 100px; text-align: right; }
.board li .cp { width: 110px; text-align: right; color: #6b7190; font-size: 18px; }
.board li.me { background: #fff2b8; border-radius: 10px; }
.board li.empty { color: #8b91ad; justify-content: center; }

.card {
  width: 700px; background: var(--card); border: 4px solid var(--navy); border-radius: 28px; padding: 26px 30px;
  box-shadow: 0 10px 0 rgba(31, 42, 77, .35); display: flex; flex-direction: column; gap: 14px;
}
.tabs { display: flex; gap: 8px; }
.tabs button { flex: 1; padding: 10px 0; font-size: 24px; border: 3px solid var(--navy); border-radius: 16px; background: #eef3ff; }
.tabs button.on { background: var(--sun); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .15); }
.pane { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 14px; font-size: 24px; }
.row > span:first-child { width: 78px; flex: none; color: #59607f; }
.row select, .row input:not([type]) {
  flex: 1; min-width: 0; padding: 8px 12px; border: 3px solid var(--navy); border-radius: 14px; background: #fff; font-size: 22px;
}
.row.check { font-size: 21px; cursor: pointer; }
.row.check input { width: 24px; height: 24px; accent-color: var(--pink); }
.row.check span { width: auto !important; color: var(--navy) !important; }
.seg { display: flex; gap: 6px; flex: 1; }
.seg.wrap { flex-wrap: wrap; }
.seg button { flex: 1; padding: 7px 10px; font-size: 22px; border: 3px solid var(--navy); border-radius: 14px; background: #fff; white-space: nowrap; }
.seg button.on { background: var(--sky); color: #fff; }
.preview {
  min-height: 92px; max-height: 92px; overflow: hidden; padding: 8px 12px; background: #f1f5ff; border-radius: 14px;
  font-family: var(--word); font-size: 17px; line-height: 1.5; color: #4b5375;
}
.preview em { font-style: normal; font-family: var(--ui); color: #8b91ad; margin-right: 6px; }
.note { margin: 0; font-size: 19px; color: #6b7190; }
.keys { display: flex; flex-wrap: wrap; gap: 6px; }
.keys span { font-family: var(--word); font-weight: 700; font-size: 24px; width: 46px; height: 46px; display: grid; place-items: center; border: 3px solid var(--navy); border-bottom-width: 6px; border-radius: 10px; background: #fff; }
textarea { width: 100%; resize: none; border: 3px solid var(--navy); border-radius: 14px; padding: 10px 14px; font-family: var(--word); font-size: 20px; line-height: 1.4; }
.actions { display: flex; gap: 10px; margin-top: 6px; }
.go {
  flex: 1; padding: 12px 0; font-size: 34px; border: 4px solid var(--navy); border-radius: 20px; background: var(--pink); color: #fff;
  -webkit-text-stroke: 1px var(--navy); box-shadow: 0 6px 0 var(--navy); transition: transform .08s;
}
.go:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--navy); }
.go small { font-size: 18px; -webkit-text-stroke: 0; opacity: .85; }
.ghost { padding: 10px 16px; font-size: 21px; border: 3px solid var(--navy); border-radius: 18px; background: #fff; }

/* 가운데 알림판 */
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(27, 33, 64, .35); }
#banner { background: transparent; pointer-events: none; }
.big {
  text-align: center; color: #fff; -webkit-text-stroke: 8px var(--navy); paint-order: stroke fill;
  text-shadow: 0 8px 0 var(--navy); animation: pop .5s cubic-bezier(.2, 1.6, .4, 1);
}
.big h2 { margin: 0; font-family: var(--word); font-weight: 700; font-size: 130px; line-height: 1; }
.big p { margin: 10px 0 0; font-size: 48px; }
.big .count { font-family: var(--word); font-weight: 700; font-size: 110px; color: var(--sun); margin-top: 16px; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.box { background: var(--card); border: 4px solid var(--navy); border-radius: 28px; padding: 30px 40px; min-width: 520px; text-align: center; box-shadow: 0 10px 0 rgba(31, 42, 77, .35); }
.box h2 { margin: 0 0 18px; font-size: 52px; }

/* 결과 */
#result { display: grid; place-items: center; background: rgba(27, 33, 64, .45); }
#result .box { width: 1080px; text-align: left; }
#result h2 { text-align: center; font-size: 60px; margin-bottom: 6px; }
#result .sub { text-align: center; font-size: 26px; color: #59607f; margin: 0 0 20px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stats div { background: #f1f5ff; border-radius: 18px; padding: 12px; text-align: center; font-size: 22px; color: #59607f; }
.stats b { display: block; font-family: var(--word); font-size: 44px; color: var(--navy); }
.stats .best b { color: #e0457b; }
.missed { font-size: 22px; background: #fff4f6; border-radius: 18px; padding: 12px 18px; max-height: 210px; overflow: auto; }
.missed ul { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.missed li { font-family: var(--word); font-size: 20px; background: #fff; border: 2px solid #f3a6bc; border-radius: 12px; padding: 2px 12px; }
.missed.ok { background: #effbf4; }
.missed { max-height: 132px; }

/* 결과 화면 점수판 올리기 */
.reg { margin-top: 14px; background: #fff8e1; border: 3px solid #f2c94c; border-radius: 18px; padding: 12px 18px; }
.reg-q { font-size: 28px; }
.reg-q small { font-size: 19px; color: #8b7a3a; margin-left: 8px; }
.reg-q .rank { font-size: 24px; color: #e0457b; margin-left: 8px; }
.reg-q b.me { font-family: var(--word); }
.reg-row { display: flex; gap: 10px; margin-top: 8px; align-items: stretch; }
.nick {
  flex: 1; display: flex; align-items: center; height: 58px; padding: 0 18px; background: #fff; border: 4px solid var(--navy);
  border-radius: 16px; font-family: var(--word); font-weight: 700; font-size: 32px; white-space: pre; overflow: hidden;
}
.nick em { display: none; font-style: normal; font-family: var(--ui); font-weight: 400; font-size: 24px; color: #a3a9c2; margin-left: 6px; }
.nick.empty em { display: inline; }
.nick .caret { height: 34px; }
.go.small { flex: none; padding: 0 22px; font-size: 26px; }
.go:disabled { background: #d9d6e6; color: #fff; box-shadow: 0 6px 0 #9b98ad; cursor: default; }
.reg .ghost small, .go.small small { font-size: 15px; }
.reg .note { margin-top: 8px; }
.note.warn { color: #d6336c; }
.link { border: 0; background: none; color: #3577d4; text-decoration: underline; font-size: inherit; padding: 0; }
.mini { list-style: none; margin: 8px 0 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.mini li { font-size: 20px; background: #fff; border-radius: 12px; padding: 2px 12px; border: 2px solid #f2c94c; }
.mini li b { font-family: var(--word); margin-right: 4px; }
.mini li span { font-family: var(--word); color: #e0457b; margin-left: 6px; }
.mini li.me { background: #ffe680; }

#toast {
  position: absolute; left: 50%; top: 84px; transform: translateX(-50%); background: var(--navy); color: #fff;
  padding: 10px 24px; border-radius: 16px; font-size: 24px; opacity: 0; transition: opacity .3s; pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; }
