* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --panel: rgba(36, 24, 14, 0.92);
  --panel-solid: #24180e;
  --border: #8a6a3a;
  --gold: #e0b44a;
  --text: #f3e6c8;
  --muted: #b9a67e;
  --pixel-font: 'Gulim', '굴림', 'Dotum', '돋움', sans-serif;
  --brush-font: 'Gungsuh', '궁서', 'Batang', serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--pixel-font);
  background: #1b140e;
  color: var(--text);
}

.hidden { display: none !important; }

.panel-frame {
  background: var(--panel);
  border: 2px solid var(--border);
  box-shadow: inset 0 0 0 2px #3b2412, 0 0 0 2px #120c07;
}

/* 로그인 */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, #4a3520, #1b140e 70%);
}

.card {
  width: 340px;
  padding: 28px 26px;
  background: var(--panel-solid);
  border: 3px solid var(--border);
  box-shadow: inset 0 0 0 3px #3b2412, 0 0 0 3px #120c07, 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.card h1 { font-family: var(--brush-font); font-size: 30px; color: var(--gold); letter-spacing: 4px; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: -6px; }
.card label, .card .label { text-align: left; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }

.card input {
  padding: 9px 10px;
  border: 2px solid var(--border);
  background: #120c07;
  color: var(--text);
  font-family: var(--pixel-font);
  font-size: 15px;
  outline: none;
}
.card input:focus { border-color: var(--gold); }

.colors { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.colors button {
  width: 28px;
  height: 28px;
  border: 3px solid #120c07;
  cursor: pointer;
}
.colors button.active { outline: 2px solid var(--gold); outline-offset: 1px; }

#preview { margin: 0 auto; image-rendering: pixelated; background: #3a2a18; border: 2px solid var(--border); }

.card button[type='submit'] {
  padding: 11px;
  border: 2px solid var(--gold);
  background: #7a2016;
  color: #fff3d0;
  font-family: var(--brush-font);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 6px;
  cursor: pointer;
}
.card button[type='submit']:hover { background: #9b2d20; }

/* 게임 */
#game, #canvas { position: fixed; inset: 0; width: 100%; height: 100%; }
#canvas { display: block; image-rendering: pixelated; }

#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 6px;
}
#hud > div, #hud > button {
  padding: 6px 12px;
  font-family: var(--pixel-font);
  font-size: 12px;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--border);
  box-shadow: 0 0 0 2px #120c07;
}
#zone-label { font-weight: 700; color: var(--gold) !important; }
#hud > button { cursor: pointer; }
#board-toggle { background: #7a2016 !important; color: #fff3d0 !important; font-weight: 700; }
#board-toggle:hover { background: #9b2d20 !important; }
#change-name:hover { color: var(--gold) !important; }
#coins { color: #ffe08a !important; font-weight: 700; }
#share { background: #2c5a2a !important; color: #eaffd8 !important; font-weight: 700; }
#share:hover { background: #3b7538 !important; }

#help {
  position: fixed;
  bottom: 12px;
  left: 12px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 2px solid var(--border);
}

#emotes {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 2px solid var(--border);
  box-shadow: 0 0 0 2px #120c07;
}
#emotes button {
  width: 38px;
  height: 38px;
  border: 1px solid #3b2412;
  background: #2e1f12;
  font-size: 20px;
  cursor: pointer;
}
#emotes button:hover { background: #4a3520; border-color: var(--gold); }
#emotes button.shout {
  width: auto;
  padding: 0 10px;
  font-family: var(--brush-font);
  font-size: 14px;
  font-weight: 700;
  color: #fff3d0;
  background: #7a2016;
  white-space: nowrap;
}
#emotes button.shout:hover { background: #9b2d20; }
#emotes button.drink {
  width: auto;
  padding: 0 10px;
  font-size: 15px;
  font-weight: 700;
  color: #fff3d0;
  background: #3d5a2a;
  white-space: nowrap;
}
#emotes button.drink:hover { background: #4f7536; }
#chat-log .room-tag { color: #9fd18b; font-weight: 700; margin-right: 4px; }

#shop-btn, #avg-btn { color: var(--gold) !important; font-weight: 700; }
#coins { cursor: pointer; }

.name-row { display: flex; gap: 6px; }
.name-row input { flex: 1; min-width: 0; }
#nick-random {
  padding: 0 10px;
  font-size: 12px;
  white-space: nowrap;
  background: #3b2412;
  color: var(--gold);
  border: 2px solid var(--border);
  cursor: pointer;
}

#quick {
  position: fixed;
  bottom: 52px;
  left: 12px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 2px #120c07;
  max-width: 420px;
}
#quick.idle { border-color: var(--border); color: var(--muted); }
#quick .row { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
#quick button {
  padding: 3px 10px;
  font-weight: 700;
  color: #fff;
  border: 1px solid #120c07;
  cursor: pointer;
}
#quick button.up { background: #c0281e; }
#quick button.down { background: #1f4fa8; }
#quick span { color: var(--muted); }

#modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
}
.modal-window {
  width: min(360px, calc(100% - 24px));
  background: linear-gradient(#1d2a4a, #121a30);
  border: 3px solid #c9b68c;
  box-shadow: 0 0 0 3px #120c07;
  color: #f3e6c8;
}
.modal-window .dlg-title { display: flex; justify-content: space-between; align-items: center; }
#modal-close { background: none; border: none; color: #f3e6c8; cursor: pointer; font-size: 14px; }
#modal-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
#modal-body p { line-height: 1.5; color: #d8cba8; }
#modal-body select, #modal-body input {
  padding: 7px 8px;
  font-size: 14px;
  background: #0d1424;
  color: #f3e6c8;
  border: 2px solid #5a6a8a;
}
.modal-buttons { display: flex; gap: 8px; }
#modal-body button {
  padding: 6px 14px;
  font-weight: 700;
  color: #1a120c;
  background: #e0b44a;
  border: 2px solid #120c07;
  cursor: pointer;
}
#modal-body button.ghost { background: #3a4a6a; color: #f3e6c8; }
.shop-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; border-bottom: 1px solid #2c3a5a; }

/* 채팅 */
#chat {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 320px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 2px solid var(--border);
  box-shadow: inset 0 0 0 2px #3b2412, 0 0 0 2px #120c07;
  overflow: hidden;
}
#chat.collapsed { bottom: auto; }
#chat.collapsed #chat-log, #chat.collapsed #chat-form { display: none; }

#chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-family: var(--brush-font);
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  background: #3b2412;
  border-bottom: 2px solid var(--border);
}
#chat-toggle { background: none; border: none; color: var(--gold); cursor: pointer; font-size: 14px; }

#chat-log {
  flex: 1;
  list-style: none;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}
#chat-log .system { color: #9fd18b; font-size: 12px; }
#chat-log .npc { background: rgba(224, 180, 74, 0.12); border-left: 3px solid var(--gold); padding-left: 6px; }
#chat-log .name { font-weight: 700; margin-right: 6px; }
#chat-log .time { color: #7d6a4a; font-size: 11px; margin-left: 6px; }

#chat-form { padding: 8px; border-top: 2px solid var(--border); }
#chat-input {
  width: 100%;
  padding: 8px 10px;
  border: 2px solid var(--border);
  background: #120c07;
  color: var(--text);
  font-family: var(--pixel-font);
  font-size: 13px;
  outline: none;
}
#chat-input:focus { border-color: var(--gold); }

#canvas { touch-action: none; }

@media (min-width: 721px) {
  #game.chat-docked #canvas { right: auto; width: calc(100% - 344px); }
  #game.chat-docked #emotes { left: calc((100% - 344px) / 2); }
}

/* 바람의나라풍 대화창 */
#dialog {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 90px;
  z-index: 30;
  background: rgba(0, 0, 0, 0.15);
}
.dlg-window {
  width: min(520px, 92vw);
  background: linear-gradient(180deg, #24345a 0%, #121c34 100%);
  border: 3px solid;
  border-color: #d6dceb #4a5468 #4a5468 #d6dceb;
  box-shadow: 0 0 0 1px #000, inset 0 0 0 1px #000, 6px 6px 0 rgba(0, 0, 0, 0.45);
  font-family: var(--pixel-font);
  animation: dlg-pop 0.12s steps(3);
}
@keyframes dlg-pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.dlg-title {
  padding: 3px 8px;
  background: linear-gradient(90deg, #0a2a8a 0%, #3a6ad0 100%);
  border-bottom: 1px solid #000;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #000;
}
.dlg-body {
  display: flex;
  gap: 12px;
  padding: 12px;
  min-height: 112px;
}
#dialog-portrait {
  flex: none;
  width: 80px;
  height: 96px;
  image-rendering: pixelated;
  background: #0b1222;
  border: 2px solid;
  border-color: #4a5468 #d6dceb #d6dceb #4a5468;
}
#dialog-text {
  flex: 1;
  color: #fff;
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-line;
  text-shadow: 1px 1px 0 #000;
}
#dialog-text::after {
  content: '▼';
  margin-left: 4px;
  font-size: 11px;
  color: #ffe08a;
  animation: dlg-blink 0.8s steps(1) infinite;
}
@keyframes dlg-blink { 50% { opacity: 0; } }
.dlg-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 12px 12px;
}
.dlg-buttons button {
  min-width: 92px;
  padding: 5px 12px;
  font-family: var(--pixel-font);
  font-size: 13px;
  color: #000;
  background: #c3c7cf;
  border: 2px solid;
  border-color: #fff #5a5e66 #5a5e66 #fff;
  box-shadow: 0 0 0 1px #000;
  cursor: pointer;
}
.dlg-buttons button:hover { background: #d4d8e0; }
.dlg-buttons button:active { border-color: #5a5e66 #fff #fff #5a5e66; }

@media (max-width: 720px) {
  #dialog { padding-bottom: calc(28% + 24px); }
  #dialog-text { font-size: 14px; }
}

#toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translate(-50%, -10px);
  padding: 7px 16px;
  font-size: 13px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  background: linear-gradient(180deg, #24345a 0%, #121c34 100%);
  border: 2px solid;
  border-color: #d6dceb #4a5468 #4a5468 #d6dceb;
  box-shadow: 0 0 0 1px #000, 4px 4px 0 rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#joystick {
  display: none;
  position: fixed;
  left: 24px;
  bottom: 24px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(36, 24, 14, 0.55);
  border: 3px solid rgba(224, 180, 74, 0.7);
  touch-action: none;
  z-index: 10;
}
#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(224, 180, 74, 0.85);
  border: 3px solid #3b2412;
  pointer-events: none;
}

@media (pointer: coarse) {
  #joystick { display: block; }
  #help { display: none; }
}

@media (max-width: 720px) {
  #hud { flex-wrap: wrap; right: 8px; top: 8px; left: 8px; gap: 4px; }
  #hud > div, #hud > button { padding: 4px 8px; font-size: 11px; }
  #chat { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 28%; }
  #chat-header { padding: 4px 10px; font-size: 13px; }
  #chat-log { padding: 6px 10px; font-size: 12px; }
  #chat-form { padding: 6px; }
  #chat-input { font-size: 16px; padding: 6px 8px; }
  #emotes { left: auto; right: 8px; transform: none; bottom: calc(28% + 16px); flex-direction: column; }
  #emotes button { width: 34px; height: 34px; font-size: 18px; }
  #emotes button.shout { width: 34px; padding: 0; font-size: 10px; white-space: normal; line-height: 1.1; }
  #emotes button.drink { width: 34px; padding: 0; font-size: 0; }
  #emotes button.drink::before { content: '🍶'; font-size: 18px; }
  #quick { top: 96px; bottom: auto; left: 8px; right: 8px; max-width: none; font-size: 11px; }
  #joystick { left: 16px; bottom: calc(28% + 20px); width: 110px; height: 110px; }
  #help { display: none; }
  #toast { top: 72px; }
}
