:root {
  color-scheme: dark;
  --game-w: 100vw;
  --game-h: 100vh;
  --game-aspect: 1.7777778;
  --panel: rgba(52, 33, 14, 0.88);
  --gold: #f5d487;
  --text: #fff0cf;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  display: grid;
  place-items: center;
  background: #050403;
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  user-select: none;
}

.client-shell {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  background: #050403;
  overflow: hidden;
}

.game-window {
  position: relative;
  width: min(100vw, calc(100vh * var(--game-aspect)));
  height: min(100vh, calc(100vw / var(--game-aspect)));
  aspect-ratio: var(--game-aspect);
  overflow: hidden;
  background: #050403;
  box-shadow: none;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
}

.auth-brand {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: clamp(10px, 3.2vh, 28px);
  width: min(78%, 720px);
  aspect-ratio: 760 / 180;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 14px 18px rgba(0, 0, 0, 0.58));
  transition: opacity 180ms ease, transform 180ms ease;
}

.game-window.auth-active .auth-brand {
  opacity: 1;
  animation: brandFloat 4.6s ease-in-out infinite;
}

.game-window.auth-register .auth-brand {
  top: clamp(4px, 1.5vh, 14px);
  width: min(68%, 650px);
}

.auth-brand-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.brand-main,
.brand-back,
.brand-edge {
  font-family: "SimHei", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 94px;
  font-weight: 900;
  letter-spacing: 0;
  paint-order: stroke fill;
  dominant-baseline: alphabetic;
}

.brand-back {
  fill: transparent;
  stroke: rgba(55, 38, 24, 0.82);
  stroke-width: 9px;
  stroke-linejoin: round;
  filter: drop-shadow(0 7px 5px rgba(0, 0, 0, 0.5));
}

.brand-main {
  fill: url(#brandFill);
  stroke: rgba(255, 231, 156, 0.94);
  stroke-width: 4px;
  filter: url(#brandRough);
  animation: brandNeon 2.8s ease-in-out infinite;
}

.brand-edge {
  fill: transparent;
  stroke: url(#brandStroke);
  stroke-width: 5.5px;
  stroke-dasharray: 34 260;
  filter: url(#brandGlow);
  animation: brandTrace 2.9s linear infinite;
}

.brand-char {
  transform-box: fill-box;
  transform-origin: center;
}

.brand-char-1 { animation: stoneLiftA 4.5s ease-in-out infinite; }
.brand-char-2 { animation: stoneLiftB 4.2s ease-in-out infinite; }
.brand-char-3 { animation: stoneLiftC 4.7s ease-in-out infinite; }
.brand-char-4 { animation: stoneLiftD 4.3s ease-in-out infinite; }

.brand-cracks {
  fill: none;
  stroke: rgba(83, 45, 20, 0.66);
  stroke-width: 2.4px;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 0 rgba(255, 231, 158, 0.42));
  opacity: 0.82;
  animation: crackFlash 3.8s ease-in-out infinite;
}

.brand-stone-chips {
  fill: #9bdc94;
  stroke: rgba(64, 82, 50, 0.78);
  stroke-width: 2px;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.28)) url(#brandGlow);
  opacity: 0.96;
  animation: chipJitter 3.5s steps(2, end) infinite;
}

.brand-sub {
  fill: #d2fff3;
  stroke: rgba(5, 12, 14, 0.96);
  stroke-width: 5px;
  paint-order: stroke fill;
  font: 800 17px Georgia, "Times New Roman", serif;
  letter-spacing: 8px;
  opacity: 0.96;
  animation: brandSubPulse 3.4s ease-in-out infinite;
}

.brand-orbits {
  fill: none;
  stroke-linecap: round;
  stroke-width: 2.2px;
  stroke: rgba(90, 255, 241, 0.7);
  filter: url(#brandGlow);
  opacity: 0.9;
  transform-origin: 380px 96px;
  animation: orbitDrift 5.8s ease-in-out infinite;
}

.brand-orbits ellipse:nth-child(2) {
  stroke: rgba(255, 225, 78, 0.62);
  stroke-dasharray: 18 22;
  animation: orbitDash 4.2s linear infinite;
}

.brand-orbits path {
  stroke: rgba(255, 78, 206, 0.68);
  stroke-dasharray: 28 18;
  animation: orbitDash 3.2s linear infinite reverse;
}

.brand-sparks {
  fill: #fff7a8;
  filter: url(#brandGlow);
  animation: sparkBlink 1.7s steps(2, end) infinite;
}

@keyframes brandFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-5px); }
}

@keyframes brandNeon {
  0%, 100% { opacity: 0.96; }
  13% { opacity: 1; }
  17% { opacity: 0.72; }
  20% { opacity: 1; }
  64% { opacity: 0.9; }
}

@keyframes brandTrace {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -294; }
}

@keyframes brandSubPulse {
  0%, 100% { opacity: 0.74; }
  50% { opacity: 1; }
}

@keyframes orbitDrift {
  0%, 100% { transform: rotate(-2deg) scaleX(1); }
  50% { transform: rotate(2deg) scaleX(1.04); }
}

@keyframes orbitDash {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -120; }
}

@keyframes sparkBlink {
  0%, 100% { opacity: 0.38; }
  50% { opacity: 1; }
}

@keyframes stoneLiftA {
  0%, 100% { transform: translate(158px, 106px) rotate(-7deg) scale(1.04, 0.98); }
  50% { transform: translate(158px, 102px) rotate(-9deg) scale(1.07, 0.99); }
}

@keyframes stoneLiftB {
  0%, 100% { transform: translate(310px, 98px) rotate(3deg) scale(1, 1.02); }
  50% { transform: translate(310px, 101px) rotate(4deg) scale(1.03, 1); }
}

@keyframes stoneLiftC {
  0%, 100% { transform: translate(470px, 106px) rotate(-4deg) scale(1.08, 0.99); }
  50% { transform: translate(470px, 102px) rotate(-2deg) scale(1.1, 1.01); }
}

@keyframes stoneLiftD {
  0%, 100% { transform: translate(620px, 100px) rotate(5deg) scale(0.98, 1.02); }
  50% { transform: translate(620px, 103px) rotate(7deg) scale(1, 1); }
}

@keyframes crackFlash {
  0%, 100% { opacity: 0.78; }
  50% { opacity: 0.96; }
}

@keyframes chipJitter {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

.client-dialog {
  position: absolute;
  z-index: 20;
  color: #fbe8bd;
  border: 2px solid rgba(96, 57, 18, 0.94);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(91, 55, 22, 0.94), rgba(38, 24, 12, 0.94));
  box-shadow: inset 0 0 0 2px rgba(249, 211, 128, 0.24), 0 18px 34px rgba(0, 0, 0, 0.44);
}

.login-dialog {
  right: 8%;
  bottom: 10%;
  width: min(300px, 38%);
  padding: 18px 18px 16px;
  display: grid;
  gap: 11px;
}

.hidden,
.login-dialog.hidden,
.character-dialog.hidden,
.battle-panel.hidden,
.npc-window.hidden,
.chat-bar.hidden,
.client-actionbar.hidden,
.control-pad.hidden { display: none !important; }

.login-dialog label {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  text-shadow: 0 1px 0 #000;
}

.login-dialog select,
.login-dialog input,
.chat-bar input {
  min-width: 0;
  border: 1px solid #5f3917;
  border-radius: 8px;
  outline: none;
  background: rgba(255, 237, 194, 0.92);
  color: #2f1d10;
  font: 15px "Microsoft YaHei", system-ui, sans-serif;
  padding: 8px 10px;
  box-shadow: inset 0 2px 6px rgba(78, 47, 17, 0.24);
}

.login-dialog select { width: 100%; }
.login-dialog button,
.character-dialog button,
.chat-bar button,
.client-actionbar button,
.control-pad button,
.battle-panel button,
.npc-window button {
  border: 1px solid #6b451b;
  border-radius: 10px;
  color: #fff4d5;
  background: linear-gradient(#bb7b2c, #714211);
  box-shadow: inset 0 1px 0 rgba(255, 238, 174, 0.42), 0 3px 0 #3c220c, 0 8px 16px rgba(0, 0, 0, 0.28);
  font-weight: 700;
  cursor: pointer;
}
.login-dialog button { padding: 10px 12px; font-size: 16px; }
button:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255, 238, 174, 0.25), 0 1px 0 #3c220c; }

.client-status {
  min-height: 20px;
  color: #ffe8a3;
  font-size: 13px;
  text-align: center;
  text-shadow: 0 1px 0 #000;
}
.client-status.active { color: #b9ff91; }

.character-dialog {
  left: 50%;
  top: 50%;
  width: min(450px, 62%);
  transform: translate(-50%, -50%);
  padding: 20px;
}
.character-dialog h2 { margin: 0 0 14px; text-align: center; letter-spacing: 4px; }
.character-list { display: grid; gap: 10px; max-height: 265px; overflow: auto; }
.character-list.empty { min-height: 52px; display: grid; place-items: center; color: #f1ce8d; }
.character-card { min-height: 54px; padding: 12px; font-size: 18px; text-align: left; }
.character-dialog > button { width: 100%; margin-top: 12px; padding: 9px; }

.chat-bar {
  position: absolute;
  z-index: 12;
  left: 2.6%;
  right: 2.6%;
  bottom: 2.3%;
  height: 36px;
  display: grid;
  grid-template-columns: 1fr 76px;
  gap: 8px;
}
.chat-bar input { background: rgba(255, 244, 215, 0.86); }
.chat-bar button { font-size: 14px; }

.client-actionbar {
  position: absolute;
  z-index: 12;
  left: 2.6%;
  bottom: calc(2.3% + 44px);
  display: flex;
  gap: 7px;
}
.client-actionbar button { height: 34px; padding: 0 12px; font-size: 13px; }

.control-pad {
  position: absolute;
  z-index: 12;
  right: 2.6%;
  bottom: calc(2.3% + 44px);
  display: grid;
  grid-template-columns: repeat(3, 36px);
  grid-template-rows: repeat(3, 32px);
  gap: 5px;
  opacity: 0.76;
}
.control-pad button { padding: 0; font-size: 17px; }

.battle-panel,
.npc-window {
  position: absolute;
  z-index: 22;
  left: 50%;
  bottom: 11%;
  transform: translateX(-50%);
  width: min(620px, 72%);
  padding: 14px;
  border: 2px solid rgba(96, 57, 18, 0.94);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: inset 0 0 0 2px rgba(249, 211, 128, 0.18), 0 16px 26px rgba(0, 0, 0, 0.38);
}
.battle-status { margin-bottom: 10px; font-weight: 700; color: #ffe09c; }
.battle-targets { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 7px; margin-bottom: 10px; }
.battle-target, .battle-empty { min-height: 38px; padding: 8px; }
.battle-target.enemy { background: linear-gradient(#b9452f, #6f2116); }
.battle-target.ally { background: linear-gradient(#4c9664, #285537); }
.battle-actions, .window-actions { display: flex; gap: 8px; justify-content: flex-end; }
.battle-actions button, .window-actions button { padding: 8px 14px; }
.npc-window-text { white-space: pre-wrap; line-height: 1.55; max-height: 170px; overflow: auto; margin-bottom: 12px; }

.debug-sink {
  display: none;
  pointer-events: none;
}

@media (max-width: 760px) {
  .login-dialog { width: 76%; right: 12%; bottom: 8%; }
  .auth-brand { width: min(82%, 560px); top: 1.5vh; }
  .game-window.auth-register .auth-brand { width: min(70%, 500px); top: 0.4vh; }
  .brand-main,
  .brand-back,
  .brand-edge { font-size: 88px; }
  .brand-sub { font-size: 15px; letter-spacing: 6px; }
  .character-dialog { width: 82%; }
  .client-actionbar { bottom: calc(2.3% + 40px); }
  .control-pad { grid-template-columns: repeat(3, 32px); grid-template-rows: repeat(3, 30px); }
}

/* Native-client mode: all visible UI is drawn on the game canvas. */
.login-dialog.canvas-driven {
  z-index: 30;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  display: block;
  opacity: 1;
  pointer-events: none;
}
.login-dialog.canvas-driven select,
.login-dialog.canvas-driven label span,
.login-dialog.canvas-driven button,
.login-dialog.canvas-driven .client-status {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.login-dialog.canvas-driven label {
  position: absolute;
  display: block;
  margin: 0;
  padding: 0;
}
.login-dialog.canvas-driven input {
  position: absolute;
  left: -1000px;
  top: -1000px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: auto;
}
.login-dialog.canvas-driven input:focus {
  left: 0;
  top: 0;
}

/* Player-facing native parity shell. Normal mode must not expose web chrome. */
body.native-mode .client-dialog:not(.login-dialog),
body.native-mode .battle-panel,
body.native-mode .npc-window,
body.native-mode .client-actionbar,
body.native-mode .control-pad {
  display: none !important;
}


body.native-mode .chat-bar {
  z-index: 30;
  left: 0;
  right: auto;
  bottom: auto;
  top: 0;
  width: 1px;
  height: 1px;
  display: block;
  opacity: 0;
  pointer-events: none;
  overflow: visible;
}

body.native-mode .chat-bar input {
  position: absolute;
  left: -1000px;
  top: -1000px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: auto;
}

body.native-mode .chat-bar input:focus {
  left: 0;
  top: 0;
}

body.native-mode .chat-bar button {
  display: none !important;
}

body.native-mode .debug-sink {
  display: none !important;
}

body.debug-mode[data-phase="battle"] .battle-panel,
body.debug-mode[data-phase="battle"] .debug-sink {
  display: none !important;
}

body.debug-mode .debug-sink {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 1000;
  max-width: min(560px, calc(100vw - 16px));
  max-height: 35vh;
  overflow: auto;
  display: block;
  padding: 8px;
  border: 1px solid rgba(245, 212, 135, 0.4);
  border-radius: 8px;
  background: rgba(5, 4, 3, 0.72);
  color: #fff0cf;
  font-size: 12px;
  pointer-events: none;
}

body.debug-mode .debug-sink button {
  margin: 2px;
  padding: 4px 8px;
  pointer-events: auto;
}


.login-dialog.create-only {
  left: 0;
  top: 0;
  right: auto;
  bottom: auto;
  width: 0;
  height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  display: block;
  pointer-events: none;
}

.login-dialog.create-only select,
.login-dialog.create-only label:has(#accountInput),
.login-dialog.create-only label:has(#passwordInput),
.login-dialog.create-only label:has(#registerAccountInput),
.login-dialog.create-only label:has(#registerPasswordInput),
.login-dialog.create-only label:has(#registerConfirmInput),
.login-dialog.create-only #sendLogin,
.login-dialog.create-only #connectionBadge {
  display: none !important;
}

.login-dialog.create-only label:has(#createNameInput) {
  position: absolute;
  left: calc((100vw - var(--game-w)) / 2 + var(--game-w) * 0.696);
  top: calc((100vh - var(--game-h)) / 2 + var(--game-h) * 0.213);
  width: min(210px, 24vw);
  display: block;
  pointer-events: auto;
}

.login-dialog.create-only label:has(#createNameInput) span {
  display: none;
}

.login-dialog.create-only #createNameInput {
  width: 100%;
  height: 34px;
  border: 0;
  border-radius: 7px;
  background: rgba(255, 244, 214, 0.1);
  color: #fff7dc;
  box-shadow: none;
  font: 19px Consolas, "Microsoft YaHei", sans-serif;
  padding: 5px 10px;
}

.login-dialog:not(.create-only) label:has(#createNameInput) {
  display: none;
}
