:root {
  --desktop: #008080;
  --panel: #c6c6c6;
  --panel-dark: #8d8d8d;
  --panel-light: #ffffff;
  --ink: #101010;
  --blue: #093b91;
  --blue-2: #1f5fbf;
  --danger: #ba1d1d;
  --success: #18743a;
  --gold: #c99718;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--desktop);
  font-family: "Microsoft JhengHei", "Noto Sans TC", "Segoe UI", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 34px;
  border: 2px solid;
  border-color: var(--panel-light) var(--panel-dark) var(--panel-dark) var(--panel-light);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

button:active,
button.active {
  border-color: var(--panel-dark) var(--panel-light) var(--panel-light) var(--panel-dark);
  background: #b7b7b7;
}

button:disabled {
  color: #666;
  cursor: not-allowed;
}

input {
  min-height: 36px;
  border: 2px solid;
  border-color: var(--panel-dark) var(--panel-light) var(--panel-light) var(--panel-dark);
  padding: 0 10px;
  background: #fff;
}

input[type="file"] {
  width: 100%;
  padding: 6px;
}

.is-hidden {
  display: none !important;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.07) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,0.07) 1px, transparent 1px),
    var(--desktop);
  background-size: 34px 34px;
}

.login-cursor-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.login-demo-cursor {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
  color: #ffffff;
  filter: drop-shadow(2px 2px 0 rgba(0,0,0,0.42));
  opacity: 0.72;
  transform: translate(0, 0);
  transition: transform 1100ms cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}

.login-demo-pointer {
  width: 0;
  height: 0;
  border-left: 14px solid #ffffff;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  transform: rotate(-28deg);
}

.login-demo-label {
  max-width: 120px;
  padding: 2px 6px;
  border: 1px solid rgba(255,255,255,0.8);
  background: rgba(11, 77, 143, 0.82);
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.25;
}

.login-window,
.side-card,
.hud,
.dialog-body {
  background: var(--panel);
  border: 2px solid;
  border-color: var(--panel-light) #555 #555 var(--panel-light);
  box-shadow: 4px 4px 0 var(--shadow);
}

.login-window {
  position: relative;
  z-index: 1;
  width: min(820px, 100%);
}

.window-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
  padding: 4px 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.login-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 16px;
  padding: 18px;
}

.login-body h1 {
  margin: 0 0 8px;
  font-size: 26px;
  line-height: 1.25;
}

.login-body p {
  margin: 0 0 16px;
  line-height: 1.65;
}

.login-form {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
}

.login-form button[type="submit"] {
  grid-column: 1 / -1;
}

.login-mode-tabs,
.account-action-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.account-action-tabs {
  grid-column: 1 / -1;
  margin-bottom: 2px;
}

.account-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
}

.field-status {
  grid-column: 2;
  min-height: 16px;
  margin-top: -4px;
  color: #5c5c5c;
  font-size: 12px;
  line-height: 1.2;
}

.account-fields .field-status {
  grid-column: 2;
}

.field-status.ok {
  color: #136c2e;
}

.field-status.error {
  color: #b00020;
}

.login-leaderboard {
  min-width: 0;
  border: 2px solid;
  border-color: var(--panel-light) #555 #555 var(--panel-light);
  background: #e8e8e8;
}

.login-leaderboard-list {
  display: grid;
  gap: 4px;
  max-height: 270px;
  margin: 0;
  padding: 8px 12px 10px;
  overflow: auto;
  list-style: none;
  line-height: 1.45;
}

.login-leaderboard-list li {
  display: grid;
  grid-template-columns: 28px 26px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-height: 26px;
  padding: 3px 0;
}

.login-leaderboard-list li.empty {
  grid-template-columns: 1fr;
}

.login-leaderboard-rank {
  color: #555;
  font-weight: 700;
}

.login-leaderboard-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-leaderboard-crowns {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  font-weight: 700;
}

.quick-start {
  margin: 18px 0 0;
  padding-left: 22px;
  line-height: 1.8;
}

.game-shell {
  position: fixed;
  inset: 0;
  background: #0f6f6f;
}

#worldCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#worldCanvas.dragging {
  cursor: grabbing;
}

.own-board-pointer {
  position: absolute;
  z-index: 7;
  left: var(--pointer-x, 50%);
  top: var(--pointer-y, 50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 6px 10px;
  transform: translate(-50%, -50%);
  background: rgba(255, 232, 92, 0.92);
  box-shadow: 3px 3px 0 var(--shadow);
  color: #111;
  font-weight: 700;
}

.own-board-pointer .arrow {
  display: inline-block;
  font-size: 20px;
  line-height: 1;
  transform: rotate(var(--pointer-angle, 0rad));
}

.own-board-pointer .distance {
  min-width: 48px;
  text-align: left;
  white-space: nowrap;
}

.start-prompt {
  position: absolute;
  z-index: 8;
  left: var(--prompt-x, 50%);
  top: var(--prompt-y, 50%);
  width: min(280px, calc(100vw - 24px));
  padding: 10px;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border: 2px solid;
  border-color: var(--panel-light) #555 #555 var(--panel-light);
  box-shadow: 4px 4px 0 var(--shadow);
}

.prompt-title {
  margin-bottom: 6px;
  font-weight: 700;
}

.prompt-slot {
  display: inline-block;
  margin-bottom: 8px;
  padding: 2px 7px;
  border: 1px inset #999;
  background: #f3f3f3;
  font-family: "Consolas", monospace;
}

.mode-segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.mode-segment button {
  min-height: 32px;
  padding: 4px 6px;
  font-size: 13px;
}

.prompt-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.victory-overlay {
  position: fixed;
  z-index: 11;
  left: 50%;
  top: 44%;
  display: grid;
  gap: 10px;
  justify-items: center;
  min-width: min(420px, calc(100vw - 36px));
  padding: 18px 24px;
  transform: translate(-50%, -50%) scale(0.98);
  color: #fff7bb;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 0 #6d4200, 0 0 18px rgba(255, 210, 64, 0.92);
  animation: victory-pop 2600ms ease forwards;
}

.victory-title {
  font-size: clamp(34px, 7vw, 72px);
  font-weight: 900;
  letter-spacing: 0;
}

.victory-crowns {
  padding: 8px 16px;
  border: 2px solid #fff2a8;
  background: rgba(105, 63, 0, 0.78);
  box-shadow: 0 0 24px rgba(255, 217, 80, 0.45);
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 800;
}

@keyframes victory-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.78);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.06);
  }
  70% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -54%) scale(0.96);
  }
}

.hud {
  position: absolute;
  z-index: 3;
  padding: 10px;
}

.hud-top {
  top: 12px;
  left: 12px;
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 280px;
}

.hud-button {
  min-height: 28px;
  padding: 2px 8px;
}

.hud-player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.hud-player-text {
  min-width: 0;
}

.hud-top strong,
.hud-top span {
  display: inline-block;
  margin-right: 8px;
}

.status-dot {
  padding: 3px 8px;
  border: 1px solid #555;
  background: #e7e7e7;
  font-size: 13px;
}

.status-dot.online {
  color: var(--success);
}

.board-panel {
  left: 12px;
  bottom: 78px;
  width: min(360px, calc(100vw - 24px));
}

.panel-title,
.side-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

#boardInfo {
  min-height: 74px;
  margin: 8px 0;
  line-height: 1.55;
}

.secondary-btn {
  width: 100%;
}

.side-panel {
  position: absolute;
  z-index: 4;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 330px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.side-card {
  min-height: 0;
  padding: 10px;
}

.side-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.profile-actions {
  display: inline-flex;
  gap: 6px;
}

.profile-actions button {
  min-height: 30px;
  padding: 2px 8px;
}

.mobile-top-actions {
  position: absolute;
  z-index: 5;
  top: 12px;
  right: 12px;
  display: none;
  gap: 6px;
}

.mobile-top-actions button {
  min-height: 30px;
  padding: 2px 8px;
}

.profile-summary {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  padding: 6px;
  border: 1px inset #999;
  background: #eee;
}

.avatar {
  display: inline-block;
  object-fit: cover;
  border: 2px solid;
  border-color: var(--panel-dark) var(--panel-light) var(--panel-light) var(--panel-dark);
  background: #dcdcdc;
}

.avatar-large {
  width: 44px;
  height: 44px;
}

.avatar-hud {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}

.avatar-small {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  vertical-align: middle;
}

.avatar-chat {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  vertical-align: middle;
}

.avatar-preview {
  width: 150px;
  height: 150px;
  object-fit: cover;
  border: 2px solid;
  border-color: var(--panel-dark) var(--panel-light) var(--panel-light) var(--panel-dark);
  background: #eee;
}

.crown-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
}

.crown-icon {
  color: #a46a00;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
}

.stat-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.stat-list div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px;
  border: 1px inset #999;
  background: #eee;
}

.stat-list dt,
.stat-list dd {
  margin: 0;
}

.chat-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-log {
  min-height: 0;
  overflow: auto;
  padding: 8px;
  border: 2px solid;
  border-color: var(--panel-dark) var(--panel-light) var(--panel-light) var(--panel-dark);
  background: #f7f7f7;
}

.chat-line {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 8px;
  line-height: 1.45;
  word-break: break-word;
}

.chat-line .chat-content {
  min-width: 0;
}

.chat-line .name {
  font-weight: 700;
  color: var(--blue);
}

.chat-line.system .name {
  color: var(--danger);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 8px;
  margin-top: 10px;
}

.chat-muted-notice {
  margin-top: 10px;
  padding: 9px 10px;
  border: 2px solid;
  border-color: var(--panel-dark) var(--panel-light) var(--panel-light) var(--panel-dark);
  background: #eee3c4;
  color: #7a1a12;
  font-weight: 700;
  text-align: center;
}

.mobile-toolbar {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 12px;
  display: none;
  transform: translateX(-50%);
}

.mobile-toolbar button {
  min-height: 34px;
  min-width: 92px;
  padding: 3px 12px;
}

.long-press-indicator {
  position: fixed;
  z-index: 8;
  width: 84px;
  height: 14px;
  padding: 3px;
  border: 2px solid;
  border-color: var(--panel-light) #555 #555 var(--panel-light);
  background: var(--panel);
  pointer-events: none;
}

.long-press-track {
  height: 100%;
  border: 1px inset #999;
  background: #e8e8e8;
  overflow: hidden;
}

.long-press-fill {
  width: 100%;
  height: 100%;
  background: var(--blue);
  transform: scaleX(0);
  transform-origin: left center;
}

.long-press-indicator.charging .long-press-fill {
  transform: scaleX(1);
  transition: transform 600ms linear;
}

.leaderboard-dialog {
  padding: 0;
  border: 0;
  background: transparent;
}

.profile-dialog {
  padding: 0;
  border: 0;
  background: transparent;
}

.dialog-body {
  width: min(420px, calc(100vw - 24px));
  padding: 0 0 12px;
}

.dialog-body .window-title button {
  min-height: 24px;
  width: 28px;
  padding: 0;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  margin: 12px;
  padding-left: 0;
  list-style-position: inside;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 26px 24px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 6px;
  border: 1px inset #999;
  background: #eee;
}

.profile-dialog-body {
  width: min(390px, calc(100vw - 24px));
}

.profile-settings {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 14px;
}

.avatar-cropper {
  display: grid;
  justify-items: center;
  gap: 8px;
  width: 100%;
}

.avatar-cropper canvas {
  display: block;
  width: min(280px, calc(100vw - 72px));
  height: min(280px, calc(100vw - 72px));
  border: 2px solid;
  border-color: var(--panel-dark) var(--panel-light) var(--panel-light) var(--panel-dark);
  background: #eee;
  cursor: grab;
  touch-action: none;
}

.avatar-cropper canvas.dragging {
  cursor: grabbing;
}

.crop-zoom {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  width: min(280px, 100%);
}

.crop-zoom input[type="range"] {
  min-height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
}

.crop-hint {
  max-width: 280px;
  margin: 0;
  color: #333;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.avatar-picker {
  display: grid;
  width: 100%;
  gap: 6px;
}

.profile-settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 20px;
  max-width: min(520px, calc(100vw - 24px));
  padding: 10px 14px;
  transform: translate(-50%, 120px);
  border: 2px solid;
  border-color: var(--panel-light) #555 #555 var(--panel-light);
  background: var(--panel);
  box-shadow: 3px 3px 0 var(--shadow);
  transition: transform 180ms ease;
}

.toast.show {
  transform: translate(-50%, 0);
}

.toast.center {
  top: 50%;
  bottom: auto;
  font-size: 18px;
  font-weight: 700;
  transform: translate(-50%, -50%) scale(0.96);
}

.toast.center.show {
  transform: translate(-50%, -50%) scale(1);
}

.mobile-only {
  display: none;
}

@media (max-width: 860px) {
  .side-panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 54px;
    width: auto;
    max-height: 48vh;
    grid-template-rows: 1fr;
    transform: translateY(calc(100% + 68px));
    transition: transform 180ms ease;
  }

  .side-panel.open {
    transform: translateY(0);
  }

  .profile-card {
    display: none;
  }

  .chat-card #chatToggle {
    display: none;
  }

  .mobile-only {
    display: inline-block;
  }

  .mobile-top-actions {
    display: flex;
  }

  .mobile-toolbar {
    display: block;
  }

  .hud-top {
    min-width: 0;
    max-width: calc(100vw - 148px);
    flex-wrap: wrap;
  }

  .board-panel {
    bottom: 72px;
    max-height: 34vh;
    overflow: auto;
  }

  .login-form {
    grid-template-columns: 1fr;
  }

  .login-body {
    grid-template-columns: 1fr;
  }

  .account-fields {
    grid-template-columns: 1fr;
  }

  .field-status,
  .account-fields .field-status {
    grid-column: 1;
  }
}
