* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #101010; }
canvas { display: block; image-rendering: pixelated; cursor: crosshair; }

#loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  font: 20px system-ui, sans-serif; color: #fff; pointer-events: none;
  padding: 24px; text-align: center; z-index: 5;
}
#loading.failed { color: #ff8080; background: #101010; }

#ui { position: fixed; inset: 0; display: none; z-index: 10; }
#ui.open { display: block; }
#ui, #ui * { image-rendering: pixelated; }

.mc-text { display: block; flex: 0 0 auto; }
.mc-btn .mc-text, .mc-key .mc-text { transform: translateY(1px); }

.mc-screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; }
.mc-screen.dirt {
  background: url('textures/dirt.png');
  background-size: 64px 64px;
  box-shadow: inset 0 0 0 200vmax rgba(0, 0, 0, 0.75);
}
.mc-screen.transparent { background: transparent; }
.mc-screen.dim { background: rgba(0, 0, 0, 0.55); }

.mc-title-stack {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 34px;
}
.mc-title-stack:not(.pause) .mc-logo-wrap { transform: translateY(-46px); }
.mc-title-stack:not(.pause) .mc-col { transform: translateY(-76px); }
.mc-title-stack.pause { gap: 20px; }
.mc-title-stack.notice { gap: 10px; transform: translateY(-5px); }
.mc-logo-wrap { position: relative; }
.mc-logo-img { display: block; width: 680px; max-width: 82vw; height: auto; aspect-ratio: 1360 / 453; }
.mc-splash {
  position: absolute; right: -60px; bottom: 2px;
  transform: rotate(-14deg);
  animation: mc-splash 0.45s infinite alternate ease-in-out;
}
@keyframes mc-splash {
  from { transform: rotate(-14deg) scale(1); }
  to { transform: rotate(-14deg) scale(1.08); }
}

.mc-col { display: flex; flex-direction: column; gap: 8px; align-items: center; }

.mc-btn {
  display: flex; align-items: center; justify-content: center;
  height: 40px; padding: 0; cursor: pointer;
  background: #6d6d6d;
  border: 2px solid #000;
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.42), inset -2px -2px 0 rgba(0, 0, 0, 0.35);
}
.mc-btn:hover:not(.disabled) { background: #7a86b0; }
.mc-btn:active:not(.disabled) { box-shadow: inset -2px -2px 0 rgba(255, 255, 255, 0.3), inset 2px 2px 0 rgba(0, 0, 0, 0.4); }
.mc-btn.disabled { background: #3f3f3f; cursor: default; }
.mc-btn.wide { width: 400px; }
.mc-btn.half { width: 300px; }
.mc-btn.third { width: 196px; }
.mc-btn.quart { width: 145px; }
.mc-btn.quarter { width: 146px; }

.mc-header { padding: 14px 0 10px; display: flex; justify-content: center; }
.mc-header.plain { padding: 0; }

.mc-list {
  flex: 1; width: 100%; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 0;
  background: rgba(0, 0, 0, 0.45);
  border-top: 2px solid #000; border-bottom: 2px solid #000;
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.5);
}
.mc-row {
  display: flex; align-items: center; gap: 10px;
  width: 620px; max-width: 92vw; padding: 5px;
  border: 2px solid transparent; cursor: pointer;
}
.mc-row.selected { border-color: #a0a0a0; outline: 2px solid #000; background: rgba(0, 0, 0, 0.55); }
.mc-row-text { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; overflow: hidden; }
.mc-row-meta { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; padding-right: 4px; }
.mc-thumb { width: 64px; height: 64px; object-fit: cover; flex-shrink: 0; }
.mc-thumb.small { width: 44px; height: 44px; }
.mc-empty { padding: 26px 0; }

.mc-footer { display: flex; flex-direction: column; gap: 8px; padding: 12px 0 16px; }
.mc-bar { display: flex; gap: 10px; justify-content: center; }

.mc-form-col { flex: 1; display: flex; flex-direction: column; gap: 22px; justify-content: center; width: 400px; max-width: 90vw; }
.mc-field { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.mc-field .mc-input-wrap { align-self: stretch; }
.mc-input-wrap {
  position: relative; height: 40px; width: 100%;
  background: #000; border: 2px solid #a0a0a0;
}
.mc-input-wrap:focus-within { border-color: #fff; }
.mc-input-view { position: absolute; inset: 0; width: 100%; height: 100%; }
.mc-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  padding: 0 10px; background: transparent; border: none;
  color: transparent; caret-color: transparent; font: 16px monospace;
}
.mc-input:focus { outline: none; }
.mc-input::selection { background: rgba(160, 160, 255, 0.4); }

.mc-avatar { flex: 1; display: flex; align-items: center; justify-content: center; gap: 44px; }
.mc-doll { width: 96px; height: 192px; image-rendering: pixelated; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.45)); }
.mc-swatches { display: flex; flex-direction: column; gap: 14px; }
.mc-swatch-row { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.mc-swatch-cells { display: flex; gap: 6px; }
.mc-swatch {
  width: 34px; height: 34px; padding: 0; cursor: pointer;
  border: 2px solid #000;
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.35), inset -2px -2px 0 rgba(0, 0, 0, 0.35);
}
.mc-swatch.picked { outline: 3px solid #fff; }

.mc-corner-left { position: absolute; left: 6px; bottom: 6px; }
.mc-corner-right { position: absolute; right: 6px; bottom: 6px; }

.mc-panel { flex: 1; display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.mc-gap { width: 300px; }
.mc-slider { position: relative; width: 300px; height: 40px; border: 2px solid #000; cursor: pointer; touch-action: none; }
.mc-slider-view { position: absolute; inset: 0; width: 100%; height: 100%; }
.mc-keyrow {
  display: flex; align-items: center; justify-content: space-between;
  width: 620px; max-width: 92vw; padding: 4px 6px;
}
.mc-key {
  display: flex; align-items: center; justify-content: center;
  min-width: 130px; height: 34px; padding: 0 10px;
  background: #6d6d6d; border: 2px solid #000;
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.42), inset -2px -2px 0 rgba(0, 0, 0, 0.35);
}

.mc-screen.death { background: rgba(96, 12, 12, 0.55); }
.mc-death-title { margin-bottom: 6px; }
.mc-row.slim { width: 480px; padding: 4px 8px; }
.mc-packs { flex: 1; display: flex; gap: 18px; justify-content: center; align-items: stretch; padding: 12px 0; width: 100%; }
.mc-pack-pane { display: flex; flex-direction: column; width: 360px; max-width: 44vw; }
.mc-pane-head { display: flex; justify-content: center; padding: 6px 0; }
.mc-pack-list {
  flex: 1; display: flex; flex-direction: column; gap: 6px; align-items: center; padding: 10px 0;
  background: rgba(0, 0, 0, 0.45); border-top: 2px solid #000; border-bottom: 2px solid #000;
  overflow-y: auto;
}
.mc-pack-list .mc-row.slim { width: 330px; }

.mc-adv-frame {
  flex: 1; display: flex; flex-direction: column; gap: 10px; justify-content: center; align-items: center;
  width: 100%; padding: 12px 0;
  background: rgba(0, 0, 0, 0.45); border-top: 2px solid #000; border-bottom: 2px solid #000;
}
.mc-adv {
  display: flex; align-items: center; gap: 12px; width: 520px; max-width: 90vw; padding: 8px 10px;
  background: #3a3a3a; border: 2px solid #000;
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.25), inset -2px -2px 0 rgba(0, 0, 0, 0.35);
  opacity: 0.55;
}
.mc-adv.done { opacity: 1; box-shadow: inset 0 0 0 2px #d9a72c, inset 4px 4px 0 rgba(255, 255, 255, 0.2); }
.mc-adv-icon { width: 40px; height: 40px; }

.mc-credits { flex: 1; overflow: hidden; width: 100%; display: flex; justify-content: center; }
.mc-credits-roll {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  animation: mc-credits 26s linear infinite;
}
.mc-credits-gap { height: 26px; }
@keyframes mc-credits {
  from { transform: translateY(72vh); }
  to { transform: translateY(-110%); }
}

.mc-chat {
  position: fixed; left: 8px; bottom: 48px; width: 480px; max-width: 70vw;
  display: none; flex-direction: column; z-index: 12;
}
.mc-chat.open, .mc-chat.has-lines { display: flex; }
body.touch .mc-chat.open { top: calc(10px + var(--tc-safe-top, 0px)); bottom: auto; left: calc(8px + var(--tc-safe-left, 0px)); max-width: 60vw; }
body.touch .mc-chat.open .mc-chat-lines { max-height: 96px; overflow: hidden; justify-content: flex-end; }
.mc-chat-lines { display: flex; flex-direction: column; }
.mc-chat-line { background: rgba(0, 0, 0, 0.5); padding: 1px 4px; }
.mc-chat-entry { height: 34px; display: none; position: absolute; top: 100%; margin-top: 6px; left: 0; right: 0; }
.mc-chat.open .mc-chat-entry { display: block; }
.mc-chat-entry.mc-input-wrap { background: rgba(0, 0, 0, 0.5); border: none; }
.mc-chat-suggest { position: absolute; top: 100%; margin-top: 6px; transform: translateY(-100%); background: rgba(0, 0, 0, 0.7); padding: 2px 4px; display: none; z-index: 5; }
.mc-chat.open .mc-chat-suggest.has-items { display: block; }
.mc-chat-suggest-row { padding: 1px 2px; }

.mc-tablist {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  display: none; flex-direction: column; align-items: center; gap: 4px;
  min-width: 320px; padding: 8px 14px; z-index: 12;
  background: rgba(0, 0, 0, 0.55); border: 2px solid #000;
}
.mc-tablist.open { display: flex; }
.mc-tablist-row { display: flex; align-items: flex-start; gap: 6px; background: rgba(255, 255, 255, 0.08); padding: 3px 10px 1px; }
.mc-tablist-avatar { width: 16px; height: 16px; image-rendering: pixelated; }
.mc-tablist-badge { margin-right: -6px; transform: translateY(0.5px); }

.mc-sleep {
  position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%);
  display: none; z-index: 12;
}
.mc-sleep.open { display: block; }

.mc-identity { position: absolute; right: 8px; top: 8px; pointer-events: none; }
.mc-title-row { position: relative; display: flex; gap: 8px; margin-top: 40px; }
.mc-btn.square { width: 44px; flex: none; }
.mc-title-row .mc-btn.square { position: absolute; left: -52px; top: 0; }
.mc-btn.square img { width: 30px; height: 30px; image-rendering: pixelated; }
.mc-row-title { display: flex; align-items: center; gap: 8px; }
.mc-pin { width: 22px; height: 22px; image-rendering: pixelated; transform: translateY(-2px); }
.mc-tooltip {
  position: fixed; z-index: 40; pointer-events: none;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 8px 10px;
  background: rgba(16, 0, 16, 0.94) padding-box;
  border: 2px solid transparent;
  border-image: linear-gradient(to bottom, rgba(80, 0, 255, 0.55), rgba(40, 0, 127, 0.55)) 1;
}
.mc-tooltip-gap { height: 8px; }

canvas#game { touch-action: none; }

#rotate-gate {
  position: fixed; inset: 0; z-index: 60; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: #101010 url('textures/dirt.png');
  background-size: 64px 64px;
  box-shadow: inset 0 0 0 200vmax rgba(0, 0, 0, 0.78);
}
#fullscreen-gate {
  position: fixed; inset: 0; z-index: 70; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 24px;
  background: #101010 url('textures/dirt.png');
  background-size: 64px 64px;
  box-shadow: inset 0 0 0 200vmax rgba(0, 0, 0, 0.78);
}
#fullscreen-gate .mc-text { max-width: 88vw; height: auto; }
#fullscreen-gate .mc-btn { width: min(280px, 80vw); margin-top: 6px; }
#fullscreen-gate .mc-btn .mc-text { max-width: 90%; }
.rotate-phone {
  width: 46px; height: 78px; border: 4px solid #fff; border-radius: 8px;
  animation: rotate-phone 1.6s ease-in-out infinite;
}
@keyframes rotate-phone {
  0%, 25% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(90deg); }
}

#touch-ui { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#touch-ui .touch-cluster { position: absolute; display: flex; gap: 14px; }
#touch-ui .touch-cluster.left { left: 18px; bottom: 18px; }
#touch-ui .touch-cluster.right { right: 18px; bottom: 18px; flex-direction: column-reverse; }
#touch-ui .touch-cluster.top { left: calc(18px + var(--tc-safe-left, 0px)); top: calc(10px + var(--tc-safe-top, 0px)); flex-direction: column; align-items: flex-start; gap: 8px; }
.touch-btn {
  pointer-events: auto; touch-action: none; user-select: none;
  width: 66px; height: 66px; padding: 0; border: none;
  background: transparent center / 100% 100% no-repeat;
  image-rendering: pixelated; opacity: 0.78; font-size: 0; color: transparent;
}
.touch-btn.t-left { background-image: url('textures/touch_left.png'); }
.touch-btn.t-left.held { background-image: url('textures/touch_left_pressed.png'); }
.touch-btn.t-right { background-image: url('textures/touch_right.png'); }
.touch-btn.t-right.held { background-image: url('textures/touch_right_pressed.png'); }
.touch-btn.t-down { background-image: url('textures/touch_down.png'); }
.touch-btn.t-down.held { background-image: url('textures/touch_down_pressed.png'); }
.touch-btn.t-jump { background-image: url('textures/touch_jump.png'); }
.touch-btn.t-jump.held { background-image: url('textures/touch_jump_pressed.png'); }
.touch-btn.bar {
  width: 64px; height: 26px; font: 700 13px monospace; color: #3a3a3a;
  background-image: url('textures/touch_button.png');
}
.touch-btn.bar.held { background-image: url('textures/touch_button_pressed.png'); color: #fff; }

html, body, body * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
input, textarea { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }

body.tma .mc-screen { padding-top: var(--tc-safe-top, 0px); }

@media (max-height: 500px) {
  .mc-logo-img { width: 420px; max-width: 56vw; }
  .mc-title-stack { gap: 12px; }
  .mc-title-stack:not(.pause) .mc-logo-wrap { transform: translateY(-28px); }
  .mc-title-stack:not(.pause) .mc-col { transform: translateY(-24px); }
  .mc-title-stack:not(.pause) .mc-title-row { transform: translateY(-16px); }
  .mc-col { gap: 6px; }
  .mc-btn { height: 36px; }
  .mc-btn.wide { width: 320px; }
  .mc-btn.half { width: 260px; }
  .mc-btn.third { width: 180px; }
  .mc-btn.quart, .mc-btn.quarter { width: 132px; }
  .mc-btn .mc-text, .mc-key .mc-text { max-width: calc(100% - 10px); height: auto; }
  .mc-identity { display: none; }
  .mc-header { padding: 8px 0 6px; }
  .mc-footer { padding: 8px 0 10px; gap: 6px; }
  .mc-row { width: 560px; }
  .mc-splash { right: -30px; }
  .mc-corner-left, .mc-corner-right { display: none; }
}

.rotate-sub { display: flex; flex-direction: column; align-items: center; gap: 6px; opacity: 0.85; }
