:root { --bg: #0b0a14; --panel: #1a1530; --line: #4a3a8a; --text: #efe9ff; --accent: #e8a21a; --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Malgun Gothic", sans-serif; overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
/* 게임 영역은 길게 눌러도 복사 메뉴·선택·이미지 드래그가 나오지 않게 한다 */
#stage, #touch, #bar { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
#bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px; align-items: center; flex: 0 0 auto; background: #120f22; border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
button { white-space: nowrap; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; cursor: pointer; }
button:hover { border-color: #8a74ff; }
button:focus-visible { outline: 2px solid #c9b8ff; outline-offset: 2px; }
button.primary { background: var(--accent); border-color: #ffd37a; color: #1a1002; font-weight: 700; }
button.big { font-size: 1.2rem; padding: 12px 28px; }
kbd { font: inherit; font-size: .8em; background: #0004; border: 1px solid #fff4; border-radius: 4px; padding: 0 4px; }
#stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
#screen { image-rendering: pixelated; image-rendering: crisp-edges; background: #000; box-shadow: 0 0 0 2px #2a2058; }
#screen.smooth { image-rendering: auto; }
#pausedMsg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #000a; font-size: 1.4rem; font-weight: 700; }
#netHint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); background: #1a1530f0; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: .8rem; max-width: 92%; text-align: center; pointer-events: none; z-index: 3; }
#soundHint { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: #1a1530f0; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: .8rem; white-space: nowrap; pointer-events: none; }
#iosHint { position: absolute; left: 12px; right: 12px; bottom: 8px; background: #1a1530f0; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: .85rem; text-align: center; }
#foot { flex: 0 0 auto; text-align: center; font-size: 11px; opacity: .45; padding: 2px; }
body.touch #foot { display: none; }

/* 터치 조작부: 반투명. 세로 폰에서는 화면 아래, 가로에서는 화면 좌우 빈자리에 둔다 */
#touch { display: none; }
body.touch #touch { display: flex; justify-content: space-between; align-items: flex-end; flex: 0 0 auto; height: min(34vh, 230px); padding: 8px 18px 14px; pointer-events: none; }
body.touch #touch > * { pointer-events: auto; }
#stick { position: relative; width: min(38vw, 190px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(#fff2, #fff1 60%, #fff0 62%), #2a2058aa; border: 2px solid #a48fff88; opacity: .75; touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 38%; height: 38%; margin: -19% 0 0 -19%; border-radius: 50%; background: #ffffffb0; box-shadow: 0 2px 8px #0008; pointer-events: none; transition: transform .06s; }
#btns { display: grid; grid-template-columns: repeat(2, auto); gap: 10px 14px; align-items: end; padding-bottom: 6px; }
#btns button { width: min(19vw, 80px); aspect-ratio: 1; border-radius: 50%; font-size: 1.4rem; font-weight: 800; border: 2px solid #ffffffaa; color: #fff; opacity: .78; touch-action: none; padding: 0; }
#btns button[data-btn="b1"] { background: #e8a21ab0; grid-column: 2; grid-row: 2; }
#btns button[data-btn="b2"] { background: #4f8bffb0; grid-column: 1; grid-row: 2; }
#btns button[data-btn="b3"] { background: #3fbf6fb0; grid-column: 1; grid-row: 1; }
#btns button[data-btn="b4"] { background: #c05fe8b0; grid-column: 2; grid-row: 1; }
#btns button.on { filter: brightness(1.4); transform: scale(.94); }
@media (orientation: landscape) and (max-height: 520px) {
  body.touch #app { display: grid; grid-template-columns: minmax(130px, 22vw) minmax(0, 1fr) minmax(130px, 22vw); grid-template-rows: auto 1fr; }
  body.touch #bar { grid-column: 1 / -1; }
  body.touch #stage { grid-column: 2; grid-row: 2; }
  body.touch #touch { display: contents; }
  body.touch #stick { grid-column: 1; grid-row: 2; align-self: end; justify-self: start; margin: 0 0 14px 18px; width: min(34vh, 170px); }
  body.touch #btns { grid-column: 3; grid-row: 2; align-self: end; justify-self: end; margin: 0 18px 14px 0; }
  body.touch #btns button { width: min(15vh, 64px); }
}

#overlay { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; text-align: center; background: radial-gradient(circle at 50% 30%, #3a2670, #0b0a14 70%); padding: 24px; }
#overlay[hidden] { display: none; }
#overlay h1 { margin: 0 0 12px; font-size: 1.9rem; letter-spacing: .04em; color: #ffd23f; text-shadow: 0 3px 0 #7a2a10; }
#overlay p { margin: 6px 0; } .small { font-size: .82rem; opacity: .75; }
progress { width: min(70vw, 320px); height: 14px; accent-color: var(--accent); }
dialog { background: #1a1530; color: var(--text); border: 1px solid var(--line); border-radius: 14px; width: min(92vw, 560px); max-height: 88vh; overflow: auto; }
dialog::backdrop { background: #000a; }
table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: .9rem; } th, td { border-bottom: 1px solid #fff2; padding: 5px 6px; text-align: left; }
@media (max-width: 520px) { #bar { gap: 4px; padding: 5px 6px; } #bar button { padding: 6px 7px; font-size: .74rem; } #startBtn kbd { display: none; } }

/* 대화상자 공통 */
dialog .row { display: flex; gap: 6px; margin: 8px 0; }
dialog input[type="text"], dialog input:not([type]), dialog input[type="password"] { flex: 1; min-width: 0; font: inherit; color: var(--text); background: #0f0b22; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.status { min-height: 1.2em; font-size: .85rem; color: #ffd23f; margin: 6px 0; }
.check { display: block; font-size: .82rem; opacity: .85; margin: 4px 0; }
.memo-row { display: flex; gap: 6px; margin: 8px 0 2px; flex-wrap: nowrap; }
.memo-row input:first-child { flex: 0 0 7.5em; }
button.icon { padding: 4px 8px; }
button.go { background: var(--accent); color: #1a1002; border-color: #ffd37a; font-weight: 700; }
.memos { list-style: none; margin: 8px 0; padding: 0; max-height: 40vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.memos li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: #ffffff10; }
.memos li b { flex: 0 0 auto; color: #ffd23f; }
.memos li span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.memos li time { flex: 0 0 auto; font-size: .72rem; opacity: .6; }
.memos li.empty { justify-content: center; opacity: .7; }
table.rec td.empty { text-align: center; opacity: .7; }
table.rec tr.mine td { color: #ffd23f; }
table.rec td, table.rec th { font-size: .82rem; padding: 4px 5px; }
dialog > button:last-child { margin-top: 6px; }

/* 오른쪽 고정 패널(넓은 화면): 위 기록지, 아래 출석메모. 좁은 화면에서는 위쪽 버튼으로 여는 대화상자 */
@media (min-width: 900px) {
  #app { padding-right: 380px; box-sizing: border-box; }
  #side { position: fixed; top: var(--bar-h, 52px); right: 0; bottom: 0; width: 380px; display: flex; flex-direction: column; background: #1a1530; border-left: 1px solid var(--line); z-index: 4; }
  #side dialog { position: static; inset: auto; margin: 0; width: auto; max-width: none; max-height: none; height: auto; border: 0; border-radius: 0; overflow: auto; box-sizing: border-box; }
  #side dialog + dialog { border-top: 1px solid var(--line); }
  #recDlg { flex: 0 1 auto; max-height: 56%; }
  #memoDlg { flex: 1 1 0; min-height: 0; }
  #side h2 { margin: 0 0 6px; font-size: 1.05rem; }
  #memoBtn, #recBtn, #memoClose, #recClose { display: none; }
}

/* 온라인 방 */
.rooms-head { margin: 10px 0 4px; font-size: .95rem; display: flex; align-items: center; justify-content: space-between; }
.rooms { list-style: none; margin: 0 0 8px; padding: 0; max-height: 26vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.rooms li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: #ffffff12; }
.rooms .rinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rooms .rtitle { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rooms .rsub { font-size: .78rem; opacity: .7; }
.rooms .rempty { justify-content: center; opacity: .7; font-size: .85rem; }
.players { margin: 6px 0; padding: 8px 10px; background: #ffffff10; border-radius: 8px; font: inherit; font-size: .9rem; white-space: pre-wrap; line-height: 1.5; }
@media (min-width: 900px) {
  #onDlg { flex: 0 1 auto; max-height: 42%; }
  #onDlg .rooms { max-height: 14vh; }
  #onBtn, #onClose { display: none; }
}
