:root {
  color-scheme: dark;
  --bg: #080b0f;
  --surface: rgba(21, 26, 32, 0.92);
  --surface-2: rgba(31, 38, 47, 0.96);
  --line: rgba(138, 157, 178, 0.22);
  --text: #f6f7f9;
  --muted: #b9c4d2;
  --accent: #42e7a6;
  --cyan: #47c7ff;
  --danger: #fb7185;
  --warn: #facc15;
  --shadow: rgba(0, 0, 0, 0.38);
  --glow: rgba(71, 199, 255, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(8, 11, 15, 0.9), rgba(14, 20, 25, 0.86)),
    radial-gradient(circle at 22% 16%, rgba(176, 211, 128, 0.18), transparent 34%),
    radial-gradient(circle at 82% 10%, rgba(112, 88, 56, 0.14), transparent 30%),
    linear-gradient(135deg, #0b1110 0%, #172016 44%, #090c0a 100%);
  color: var(--text);
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: linear-gradient(180deg, #64f3bc, var(--accent));
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.42);
  color: #07110b;
  font-weight: 800;
  padding: 0 14px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

button:hover {
  filter: brightness(1.08);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.28), 0 0 0 3px rgba(66, 231, 166, 0.12);
}

button:active {
  transform: translateY(1px);
}

button.ghost,
.filters button {
  background: linear-gradient(180deg, rgba(43, 52, 64, 0.96), rgba(25, 31, 39, 0.96));
  border-color: var(--line);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

button.active,
.filters button.active {
  background: linear-gradient(180deg, #7ddcff, var(--cyan));
  border-color: var(--cyan);
  color: #061019;
}

input,
select {
  min-height: 38px;
  width: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 9, 13, 0.86);
  box-shadow: inset 0 1px 8px rgba(0, 0, 0, 0.3);
  color: var(--text);
  outline: none;
  padding: 0 12px;
}

input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(71, 199, 255, 0.15), inset 0 1px 8px rgba(0, 0, 0, 0.3);
}

select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(71, 199, 255, 0.15), inset 0 1px 8px rgba(0, 0, 0, 0.3);
}

form input {
  width: 100%;
  min-width: 0;
}

.hidden {
  display: none !important;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  min-height: 0;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(25, 32, 40, 0.96), rgba(12, 16, 22, 0.94)),
    rgba(12, 16, 22, 0.92);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  padding: 10px 14px;
}

.brand {
  font-size: 20px;
  font-weight: 900;
  text-shadow: 0 0 18px rgba(71, 199, 255, 0.22);
  white-space: nowrap;
}

.join {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.join select {
  width: 92px;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--warn);
  box-shadow: 0 0 12px currentColor;
}

.dot.ready {
  background: var(--accent);
}

.dot.closed {
  background: var(--danger);
}

.lobby {
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding: 2px;
}

.gameGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(198px, 1fr));
  gap: 12px;
}

.lobbyLayout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 12px;
  align-items: start;
}

.gameCard {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 118px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(244, 231, 194, 0.08), transparent 36%),
    linear-gradient(180deg, rgba(35, 43, 39, 0.96), rgba(17, 24, 22, 0.94));
  box-shadow: 0 14px 28px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  padding: 12px;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.gameCard:hover {
  border-color: var(--cyan);
  background:
    linear-gradient(145deg, rgba(178, 222, 137, 0.13), transparent 34%),
    linear-gradient(180deg, rgba(41, 52, 45, 0.98), rgba(19, 28, 24, 0.96));
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.42), 0 0 0 3px rgba(144, 190, 109, 0.13);
  transform: translateY(-2px);
}

.gameName {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 16px;
  font-weight: 900;
}

.badge {
  flex: 0 0 auto;
  border-radius: 6px;
  border: 1px solid rgba(71, 199, 255, 0.25);
  background: rgba(10, 23, 34, 0.9);
  color: var(--cyan);
  font-size: 12px;
  padding: 3px 6px;
}

.desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  flex: 1 1 auto;
}

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

.cardActions button {
  min-height: 34px;
  padding: 0 10px;
}

.likeBtn {
  background: linear-gradient(180deg, rgba(55, 48, 25, 0.96), rgba(34, 29, 18, 0.96));
  border-color: var(--line);
  color: var(--warn);
}

.likeBtn.liked {
  background: rgba(250, 204, 21, 0.16);
  border-color: rgba(250, 204, 21, 0.45);
}

.likePanel {
  position: sticky;
  top: 0;
}

.lobbySide {
  position: sticky;
  top: 0;
  display: grid;
  gap: 12px;
}

.likeBoard {
  padding: 9px;
}

.likeRow {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 32px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 13px;
}

.likeRow:last-child {
  border-bottom: none;
}

.gameView {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 282px;
  gap: 12px;
  min-height: 0;
  padding: 14px;
}

.arena {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(121, 145, 172, 0.32);
  border-radius: 8px;
  background:
    linear-gradient(115deg, rgba(205, 224, 147, 0.18) 0 18%, rgba(69, 118, 57, 0.2) 18% 36%, transparent 36% 100%),
    radial-gradient(circle at 50% 38%, rgba(178, 222, 137, 0.22), transparent 52%),
    linear-gradient(135deg, #5f8b46, #315c2d 58%, #173719);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.48), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  overflow: hidden;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  filter: brightness(1.45) saturate(1.18) contrast(1.05);
}

.notice {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(10, 14, 20, 0.88);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  color: var(--text);
  padding: 8px 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  text-align: center;
}

.notice.show {
  opacity: 1;
}

.giftWorldOverlay {
  position: absolute;
  inset: 12px;
  z-index: 3;
  display: grid;
  gap: 12px;
  color: var(--text);
}

.giftWorldOverlay.hidden {
  display: none;
}

.giftStart {
  place-items: center;
  pointer-events: none;
}

.giftBoxButton {
  position: relative;
  width: min(360px, 82vw);
  min-height: 230px;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 28px;
  pointer-events: auto;
  border-color: rgba(250, 204, 21, 0.72);
  background:
    linear-gradient(90deg, transparent 0 43%, rgba(255, 255, 255, 0.24) 43% 57%, transparent 57% 100%),
    linear-gradient(180deg, #f97316, #be123c);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 34px rgba(250, 204, 21, 0.42);
  color: #fff7ed;
  text-align: center;
}

.giftRibbon {
  width: 92px;
  height: 42px;
  border: 8px solid #fde68a;
  border-radius: 50%;
  box-shadow: 0 0 0 999px transparent;
}

.giftTitle {
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 900;
}

.giftText {
  color: #ffedd5;
  font-weight: 800;
}

.giftChoose {
  grid-template-rows: minmax(0, 1fr) auto;
  pointer-events: none;
}

.giftPanel,
.worldChoices,
.giftHudBox {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(8, 13, 18, 0.96);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.38);
}

.giftPanel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 12px;
}

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

.giftHeader strong {
  font-size: 18px;
}

.giftHeader span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.weaponChoices {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  padding-right: 2px;
}

.weaponChip {
  min-height: 58px;
  padding: 8px 10px;
  display: grid;
  justify-items: start;
  align-content: center;
  gap: 2px;
  background: linear-gradient(180deg, rgba(31, 41, 55, 0.96), rgba(12, 18, 26, 0.96));
  color: var(--text);
  text-align: left;
}

.weaponChip.active {
  border-color: #facc15;
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.18), 0 0 22px rgba(250, 204, 21, 0.22);
}

.weaponChip span {
  font-weight: 900;
}

.weaponChip small {
  color: var(--muted);
  font-weight: 700;
}

.worldChoices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
}

.worldCard {
  min-height: 86px;
  color: #fff;
  font-size: clamp(18px, 3vw, 26px);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

.worldCard.battle {
  background: linear-gradient(135deg, #991b1b, #fb7185);
}

.worldCard.peace {
  background: linear-gradient(135deg, #166534, #34d399);
}

.worldCard.tech {
  background: linear-gradient(135deg, #075985, #38bdf8);
}

.giftHud {
  align-items: start;
  justify-items: start;
  pointer-events: none;
}

.giftHudBox {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
}

.giftHudBox span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.side {
  display: grid;
  grid-template-rows: auto minmax(150px, auto) minmax(110px, 1fr) auto auto;
  gap: 12px;
  min-height: 0;
}

.panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(31, 38, 47, 0.94), rgba(17, 22, 29, 0.92));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.panelTitle {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(42, 51, 62, 0.96), rgba(25, 31, 39, 0.96));
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  padding: 8px 10px;
}

.info,
.list,
.events,
.links {
  padding: 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.48;
}

.row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.row:last-child {
  border-bottom: none;
}

.rank {
  color: var(--muted);
  text-align: center;
}

.nameCell {
  display: flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
}

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  box-shadow: 0 0 10px currentColor;
  flex: 0 0 auto;
}

.nameText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score {
  font-weight: 900;
}

.event {
  padding: 4px 0;
}

.links {
  word-break: break-all;
}

.botPanel {
  display: grid;
  grid-template-rows: auto minmax(120px, 1fr) auto;
}

.botMessages {
  min-height: 0;
  max-height: 260px;
  overflow: auto;
  padding: 9px;
}

.gameBotPanel .botMessages {
  max-height: 170px;
}

.botBubble {
  margin-bottom: 8px;
  border-radius: 8px;
  padding: 8px 9px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.42;
}

.botBubble.user {
  margin-left: 22px;
  background: linear-gradient(180deg, rgba(24, 77, 56, 0.96), rgba(15, 48, 36, 0.96));
}

.botBubble.bot {
  margin-right: 22px;
  background: linear-gradient(180deg, rgba(28, 43, 60, 0.96), rgba(19, 30, 43, 0.96));
}

.botMeta {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.botForm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px 56px;
  gap: 7px;
  border-top: 1px solid var(--line);
  padding: 8px;
}

.gameBotPanel .botForm {
  grid-template-columns: minmax(0, 1fr) 56px 56px;
}

.botForm button {
  min-height: 36px;
  padding: 0 8px;
  font-size: 13px;
}

.mobilePad {
  display: none;
  grid-template-columns: repeat(3, 54px) 76px;
  grid-template-areas:
    ". up . action"
    "left . right super"
    ". down . super";
  justify-content: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(22, 29, 38, 0.96), rgba(12, 16, 22, 0.96));
  padding: 8px 12px 12px;
}

.mobilePad button {
  width: 54px;
  height: 48px;
  padding: 0;
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text);
}

.mobilePad button:nth-child(1) {
  grid-area: up;
}

.mobilePad button:nth-child(2) {
  grid-area: left;
}

.mobilePad button:nth-child(3) {
  grid-area: right;
}

.mobilePad button:nth-child(4) {
  grid-area: down;
}

.actionPad {
  grid-area: action;
  width: 76px !important;
  height: auto !important;
  background: var(--accent) !important;
  color: #07110b !important;
}

.superPad {
  grid-area: super;
  width: 76px !important;
  height: auto !important;
  background: #38bdf8 !important;
  color: #06121c !important;
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100%;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .join,
  .status {
    justify-content: space-between;
  }

  .join input {
    flex: 1 1 auto;
    min-width: 0;
  }

  .gameView {
    grid-template-columns: 1fr;
    grid-template-rows: 62vh auto;
  }

  .giftWorldOverlay {
    inset: 8px;
  }

  .giftHeader {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .worldChoices {
    grid-template-columns: 1fr;
  }

  .worldCard {
    min-height: 58px;
  }

  .lobbyLayout {
    grid-template-columns: 1fr;
  }

  .lobbySide,
  .likePanel {
    position: static;
  }

  .side {
    grid-template-rows: auto;
  }

  .mobilePad:not(.hidden) {
    display: grid;
    position: sticky;
    bottom: 0;
    z-index: 5;
  }
}
