@font-face { font-family: 'neodgm'; src: url('../fonts/neodgm.woff2') format('woff2'); font-display: swap; }

:root {
  --bg: #1a1c2c; --ink: #0f1020; --panel: #262b44; --panel2: #333c57; --line: #566c86;
  --text: #f4f4f4; --dim: #94b0c2; --gold: #ffcd75; --green: #a7f070; --red: #b13e53; --redl: #ef7d57;
  --p0: #ef7d57; --p0d: #b13e53; --p0l: #ffcd75;
  --p1: #41a6f6; --p1d: #3b5dc9; --p1l: #73eff7;
  --p2: #a7f070; --p2d: #38b764; --p2l: #d6ffb0;
  --p3: #d47cf0; --p3d: #8a3fa8; --p3l: #f0c2ff;
  --o: var(--p0); --od: var(--p0d); --ol: var(--p0l);
  --notch: 0 -4px 0 0 var(--c), 0 4px 0 0 var(--c), -4px 0 0 0 var(--c), 4px 0 0 0 var(--c);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); color: var(--text);
  background-image: linear-gradient(#ffffff08 1px, transparent 1px), linear-gradient(90deg, #ffffff08 1px, transparent 1px);
  background-size: 16px 16px;
  font: 16px/24px 'neodgm', ui-monospace, 'Courier New', monospace;
  font-synthesis: none; -webkit-font-smoothing: none; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
small { font-size: 16px; }
button, input, select { font: inherit; color: inherit; }
::selection { background: var(--gold); color: var(--bg); }

/* ---- 공통 부품 ---- */
.panel {
  --c: var(--line);
  position: relative; margin: 4px; padding: 14px 16px; background: var(--panel);
  box-shadow: var(--notch), inset 0 -4px 0 0 #0003;
}
.panel > h2, .dlg-head h2 { color: var(--gold); font-size: 16px; letter-spacing: .16em; margin-bottom: 10px; }
.dim { color: var(--dim); }
.label, .lbl { color: var(--dim); }
.notice { color: var(--gold); min-height: 1.6em; }
.notice.error { color: var(--redl); }

.btn {
  --c: var(--ink); --btn: var(--panel2); --fg: var(--text);
  display: inline-block; margin: 4px; padding: 8px 16px; border: 0; cursor: pointer; text-align: center;
  background: var(--btn); color: var(--fg);
  box-shadow: var(--notch), inset 0 -4px 0 0 #0006, inset 0 4px 0 0 #ffffff26;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: var(--notch), inset 0 -2px 0 0 #0006, inset 0 2px 0 0 #ffffff26; }
.btn:disabled { filter: grayscale(1) brightness(.55); cursor: not-allowed; }
.btn.primary { --btn: var(--gold); --fg: var(--bg); }
.btn.danger { --btn: var(--red); }
.btn.ghost { --btn: #29366f; }
.btn.small { padding: 2px 12px; white-space: nowrap; flex: none; }
.btn.big { padding: 12px 20px; width: calc(100% - 8px); }
.btn.big small { display: block; font-size: 16px; opacity: .8; }
:focus-visible { outline: 2px dashed var(--gold); outline-offset: 4px; }

input[type=text], input:not([type]), input[type=search] {
  background: var(--ink); border: 0; color: var(--text); padding: 6px 10px; width: 100%;
  --c: var(--line); box-shadow: var(--notch); margin: 4px 0;
}
input::placeholder { color: #566c86; }
input[readonly] { color: var(--dim); }
input[type=range] { width: 100%; accent-color: var(--gold); height: 20px; cursor: pointer; }
output { min-width: 3.5em; text-align: right; color: var(--gold); }
.field { display: block; } .field > span { display: block; color: var(--dim); }
.field-row { display: grid; grid-template-columns: 5.5em 1fr auto; gap: 10px; align-items: center; margin: 8px 0; }
.field-row .lbl { grid-column: 1; }
.field-row .seg { grid-column: 2 / 4; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; cursor: pointer; color: var(--dim); }
.check input { width: 16px; height: 16px; accent-color: var(--gold); }

.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button {
  --c: var(--ink); border: 0; padding: 2px 14px; background: var(--panel2); cursor: pointer; margin: 4px 4px 4px 4px;
  box-shadow: var(--notch), inset 0 -4px 0 0 #0006;
}
.seg button[aria-pressed=true] { background: var(--gold); color: var(--bg); }
.seg button:disabled { cursor: not-allowed; opacity: .75; }

kbd {
  display: inline-block; min-width: 22px; padding: 0 6px; margin: 0 2px; text-align: center; color: var(--text);
  background: var(--panel2); box-shadow: 0 3px 0 0 var(--ink), 0 0 0 2px var(--ink); font: inherit;
}
.keys-inline { display: inline-flex; gap: 2px; flex-wrap: wrap; vertical-align: middle; }
.keys-inline.big kbd { min-width: 34px; padding: 3px 8px; margin: 0 3px; }

.badge {
  display: inline-grid; place-items: center; width: 32px; height: 32px; color: var(--bg); flex: none;
  box-shadow: inset 0 -4px 0 0 #0004, 0 0 0 2px var(--ink);
}
.p0 { --o: var(--p0); --od: var(--p0d); --ol: var(--p0l); } .p1 { --o: var(--p1); --od: var(--p1d); --ol: var(--p1l); }
.p2 { --o: var(--p2); --od: var(--p2d); --ol: var(--p2l); } .p3 { --o: var(--p3); --od: var(--p3d); --ol: var(--p3l); }
.badge { background: var(--o); }
.tag { margin-left: auto; padding: 0 8px; background: var(--ink); color: var(--gold); }
.tag:empty { display: none; }

/* ---- 상단바 ---- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px 6px; flex: none; }
.logo { background: none; border: 0; cursor: pointer; font-size: 32px; line-height: 1; letter-spacing: .06em; color: var(--text); display: flex; align-items: center; gap: 10px; padding: 0; text-shadow: 2px 2px 0 var(--ink); }
.logo-mark { width: 24px; height: 24px; background: linear-gradient(90deg, var(--p0) 0 50%, var(--p1) 50% 100%); box-shadow: 0 0 0 2px var(--ink), 4px 4px 0 0 var(--ink); display: inline-block; }
.chips { display: flex; gap: 8px; margin-right: auto; }
.chip { padding: 0 10px; background: var(--ink); color: var(--dim); } .chip b { color: var(--gold); letter-spacing: .12em; font-weight: normal; }
.chip.ok { color: var(--green); } .chip.bad { color: var(--redl); }

main { flex: 1; min-height: 0; position: relative; }
.screen { height: 100%; overflow: auto; padding: 8px 16px 20px; }

/* ---- 메뉴 ---- */
.hero { text-align: center; padding: 18px 0 12px; }
.title { font-size: 80px; line-height: 1; font-weight: normal; letter-spacing: .04em; display: flex; justify-content: center; gap: 14px; }
.title span:first-child { color: var(--p0); text-shadow: 4px 4px 0 var(--p0d), 8px 8px 0 #5d275d; }
.title span:last-child { color: var(--p1); text-shadow: 4px 4px 0 var(--p1d), 8px 8px 0 #29366f; }
.tagline { margin-top: 22px; color: var(--dim); }
.eq { display: flex; justify-content: center; align-items: flex-end; gap: 6px; height: 44px; margin-top: 14px; }
.eq i { width: 8px; background: var(--p0); animation: eq 1.1s steps(5) infinite; }
.eq i:nth-child(even) { background: var(--p1); }
.eq i:nth-child(3n) { animation-duration: .8s; } .eq i:nth-child(4n) { animation-duration: 1.4s; }
.eq i:nth-child(5n) { animation-delay: -.4s; } .eq i:nth-child(7n) { animation-delay: -.7s; }
@keyframes eq { 0%, 100% { height: 8px; } 25% { height: 36px; } 50% { height: 16px; } 75% { height: 44px; } }

.menu-grid { display: grid; grid-template-columns: minmax(300px, 380px) minmax(300px, 460px); gap: 20px; justify-content: center; margin-top: 12px; }
.menu-actions { display: flex; flex-direction: column; gap: 6px; }
.join-row { display: flex; gap: 6px; align-items: center; }
.join-row input { text-transform: uppercase; letter-spacing: .2em; text-align: center; }
.join-row .btn { width: auto; flex: none; }
.howto ol { margin: 0 0 10px; padding-left: 1.4em; display: flex; flex-direction: column; gap: 8px; }
.howto li::marker { color: var(--gold); }
.howto b { color: var(--gold); font-weight: normal; }

/* ---- 로비 ---- */
.lobby-grid { display: grid; grid-template-columns: minmax(280px, 380px) minmax(320px, 520px); gap: 20px; justify-content: center; margin-top: 12px; }
.slot { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 6px 0; background: var(--ink); }
.slot em { margin-left: auto; font-style: normal; color: var(--dim); }
.slot.ready em { color: var(--green); }
.slot.waiting b { color: var(--dim); }
.invite { margin-top: 14px; }
.invite-row { display: flex; gap: 6px; align-items: center; }
.code-big { font-size: 42px; letter-spacing: .24em; color: var(--gold); text-shadow: 3px 3px 0 var(--p0d); line-height: 1.3; }
.progs { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 8px; margin: 12px 0; }
.prog { --c: var(--ink); display: block; position: relative; padding: 8px 12px; background: var(--ink); cursor: pointer; box-shadow: var(--notch); }
.prog input { position: absolute; opacity: 0; pointer-events: none; }
.prog b { color: var(--text); font-weight: normal; letter-spacing: .1em; } .prog span { color: var(--dim); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prog:has(input:checked) { --c: var(--gold); background: #2c2a3a; } .prog:has(input:checked) b { color: var(--gold); }
.prog:has(input:focus-visible) { outline: 2px dashed var(--gold); outline-offset: 4px; }
.prog.locked { cursor: default; opacity: .8; }
.keys-preview { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.lobby-actions { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.lobby-actions .btn.big { width: auto; min-width: 220px; }

/* ---- 게임 ---- */
#screen-game { overflow: hidden; padding: 4px 12px 8px; }
.game-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr) 280px; gap: 12px; height: 100%; }
.side { display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow: auto; padding: 4px 4px 4px 0; }
.side .panel { flex: none; }
.center { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.stage-panel { --o: var(--p0); --od: var(--p0d); --ol: var(--p0l); --c: var(--od); flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 10px 12px; transition: none; }
.stage-panel[data-owner="1"] { --o: var(--p1); --od: var(--p1d); --ol: var(--p1l); }
.stage-panel[data-owner="2"] { --o: var(--p2); --od: var(--p2d); --ol: var(--p2l); }
.stage-panel[data-owner="3"] { --o: var(--p3); --od: var(--p3d); --ol: var(--p3l); }
.stage-top { display: flex; align-items: center; gap: 12px; padding-bottom: 8px; }
.turn-chip { background: var(--o); color: var(--bg); padding: 0 10px; }
.next-chip { background: var(--ink); color: var(--gold); padding: 0 10px; animation: blink .5s steps(2) infinite; }
.chord { margin-left: auto; font-size: 32px; line-height: 1; color: var(--ol); min-width: 3.2em; text-align: right; }
.dots { display: flex; gap: 4px; } .dots i { width: 12px; height: 12px; background: var(--ink); } .dots i.on { background: var(--o); }
.dots i.on:first-child { background: var(--text); }

.canvas-box { position: relative; flex: 1; min-height: 140px; display: grid; place-items: center; background: var(--ink); overflow: hidden; }
#stage { display: block; image-rendering: pixelated; }
.pads { display: flex; gap: 6px; margin: 10px auto 0; width: var(--pads-w, 100%); max-width: 100%; touch-action: none; }
.pad {
  --c: var(--ink); flex: 1; min-width: 0; height: 56px; border: 0; padding: 0; cursor: pointer; background: var(--panel2); color: var(--text);
  font-size: 32px; line-height: 1; user-select: none; touch-action: none;
  box-shadow: var(--notch), inset 0 -6px 0 0 #0006, inset 0 4px 0 0 #ffffff1f;
}
.pad.down { background: var(--o); color: var(--bg); transform: translateY(4px); box-shadow: var(--notch), inset 0 -2px 0 0 #0006; }
.pads[data-locked="true"] .pad { opacity: .45; cursor: default; }
.help { margin-top: 12px; min-height: 3.2em; color: var(--dim); text-align: center; }
.help b { color: var(--gold); font-weight: normal; }
.controls { display: flex; justify-content: flex-end; gap: 4px; padding-top: 4px; }

.countdown { position: absolute; left: 0; right: 0; top: 18%; text-align: center; font-size: 96px; line-height: 1; color: var(--gold); text-shadow: 6px 6px 0 var(--od); pointer-events: none; }
.countdown.pop { animation: pop .5s steps(4); } .countdown small { display: block; margin-top: 12px; font-size: 16px; color: var(--text); text-shadow: none; }
@keyframes pop { 0% { transform: scale(1.5); opacity: .2; } 100% { transform: scale(1); opacity: 1; } }
.turn-flash { position: absolute; left: 0; right: 0; top: 14%; text-align: center; font-size: 32px; line-height: 48px; background: var(--o); color: var(--bg); pointer-events: none; animation: flash 1.4s steps(8) forwards; box-shadow: 0 -4px 0 var(--ol), 0 4px 0 var(--od); opacity: .94; }
@keyframes flash { 0% { transform: translateX(-100%); } 15%, 75% { transform: translateX(0); } 100% { transform: translateX(100%); opacity: 0; } }
.judge { position: absolute; left: 0; right: 0; top: 48%; text-align: center; font-size: 32px; line-height: 1; pointer-events: none; opacity: 0; text-shadow: 3px 3px 0 var(--ink); }
.judge.show { animation: rise .55s steps(5) forwards; }
.judge.perfect { color: var(--gold); } .judge.good { color: var(--green); } .judge.miss { color: var(--redl); }
@keyframes rise { 0% { opacity: 1; transform: translateY(8px); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }
.combo { position: absolute; left: 10px; top: 8px; font-size: 32px; line-height: 1.1; color: var(--text); text-shadow: 3px 3px 0 var(--p0d); pointer-events: none; }
.combo small { display: block; font-size: 16px; color: var(--dim); text-shadow: none; }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 20px; text-align: center; background: #0f1020e6; }
.overlay h2 { font-size: 32px; line-height: 1.3; color: var(--gold); letter-spacing: .06em; margin: 0; }
.overlay-stats { display: grid; grid-template-columns: repeat(2, minmax(120px, 1fr)); gap: 10px; width: min(100%, 460px); margin: 6px 0; }
.overlay-stats:empty { display: none; }
.rs { padding: 8px 10px; background: var(--panel); text-align: left; --c: var(--od); box-shadow: var(--notch); }
.rs { --c: var(--od); } .rs b { display: block; font-weight: normal; color: var(--o); }
.rs strong { font-size: 32px; font-weight: normal; line-height: 1.3; }
.overlay-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

.player { --c: var(--line); }
.player.active { --c: var(--o); }
.pl-head { display: flex; align-items: center; gap: 8px; }
.pl-head b { font-weight: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-turn { margin: 4px 0 0; color: var(--dim); min-height: 1.6em; }
.player.active .pl-turn { color: var(--o); }
.player dl { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; margin: 4px 0 0; }
.player dt { color: var(--dim); } .player dd { margin: 0; text-align: right; color: var(--text); }
.map-wrap { max-height: 240px; overflow: auto; background: var(--ink); padding: 4px; }
#map { display: block; image-rendering: pixelated; }
.log-panel { min-height: 120px; }
.log { margin: 0; padding: 0; list-style: none; max-height: 200px; overflow: auto; display: flex; flex-direction: column-reverse; }
.log li { padding: 2px 0; border-bottom: 1px dashed var(--panel2); color: var(--dim); } .log li b { font-weight: normal; }
.log li b { color: var(--o); }

/* ---- 설정 ---- */
dialog { --c: var(--line); border: 0; padding: 16px 20px 20px; width: min(560px, 92vw); max-height: 90dvh; overflow: auto; background: var(--panel); color: var(--text); box-shadow: var(--notch); }
dialog::backdrop { background: #0f1020d9; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.tabs { display: flex; gap: 6px; margin: 4px 0 12px; border-bottom: 4px solid var(--ink); }
.tab { border: 0; background: var(--ink); padding: 2px 14px; cursor: pointer; color: var(--dim); }
.tab[aria-selected=true] { background: var(--gold); color: var(--bg); }
.key-slots { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.kslot { --c: var(--ink); width: 64px; height: 76px; border: 0; padding: 6px 0 0; cursor: pointer; background: var(--panel2); display: flex; flex-direction: column; align-items: center; justify-content: space-between; box-shadow: var(--notch), inset 0 -6px 0 0 #0006; }
.kslot small { color: var(--dim); } .kslot b { font-weight: normal; font-size: 32px; line-height: 1; padding-bottom: 14px; }
.kslot.capturing { background: var(--gold); color: var(--bg); animation: blink .6s steps(2) infinite; } .kslot.capturing small { color: var(--bg); }
.kslot.flash { background: var(--o); color: var(--bg); }
@keyframes blink { 50% { opacity: .55; } }
.calib { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }

.toasts { position: fixed; left: 0; right: 0; bottom: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 50; }
.toast { --c: var(--line); padding: 4px 14px; background: var(--ink); box-shadow: var(--notch); animation: toast .25s steps(3); }
.toast.error { --c: var(--red); } .toast.ok { --c: #38b764; }
@keyframes toast { from { transform: translateY(16px); opacity: 0; } }

@media (max-width: 1180px) {
  .game-grid { grid-template-columns: 200px minmax(0, 1fr); }
  .game-grid > .side:last-child { grid-column: 1 / -1; flex-direction: row; max-height: 200px; }
  .game-grid > .side:last-child .panel { flex: 1; min-width: 0; }
}
@media (max-width: 820px) {
  body { overflow: auto; } main { overflow: visible; } .screen { height: auto; overflow: visible; }
  #screen-game { overflow: visible; } .game-grid { display: flex; flex-direction: column; height: auto; }
  .center { order: -1; height: calc(100dvh - 90px); min-height: 520px; }
  .side { flex-direction: row; overflow: visible; } .side .panel { flex: 1; min-width: 0; }
  .game-grid > .side:last-child { flex-direction: column; max-height: none; }
  .menu-grid, .lobby-grid { grid-template-columns: 1fr; }
  .title { font-size: 48px; } .countdown { font-size: 64px; }
  .pad { height: 64px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }

.pad.long, .kslot b.long { font-size: 16px; letter-spacing: 0; }
#slots .slot b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .player { padding: 10px 12px; }
