:root {
  --ink: #4a3b52;
  --cream: #fff7ea;
  --pink: #f2738c;
  --pink-dark: #d9566f;
  --lavender: #e9e1ff;
  --font: ui-rounded, "Hiragino Maru Gothic ProN", "Nunito", "Quicksand", "Arial Rounded MT Bold", "Segoe UI", system-ui, sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #7cc46e;
  font-family: var(--font);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
}

#game {
  position: fixed;
  left: 0;
  top: 0;
  image-rendering: pixelated;
  cursor: pointer;
}

#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.label {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}

.label .inner {
  position: absolute;
  bottom: 0;
  left: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: max-content;
}

.label .name {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(74, 59, 82, 0.72);
  color: #fff;
  white-space: nowrap;
}

.label.me .name { background: var(--pink); }
.label .name { transition: opacity 0.3s; }
.label.far .name { opacity: 0; }
.label.npc .name { background: rgba(74, 59, 82, 0.4); }
.label.pet .name { background: rgba(224, 147, 74, 0.85); }

.emote {
  position: absolute;
  left: 0;
  bottom: 14px;
  font-size: 20px;
  animation: float-up 1.6s ease-out forwards;
}

@keyframes float-up {
  from { transform: translate(-50%, 0) scale(0.5); opacity: 0; }
  20% { transform: translate(-50%, -10px) scale(1.1); opacity: 1; }
  to { transform: translate(-50%, -34px) scale(1); opacity: 0; }
}

#fade {
  position: fixed;
  inset: 0;
  background: var(--cream);
  opacity: 1;
  pointer-events: none;
}
#fade.out { opacity: 0; transition: opacity 0.5s ease-out; }
.label .key {
  display: none;
  margin-left: 4px;
  padding: 0 4px;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}
.label.pokeable .key { display: inline-block; }

.bubble {
  max-width: 220px;
  padding: 5px 9px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  font-size: 13px;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 0 var(--ink);
  animation: pop 0.16s ease-out;
}
.bubble.echo {
  background: var(--lavender);
  border-style: dashed;
  font-style: italic;
}
.bubble.loud { background: #fff3c4; }

@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.pill {
  padding: 5px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 2px 0 var(--ink);
}

.btn {
  padding: 9px 18px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--pink);
  color: #fff;
  font: 700 16px var(--font);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
}
.btn:hover { background: var(--pink-dark); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.small { padding: 4px 10px; border-width: 2px; font-size: 13px; box-shadow: 0 2px 0 var(--ink); background: var(--cream); color: var(--ink); }
.btn.small:hover { background: #ffe9c9; }
.btn.ghost { background: var(--cream); color: var(--ink); }
.btn.ghost:hover { background: #ffe9c9; }

input {
  width: 100%;
  padding: 8px 10px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: 600 15px var(--font);
  -webkit-user-select: text;
  user-select: text;
}
input:focus { outline: 3px solid #f9c2cd; }

#topbar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

#hint {
  position: fixed;
  top: 12px;
  left: 12px;
  max-width: calc(100vw - 480px);
  font-weight: 600;
  opacity: 0.9;
}

#chat {
  position: fixed;
  left: 12px;
  bottom: 12px;
  width: min(360px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#log {
  max-height: 180px;
  overflow-y: auto;
  padding: 8px 10px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: rgba(255, 247, 234, 0.88);
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 2px 0 var(--ink);
  -webkit-user-select: text;
  user-select: text;
}
#log:empty { display: none; }
#log .msg { overflow-wrap: anywhere; }
#log .msg b { color: var(--pink-dark); }
#log .msg.echo { font-style: italic; opacity: 0.75; }
#log .msg.sys { opacity: 0.6; font-size: 12px; }
#log .msg.news { font-size: 12px; opacity: 0.8; }
#log .msg.news.big { opacity: 1; font-weight: 700; }

#chatForm { display: flex; gap: 6px; }
#chatForm .btn { white-space: nowrap; }

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(74, 59, 82, 0.35);
  overflow-y: auto;
}

.card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--cream);
  box-shadow: 0 6px 0 var(--ink);
}
.card.wide { width: min(480px, 100%); margin: auto; }
.card h1, .card h2 { margin: 0; text-align: center; }
.card h1 { font-size: 32px; }
.card .sub { margin: -6px 0 4px; text-align: center; opacity: 0.75; }
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; }
.error { margin: 0; color: #c6384f; font-weight: 700; font-size: 13px; }
.row { display: flex; gap: 10px; justify-content: flex-end; }

.outfit-top { display: flex; gap: 16px; align-items: center; }
.outfit-side { flex: 1; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
#outfitPreview {
  width: 112px;
  height: 140px;
  image-rendering: pixelated;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #c9ecb8;
}

#outfitFields { display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; gap: 8px; align-items: center; }
.field .field-name { width: 74px; font-size: 13px; font-weight: 700; }
.field .options { flex: 1; display: flex; flex-wrap: wrap; gap: 5px; }
.opt {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.opt.style { width: 40px; height: 40px; background: #c9ecb8; overflow: hidden; }
.opt.style canvas { width: 48px; height: 60px; margin: -6px 0 0 -6px; image-rendering: pixelated; display: block; }
.opt.on { outline: 3px solid var(--pink); outline-offset: 1px; }

#toast {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
}

@media (max-width: 1000px) {
  #hint { display: none; }
}

.label.former:not(.me) .name { background: rgba(62, 160, 156, 0.85); }
.label.npc.former .name { background: rgba(62, 160, 156, 0.5); }

.usehint {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  gap: 4px;
  align-items: center;
  width: max-content;
  padding: 1px 6px 1px 2px;
  border-radius: 8px;
  background: rgba(74, 59, 82, 0.72);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  translate: -50% -100%;
  will-change: transform;
}
.usehint .key { padding: 0 4px; border-radius: 4px; background: #fff; color: var(--ink); }

.card .note { font-weight: 600; opacity: 0.7; }

#callout { display: none; }
body.observer #callout {
  display: block;
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 22px;
  font-size: 22px;
  white-space: nowrap;
}
body.observer #callout b { color: var(--pink-dark); }
body.observer #chatForm,
body.observer #hint,
body.observer #outfitBtn,
body.observer #joinNameRow,
body.observer #joinEmailRow { display: none; }
body.observer #log { max-height: 240px; font-size: 14px; }
body.observer #game { cursor: default; }

.debug {
  position: fixed;
  top: 52px;
  right: 12px;
  width: 280px;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: rgba(255, 247, 234, 0.94);
  box-shadow: 0 2px 0 var(--ink);
  font-size: 12px;
}
.debug-head {
  width: 100%;
  padding: 6px 10px;
  border: 0;
  background: none;
  color: var(--ink);
  font: 700 13px var(--font);
  text-align: left;
  cursor: pointer;
}
.debug-head span { font-weight: 600; opacity: 0.7; }
.debug.collapsed .debug-body { display: none; }
.debug-body { display: flex; flex-direction: column; gap: 8px; padding: 0 10px 10px; }
.debug-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.debug-row input { flex: 1; min-width: 0; padding: 4px 8px; font-size: 13px; }
.debug .btn.small { padding: 2px 7px; font-size: 12px; }
.debug h3 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.6; }
#debugActions { display: flex; flex-direction: column; gap: 8px; }

.menu {
  position: absolute;
  z-index: 2;
  left: 0;
  top: 0;
  translate: -50% -100%;
  pointer-events: auto;
  will-change: transform;
}
.menu-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--cream);
  box-shadow: 0 2px 0 var(--ink);
}
.menu-items .btn { text-align: left; white-space: nowrap; }
.key {
  display: inline-block;
  margin-right: 5px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  font-size: 11px;
}
.menu-items .key { background: var(--ink); color: #fff; }
#holding {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}
#holding .key { margin: 0 2px 0 4px; }
#holding { display: flex; gap: 14px; }
body.observer #holding { display: none; }

#offer {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
  background: #fff3c4;
}
#emotes {
  position: fixed;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 4px;
}
#emotes .btn { padding: 4px 6px; font-size: 16px; line-height: 1; }
body.observer #emotes, body.observer #offer { display: none; }
@media (max-width: 1000px) {
  #emotes { bottom: 64px; }
}

.modal.play { background: rgba(74, 59, 82, 0.2); }
.play-card { width: auto; max-width: calc(100vw - 32px); align-items: center; gap: 8px; padding: 16px 18px; }
.play-row { display: flex; gap: 12px; justify-content: space-between; align-items: center; width: 100%; font-size: 14px; font-weight: 700; }
#playCanvas { box-sizing: content-box; image-rendering: pixelated; border: 3px solid var(--ink); border-radius: 10px; cursor: crosshair; touch-action: none; }
.play-note { margin: 0; font-size: 13px; font-weight: 600; opacity: 0.75; text-align: center; }
.play-card .row { justify-content: center; }
.play-card .key { margin: 0 0 0 4px; }

.label.claude .name { background: rgba(217, 119, 87, 0.9); }
.bubble.claude { background: #fde8de; border-color: #a5523a; }
#log .msg.claude b { color: #c0603f; }
