/* 클래식 캐치마인드풍: 연한 하늘색 바탕, 흰 패널, 파란 포인트. 장식 없이 평평하고 또렷하게. */
@font-face {
  font-family: 'Ttukttak';
  src: url('/assets/font/뚝딱감자체.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #d9ebfa;
  --panel: #ffffff;
  --ink: #1d2b3b;
  --muted: #4d5f75;
  --line: #9ec5ea;
  --line-soft: #d4e6f6;
  --blue: #2468c4;
  --blue-dark: #194f99;
  --blue-soft: #e8f2fc;
  --orange: #e8890c;
  --green: #1f8a4c;
  --danger: #c43232;
  --score: #b45309;
  --yellow: #f2c230;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Ttukttak', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 18px;
  font-synthesis: none; /* 단일 굵기 픽셀 폰트가 가짜 볼드로 번지지 않게 */
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
}

/* ---- 아이콘(흰색 SVG를 마스크로 색칠) ---- */
.ico {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  vertical-align: -.25em;
  background: currentColor;
  -webkit-mask: var(--i) center / contain no-repeat;
  mask: var(--i) center / contain no-repeat;
}

/* ---- 버튼 ---- */
button {
  font: inherit;
  font-weight: 600;
  color: var(--blue-dark);
  background: var(--blue-soft);
  border: 2px solid var(--line);
  border-bottom-width: 3px;
  border-radius: var(--radius);
  padding: 0 14px;
  min-height: 44px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .12s, border-color .12s, transform .08s;
}
button:hover:not(:disabled) { background: #d6e8fa; border-color: var(--blue); }
button:active:not(:disabled) { transform: translateY(1px); border-bottom-width: 2px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, .cm-drop:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

.btn-primary { color: #fff; background: var(--blue); border-color: var(--blue-dark); }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-ok { color: #fff; background: var(--green); border-color: #166a39; }
.btn-ok:hover:not(:disabled) { background: #166a39; border-color: #166a39; }
.btn-ghost { background: #fff; color: var(--muted); border-color: var(--line); }
.btn-big { font-size: 20px; min-height: 54px; padding: 0 34px; }

input, select {
  font: inherit;
  color: var(--ink);
  min-height: 44px;
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus { outline: 3px solid var(--orange); outline-offset: 1px; border-color: var(--blue); }

.panel, .card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.3em; margin: 4px 0; }

/* ---- 상단 바 ---- */
.bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px auto 0;
  width: calc(100% - 40px);
  max-width: 1180px;
  padding: 8px 14px;
  background: var(--blue);
  border: 0;
  border-radius: var(--radius);
  color: #fff;
}
.bar h1, .bar h2 { margin: 0; font-size: 22px; }
.bar .grow { flex: 1; }
.bar .muted { color: #cfe3f8; }
.bar button { min-height: 40px; }
.bar .btn-primary { background: var(--orange); border-color: #b86a05; color: #1d2b3b; }
.bar .btn-primary:hover:not(:disabled) { background: #f39a22; border-color: #b86a05; }
.bar .btn-ghost, .bar .btn-info { background: rgba(255, 255, 255, .15); color: #fff; border-color: rgba(255, 255, 255, .45); }
.bar .btn-ghost:hover:not(:disabled), .bar .btn-info:hover:not(:disabled) { background: rgba(255, 255, 255, .28); border-color: #fff; }
.bar .me { display: flex; align-items: center; gap: 8px; }
.bar .me > span:last-child { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sound-btn { padding: 0 10px; }

/* ---- 프로필 아바타 (색 사각형 + 흰 아이콘) ---- */
.avatar {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center; color: #fff;
  background: var(--av, var(--blue)); border-radius: 6px;
}
.avatar .ico { width: 60%; height: 60%; vertical-align: 0; }
/* 직접 그린 프로필 그림 */
.avatar.has-img { background: #fff; border: 2px solid var(--line); overflow: hidden; }
.avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.crown { color: var(--yellow); }

/* ---- 프로필 선택 화면 ---- */
#profile-view { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 0 20px 32px; }
/* 위쪽 파란 띠: 로고와 한 줄 소개. 카드가 띠 아래쪽에 살짝 걸친다 */
.profile-hero { align-self: stretch; margin: 0 -20px; padding: 24px 20px 62px; text-align: center; color: #fff; background: var(--blue); border-bottom: 5px solid var(--blue-dark); }
.profile-hero .logo { margin: 0; font-size: 54px; line-height: 1.1; letter-spacing: 2px; }
.profile-hero .logo .ico { color: var(--orange); margin-right: 10px; width: .8em; height: .8em; vertical-align: -.08em; }
.profile-hero p { margin: 4px 0 0; font-size: 20px; color: #d6e8fb; }
.profile-card { width: min(480px, 100%); margin-top: -40px; padding: 18px 28px 20px; display: grid; gap: 14px; }
.profile-card .step { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.profile-card .step h2 { margin: 0; display: flex; align-items: center; gap: 10px; font-size: 20px; color: var(--ink); }
.profile-card .step .no { width: 30px; height: 30px; display: grid; place-items: center; flex: none; border-radius: 50%; background: var(--blue); color: #fff; font-size: 18px; }
.profile-card input { text-align: center; font-size: 20px; width: 100%; min-width: 0; }
.profile-card .go { justify-self: center; }
.profile-card .error { text-align: center; margin: -8px 0; }

/* 프로필 그림판 */
.avatar-pad { display: grid; justify-items: center; gap: 8px; }
.avatar-pad canvas { width: 180px; height: 180px; background: #fff; border: 3px solid var(--blue); border-radius: var(--radius); touch-action: none; cursor: crosshair; }
.pad-tools { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
.pad-tools button { min-height: 44px; font-size: 16px; padding: 0 10px; }
.pad-tools .pad-color { position: relative; width: 28px; height: 28px; min-height: 0; padding: 0; border: 2px solid var(--line); border-radius: 50%; }
.pad-tools .pad-color::before { content: ''; position: absolute; inset: -8px; }
.pad-tools .pad-color.on { border-color: var(--orange); box-shadow: 0 0 0 3px #fbd9a3; }
.pad-tools .pad-size { width: 44px; padding: 0; display: grid; place-items: center; background: #fff; }
.pad-tools .pad-size i { display: block; background: var(--ink); border-radius: 50%; }
.pad-tools .pad-size.on, .pad-tools .pad-eraser.on { border-color: var(--orange); background: #fff4e0; }
.pad-hint { margin: 0; font-size: 16px; }

/* ---- 로비 ---- */
main { width: calc(100% - 40px); max-width: 1180px; margin: 20px auto; }
main h2 { font-size: 20px; margin: 0 0 10px; }

/* 방 화면은 뷰포트 높이에 맞춘다 (좁은 화면에서는 아래 미디어쿼리로 해제) */
#room-view:not([hidden]) { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#room-view > .bar { flex: none; margin-top: 10px; }
#room-view .bar h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 40vw; }
#game-root { flex: 1; min-height: 0; }

.room-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); }
.room-list li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.room-list .tag { padding: 2px 10px; border-radius: 4px; background: var(--blue-soft); color: var(--blue-dark); font-size: 16px; font-weight: 600; }
.room-list .title { flex: 1; font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-list .count { color: var(--muted); font-size: 16px; }
.empty-box { text-align: center; padding: 34px 10px; display: grid; justify-items: center; gap: 10px; }
.empty-box .ico { width: 48px; height: 48px; color: var(--line); }
.empty-box p { margin: 0; }

/* ---- 로비 레이아웃: 방 목록 | 접속자 + 로비 채팅 (뷰포트 높이에 맞춤) ---- */
#lobby-view:not([hidden]) { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#lobby-view > .bar { flex: none; }
main.lobby-grid { flex: 1; min-height: 0; margin: 12px auto 14px; display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; }
.lobby-rooms, .lobby-users, .lobby-chat { padding: 12px 14px; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.lobby-rooms h2, .lobby-users h2, .lobby-chat h2 { margin: 0; font-size: 20px; }
.lobby-grid .count { color: var(--muted); font-size: 17px; font-weight: 500; }
.lobby-rooms .room-list { overflow-y: auto; min-height: 0; align-content: start; }
.lobby-side { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; min-height: 0; min-width: 0; }

.user-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; display: grid; gap: 6px; align-content: start; }
.user-list li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: var(--radius); }
.user-list li.me { background: var(--blue-soft); }
.user-list .avatar { width: 34px; height: 34px; }
.user-list .who { min-width: 0; flex: 1; display: grid; }
.user-list .nick { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-list .where { color: var(--muted); font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-list .where.in-room { color: var(--score); }

.lobby-log { flex: 1; min-height: 0; overflow-y: auto; font-size: 17px; display: flex; flex-direction: column; gap: 3px; }
.lobby-log > div { word-break: break-all; }
.lobby-log b { color: var(--blue-dark); margin-right: 6px; font-weight: 700; }
.lobby-log .mine b { color: var(--score); }
.lobby-log .sys { color: var(--muted); }
#lobby-form { display: flex; gap: 6px; }
#lobby-form input { flex: 1; min-width: 0; }

dialog { border: 0; background: transparent; padding: 0; width: min(400px, 92vw); overflow: visible; color: var(--ink); }
dialog::backdrop { background: rgba(20, 50, 90, .45); }
dialog form { padding: 22px; }
dialog h3 { margin: 0 0 14px; font-size: 22px; }
dialog label { display: grid; gap: 4px; margin-bottom: 12px; font-size: 17px; color: var(--muted); font-weight: 600; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: var(--radius); z-index: 50;
}

/* ---- 효과(fx.js): 절제된 알림 ---- */
.fx-banner {
  position: fixed; left: 50%; top: 36%; z-index: 45; pointer-events: none;
  padding: 14px 40px; text-align: center; white-space: nowrap;
  background: var(--blue); color: #fff; border-radius: var(--radius); border-bottom: 4px solid var(--blue-dark);
  font-size: clamp(22px, 4vw, 34px); font-weight: 700;
  animation: banner 1.6s ease-out forwards;
}
.fx-banner small { display: block; font-size: .5em; font-weight: 500; color: #cfe3f8; }
@keyframes banner {
  0% { transform: translate(-50%, -30%) scale(.9); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -70%) scale(1); opacity: 0; }
}

.fx-float {
  position: fixed; z-index: 45; pointer-events: none; font-size: 22px; font-weight: 700; color: var(--score);
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
  animation: float-up 1.2s ease-out forwards;
}
@keyframes float-up { from { transform: translate(-50%, 0); opacity: 0; } 15% { opacity: 1; } to { transform: translate(-50%, -50px); opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

@media (max-width: 860px) {
  #room-view:not([hidden]), #lobby-view:not([hidden]) { height: auto; display: block; }
  main.lobby-grid { grid-template-columns: minmax(0, 1fr); margin: 10px; width: auto; }
  .lobby-side { grid-template-rows: none; }
  .lobby-users .user-list { max-height: 220px; }
  .lobby-chat { height: 320px; }
}
@media (max-width: 700px) {
  .bar, #room-view > .bar { gap: 8px; padding: 8px 12px; margin: 8px 10px 0; width: auto; }
  .bar h1, .bar h2 { font-size: 20px; }
  #room-meta { display: none; }
  .bar .grow { display: none; }
  .bar .sound-btn:last-child { margin-left: auto; }
  main { width: auto; margin: 14px 10px; }
  .profile-card { padding: 20px 16px; }
  .profile-hero { padding: 26px 16px 64px; }
  .profile-hero .logo { font-size: 46px; }
  .profile-hero p { font-size: 18px; }
}

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

/* ---- 옵션 폼(options.js): 방 만들기 · 방 설정 공용 ---- */
.opt-multi { margin: 0 0 12px; padding: 8px 10px; border: 2px solid var(--line-soft); border-radius: var(--radius); min-width: 0; }
.opt-multi legend { padding: 0 6px; font-weight: 600; color: var(--muted); }
.opt-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.opt-actions button { min-height: 40px; font-size: 16px; padding: 0 10px; }
.opt-count { margin-left: auto; color: var(--muted); font-size: 16px; }
.opt-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 8px; }
label.chk { display: flex; align-items: center; gap: 8px; margin: 0; min-height: 36px; font-size: 17px; font-weight: 500; color: var(--ink); cursor: pointer; }
label.chk input { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--blue); flex: none; }
dialog form { max-height: 92vh; overflow-y: auto; }
dialog .actions { position: sticky; bottom: -22px; margin-bottom: -22px; padding: 10px 0 22px; background: var(--panel); }

/* ---- 스크롤바: 파란 둥근 손잡이 + 연한 하늘색 홈 (설정 창·채팅·목록 공통) ---- */
::-webkit-scrollbar { width: 14px; height: 14px; }
::-webkit-scrollbar-track { background: var(--blue-soft); border-radius: 8px; }
::-webkit-scrollbar-thumb { background: var(--blue); border: 3px solid var(--blue-soft); border-radius: 8px; min-height: 44px; }
::-webkit-scrollbar-thumb:hover { background: var(--blue-dark); }
::-webkit-scrollbar-thumb:active { background: var(--orange); }
::-webkit-scrollbar-corner { background: transparent; }
/* Firefox 등 ::-webkit-scrollbar를 지원하지 않는 브라우저 */
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: var(--blue) var(--blue-soft); }
}

/* 배경음 볼륨 슬라이더 (상단 바) */
.bar .bgm-vol { width: 84px; min-height: 0; padding: 0; accent-color: var(--orange); background: none; border: 0; }

/* ---- 설정 창 / 타이머 ---- */
.settings-btn { position: relative; padding: 0 10px; }
.settings-card { padding: 22px; }
.settings-card .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.timer-box { display: grid; gap: 10px; justify-items: center; padding: 14px; border: 2px solid var(--line-soft); border-radius: var(--radius); background: var(--blue-soft); }
.timer-box h4 { margin: 0; justify-self: start; font-size: 19px; }
.timer-box h4 .muted { font-size: 16px; margin-left: 6px; }
.timer-face { font-size: 64px; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ink); }
.timer-face.low { color: var(--orange); }
.timer-face.done { color: #d63a3a; animation: timer-blink .6s steps(2) infinite; }
@keyframes timer-blink { 50% { opacity: .35; } }
.timer-btns { display: flex; gap: 8px; }
.timer-box p { margin: 0; font-size: 15px; }
@media (prefers-reduced-motion: reduce) { .timer-face.done { animation: none; } }
.timer-box .timer-loop { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 17px; color: var(--ink); cursor: pointer; }
