@font-face {
  font-family: 'Cubic11';
  src: url('https://cdn.jsdelivr.net/gh/ACh-K/Cubic-11@main/fonts/web/Cubic_11.woff2') format('woff2');
  font-display: swap;
}

:root {
  --ink: #1b1b2a;
  --paper: #f4ead2;
  --paper-dark: #d9c9a3;
  --accent: #e2574c;
  --green: #3f8f4a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #22301f;
  font-family: 'Cubic11', 'PingFang TC', 'Microsoft JhengHei', monospace;
  color: var(--ink);
  -webkit-font-smoothing: none;
}

#stage { position: fixed; inset: 0; }

#game {
  position: absolute;
  top: 0; left: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#ui {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
}

.pixel-box {
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, .35), inset -3px -3px 0 var(--paper-dark);
}

.pixel-box.small { padding: 6px 10px; font-size: 14px; }

.pixel-btn {
  font: inherit;
  font-size: 16px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: 3px solid var(--ink);
  box-shadow: inset -3px -3px 0 #a8352d;
  cursor: pointer;
}
.pixel-btn:active { box-shadow: inset 3px 3px 0 #a8352d; }

/* 進場 */
.panel-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 16, 10, .55);
  padding: 16px;
}

#join-form {
  width: min(380px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#join-form h1 { margin: 0; font-size: 33px; font-weight: normal; letter-spacing: 4px; }
#join-form .sub { margin: 0 0 6px; font-size: 14px; }
#join-form label { font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
#join-form input {
  font: inherit;
  font-size: 16px;
  padding: 6px 8px;
  border: 3px solid var(--ink);
  background: #fff;
}
#join-form .hint { margin: 4px 0 0; font-size: 12px; color: #5b5240; line-height: 1.6; }
#join-form select {
  font: inherit;
  font-size: 14px;
  padding: 5px 6px;
  border: 3px solid var(--ink);
  background: #fff;
}
#join-form .error { margin: 0; padding: 6px 8px; background: var(--accent); color: #fff; font-size: 14px; }

#look-preview {
  align-self: center;
  width: 320px;
  height: 116px;
  max-width: 100%;
  image-rendering: pixelated;
  background: #5a9e4b;
  border: 3px solid var(--ink);
}
.look-row { display: grid; grid-template-columns: 40px 1fr; align-items: center; font-size: 14px; }
.opts { display: flex; gap: 4px; flex-wrap: wrap; }
.opts button {
  font: inherit;
  font-size: 13px;
  padding: 3px 8px;
  border: 2px solid var(--ink);
  background: #fff;
  cursor: pointer;
}
.opts button.on { background: #ffe066; box-shadow: inset 0 0 0 2px var(--accent); }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button {
  width: 24px; height: 24px;
  border: 3px solid var(--ink);
  cursor: pointer;
  padding: 0;
}
.swatches button.on { outline: 3px solid var(--accent); outline-offset: 1px; }

/* HUD */
#topleft { position: fixed; top: 12px; left: 12px; display: flex; gap: 8px; align-items: flex-start; }
#build-toggle { font: inherit; font-size: 14px; cursor: pointer; }
#online { position: relative; }
#room-btn {
  font: inherit;
  font-size: 14px;
  background: #ffe066;
  border: 2px solid var(--ink);
  padding: 0 6px;
  margin-right: 4px;
  cursor: pointer;
}
#room-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: -3px;
  z-index: 5;
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, .35);
  padding: 6px;
  max-height: 50vh;
  overflow-y: auto;
  min-width: 200px;
}
#room-list { display: flex; flex-direction: column; gap: 4px; }
#room-list button {
  font: inherit;
  font-size: 14px;
  text-align: left;
  padding: 4px 8px;
  border: 2px solid var(--ink);
  background: #fff;
  cursor: pointer;
}
#room-list button:disabled { color: #8a8070; cursor: default; background: var(--paper-dark); }
#build-toggle.on { background: #ffe066; }

#build-bar {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 4px;
  max-width: calc(100vw - 24px);
  overflow-x: auto;
}
#build-bar button {
  font: inherit;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 56px;
  padding: 4px;
  border: 2px solid var(--ink);
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}
#build-bar button canvas { width: 48px; height: 36px; image-rendering: pixelated; }
#build-bar button b { font-size: 26px; line-height: 36px; font-weight: normal; }
#build-bar button.on { background: #ffe066; box-shadow: inset 0 0 0 2px var(--accent); }
#build-count-box { font-size: 12px; text-align: center; align-self: center; padding: 0 6px; line-height: 1.6; }

#emotes { position: fixed; top: 12px; right: 12px; display: flex; gap: 4px; padding: 4px; }
#emotes button {
  font: inherit;
  font-size: 16px;
  width: 32px; height: 32px;
  border: 2px solid var(--ink);
  background: #fff;
  cursor: pointer;
  padding: 0;
}

#chat {
  position: fixed;
  left: 12px;
  bottom: 12px;
  width: min(340px, calc(100vw - 24px));
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#chat-log {
  height: 140px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.5;
  padding: 2px 4px;
  word-break: break-all;
}
#chat-log .sys { color: #7a6c4f; }
#chat-log .who { color: var(--accent); }
#chat-input {
  font: inherit;
  font-size: 14px;
  width: 100%;
  padding: 5px 6px;
  border: 2px solid var(--ink);
  background: #fff;
}

#toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--paper);
  padding: 8px 14px;
  font-size: 14px;
  border: 3px solid var(--paper);
  text-align: center;
}

/* 建造列出現時，聊天框往上讓位 */
#build-bar:not([hidden]) ~ #chat { bottom: 92px; }

@media (max-width: 600px) {
  #chat-log { height: 90px; }
  #emotes button { width: 28px; height: 28px; font-size: 14px; }
}

[hidden] { display: none !important; }
