:root {
  --navy: #0d2a63; --navy-2: #123a7c; --blue: #1469e6; --blue-2: #0b56c7;
  --ink: #16223a; --mute: #66728a; --line: #e4e9f2; --panel: rgba(13, 34, 76, .78);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d2a63; color: #fff; overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; }
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; border: 0; cursor: pointer; color: inherit; background: none; }
button:focus-visible, input:focus-visible { outline: 2px solid #ffd54a; outline-offset: 2px; }
[hidden] { display: none !important; }

#fade { position: fixed; inset: 0; background: #06122b; opacity: 0; pointer-events: none; transition: opacity .35s; z-index: 30; }
#fade.on { opacity: 1; }

.primary { background: linear-gradient(180deg, #2b84ff, var(--blue-2)); color: #fff; font-weight: 800; border-radius: 14px; padding: 12px 22px; box-shadow: 0 6px 14px rgba(11, 86, 199, .35); }
.primary:active { transform: translateY(1px); }
.primary:disabled { filter: grayscale(.7); opacity: .6; cursor: default; }
.primary.big { font-size: 20px; padding: 16px 44px; border-radius: 16px; }

/* 첫 화면 */
.screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: linear-gradient(180deg, rgba(8, 24, 60, .35), rgba(8, 24, 60, .72)); }
.title-card { text-align: center; }
.title-card .eyebrow { margin: 0 0 8px; font-weight: 700; letter-spacing: .02em; opacity: .9; }
.title-card h1 { margin: 0 0 26px; font-size: clamp(38px, 8vw, 68px); line-height: 1.08; font-weight: 900; text-shadow: 0 4px 20px rgba(0, 0, 0, .45); word-break: keep-all; }
.status { margin-top: 14px; min-height: 1.3em; font-size: 14px; opacity: .85; }

/* 모달 */
#modal-root { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
.backdrop { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(5, 14, 36, .5); pointer-events: auto; }
.modal { width: min(520px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--navy); border-radius: 20px; overflow: hidden; box-shadow: 0 20px 50px rgba(0, 0, 0, .45); }
.modal > header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; font-size: 18px; font-weight: 800; }
.modal > header .x { font-size: 22px; line-height: 1; padding: 2px 8px; }
.modal .sheet { background: #fff; color: var(--ink); border-radius: 16px; margin: 0 6px 6px; padding: 16px; overflow-y: auto; user-select: text; -webkit-user-select: text; }
.modal .foot { display: flex; justify-content: center; margin-top: 14px; }
.modal .foot .primary { min-width: 190px; }
.alert { width: min(360px, 100%); }
.alert p { margin: 4px 0 2px; text-align: center; font-weight: 700; line-height: 1.5; word-break: keep-all; }

.total { color: var(--mute); margin: 0 0 12px; font-size: 14px; }
.total b { color: var(--blue-2); }
.channels { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.channels button { display: flex; justify-content: space-between; padding: 10px 14px; border-radius: 10px; background: #f3f6fb; color: var(--ink); font-weight: 700; }
.channels button span { font-weight: 500; color: var(--mute); }
.channels button.on { background: var(--blue); color: #fff; }
.channels button.on span { color: #dbe8ff; }
.channels button:disabled { opacity: .45; }

.setting { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting label { font-weight: 700; }
.setting small { grid-column: 1 / -1; color: var(--mute); }
.setting input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--blue); }
.setting input[type=text], .field input { font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid #cfd8e8; width: 100%; color: var(--ink); background: #fff; user-select: text; -webkit-user-select: text; }
.setting .nick { grid-column: 1 / -1; display: flex; gap: 8px; }
.setting .nick .primary, .setting .wide { padding: 9px 14px; white-space: nowrap; border-radius: 10px; box-shadow: none; }
.setting .wide { grid-column: 1 / -1; }
.switch { width: 46px; height: 26px; border-radius: 13px; background: #c8d1e0; position: relative; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch[aria-pressed=true] { background: var(--blue); }
.switch[aria-pressed=true]::after { left: 23px; }

/* 캐릭터 만들기 */
#creator { position: fixed; inset: 0; z-index: 15; pointer-events: none; display: flex; justify-content: flex-end; padding: 12px; }
.creator-panel { pointer-events: auto; width: min(400px, 100%); height: 100%; display: flex; flex-direction: column; background: #fff; color: var(--ink); border-radius: 20px; overflow: hidden; box-shadow: 0 14px 40px rgba(0, 0, 0, .4); }
.creator-panel > header { background: var(--navy); color: #fff; padding: 14px 18px; font-size: 18px; font-weight: 800; }
.creator-body { flex: 1; overflow-y: auto; padding: 14px 16px; user-select: text; -webkit-user-select: text; }
.creator-panel > footer { padding: 12px 16px; border-top: 1px solid var(--line); }
.creator-panel > footer .primary { width: 100%; }
.field { margin-bottom: 14px; }
.field > b { display: block; margin-bottom: 6px; font-size: 14px; }
.field > b em { font-style: normal; font-weight: 500; color: var(--mute); margin-left: 4px; }
.err { color: #d0342a; font-size: 13px; margin-top: 4px; min-height: 1em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 7px 12px; border-radius: 999px; background: #f0f3f9; color: var(--ink); font-size: 14px; font-weight: 600; }
.chips button.on { background: var(--blue); color: #fff; }
.chips button i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; border: 1px solid rgba(0, 0, 0, .15); }

/* 게임 화면 */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud input, #hud form { pointer-events: auto; }
.hud-top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); display: flex; align-items: flex-start; gap: 8px; }
.place { background: var(--panel); padding: 7px 14px; border-radius: 14px; display: flex; flex-direction: column; font-size: 13px; backdrop-filter: blur(6px); }
.place strong { font-size: 15px; }
.place span { opacity: .85; }
#minimap { width: 76px; height: 76px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .75); background: rgba(13, 34, 76, .68); }
.round { flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; }
#btn-photo { margin-left: auto; }
.place { min-width: 0; white-space: nowrap; }
.place strong, .place span { overflow: hidden; text-overflow: ellipsis; }

/* 사진 찍기 */
html.photo #hud { display: none; }
#photo-ui { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
#photo-ui button { pointer-events: auto; }
#photo-close { position: absolute; top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); font-size: 18px; }
.photo-view { background: var(--panel); padding: 10px 18px; border-radius: 999px; font-weight: 800; font-size: 14px; }
#photo-ui .photo-view { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
#shutter { position: absolute; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); width: 72px; height: 72px; margin-left: -36px; border-radius: 50%; background: #fff; border: 5px solid rgba(255, 255, 255, .45); background-clip: padding-box; box-shadow: 0 2px 12px rgba(0, 0, 0, .4); }
#shutter:active { transform: scale(.92); }
#flash { position: fixed; inset: 0; z-index: 13; background: #fff; opacity: 0; pointer-events: none; }
#flash.on { animation: flash .28s ease-out; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }
#photo-review { position: fixed; inset: 0; z-index: 14; display: grid; place-items: center; padding: 14px; background: rgba(5, 14, 36, .78); }
.photo-card { width: min(640px, 100%); max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
#photo-img { max-width: 100%; min-height: 0; flex: 0 1 auto; max-height: calc(100% - 96px); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); -webkit-touch-callout: default; user-select: auto; -webkit-user-select: auto; }
.photo-card .status { margin: 0; }
.photo-btns { display: flex; gap: 10px; }

#notice { position: absolute; top: 96px; left: 0; right: 0; height: 40px; overflow: hidden; }
#notice div { position: absolute; top: 0; white-space: nowrap; left: 100%; padding: 8px 20px; background: rgba(160, 30, 90, .85); border-radius: 999px; font-weight: 800; animation: slide 14s linear forwards; }
@keyframes slide { to { transform: translateX(calc(-1 * var(--w, 100vw) - 100%)); } }

.left-stack { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: max(10px, env(safe-area-inset-bottom)); width: min(290px, 44vw); display: flex; flex-direction: column; gap: 8px; }
#stick { pointer-events: auto; touch-action: none; width: 118px; height: 118px; border-radius: 50%; background: rgba(255, 255, 255, .22); border: 2px solid rgba(255, 255, 255, .55); position: relative; margin-left: 8px; }
#knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px; border-radius: 50%; background: rgba(255, 255, 255, .92); box-shadow: 0 2px 8px rgba(0, 0, 0, .3); }
.chat { background: rgba(13, 26, 56, .62); border-radius: 12px; padding: 6px 8px; backdrop-filter: blur(4px); }
#chat-log { list-style: none; margin: 0 0 5px; padding: 0; font-size: 12px; line-height: 1.42; min-height: 34px; }
#chat-log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
#chat-log b { color: #9fd0ff; font-weight: 700; }
#chat-form { display: flex; gap: 5px; }
#chat-input { flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 9px; border: 0; background: rgba(255, 255, 255, .94); color: var(--ink); user-select: text; -webkit-user-select: text; }
.send { background: var(--blue); padding: 5px 10px; border-radius: 9px; font-size: 13px; font-weight: 700; flex: none; }

.actions { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); left: calc(min(290px, 44vw) + 26px); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.bar { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.act { width: 56px; height: 58px; border-radius: 14px; background: var(--panel); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 11px; font-weight: 700; backdrop-filter: blur(6px); }
.act i { font-style: normal; font-size: 20px; line-height: 1.1; }
.act.on { background: var(--blue); box-shadow: 0 0 0 2px #fff inset; }
.act:disabled { opacity: .45; cursor: default; }
.ctx { min-width: 150px; }
.menu { display: flex; flex-direction: column; gap: 4px; background: var(--panel); padding: 8px; border-radius: 14px; backdrop-filter: blur(6px); }
.menu button { padding: 10px 16px; border-radius: 10px; text-align: left; font-weight: 700; font-size: 14px; }
.menu button:hover { background: rgba(255, 255, 255, .14); }
.menu button.here { color: #ffd54a; }
#mat-menu { flex-direction: row; }

@media (max-width: 760px) {
  #creator { padding: 0; align-items: flex-end; }
  .creator-panel { width: 100%; height: 58dvh; border-radius: 20px 20px 0 0; }
  .act { width: 46px; height: 50px; font-size: 10px; }
  .act i { font-size: 17px; }
  .bar { gap: 4px; }
  #stick { width: 104px; height: 104px; }
}
@media (max-width: 430px) {
  .hud-top { gap: 6px; }
  .place { padding: 6px 9px; font-size: 12px; }
  .place strong { font-size: 12.5px; }
  .round { width: 38px; height: 38px; }
  #minimap { width: 62px; height: 62px; }
}
@media (max-height: 460px) {
  .left-stack { flex-direction: row; align-items: flex-end; width: min(430px, 60vw); }
  #stick { flex: none; width: 96px; height: 96px; margin-left: 0; }
  .chat { flex: 1; min-width: 0; }
  .actions { left: calc(min(430px, 60vw) + 22px); }
  #chat-log { font-size: 11px; }
  #minimap { width: 58px; height: 58px; }
  #notice { top: 66px; }
  #creator { justify-content: flex-end; padding: 8px; }
  .creator-panel { width: min(380px, 56vw); height: 100%; border-radius: 16px; }
}
/* 세로로 든 휴대폰에서 화면만 돌려 가로로 쓴다. 크기 기준은 돌린 뒤의 폭과 높이다. */
html.turned body { position: fixed; left: 0; top: 0; width: var(--w); height: var(--h); transform-origin: 0 0; transform: translateX(var(--h)) rotate(90deg); }
html.turned .left-stack { flex-direction: row; align-items: flex-end; width: min(430px, calc(var(--w) * .6)); }
html.turned #stick { flex: none; width: 96px; height: 96px; margin-left: 0; }
html.turned .chat { flex: 1; min-width: 0; }
html.turned .actions { left: calc(min(430px, calc(var(--w) * .6)) + 22px); }
html.turned #chat-log { font-size: 11px; }
html.turned #minimap { width: 58px; height: 58px; }
html.turned #notice { top: 66px; }
html.turned #creator { justify-content: flex-end; align-items: stretch; padding: 8px; }
html.turned .creator-panel { width: min(380px, 56%); height: 100%; border-radius: 16px; }
html.turned .modal { max-height: calc(var(--h) - 32px); }
@media (prefers-reduced-motion: reduce) {
  #fade { transition: none; }
}
