:root {
  color-scheme: dark;
  --text: #edf2f7;
  --muted: #9aa7b7;
  --panel: rgba(11, 15, 19, 0.78);
  --line: rgba(255, 255, 255, 0.15);
  --blue: #55b9ff;
  --red: #ff5d57;
  --gold: #e1b95a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: #07090d;
  color: var(--text);
  font-family: Inter, "Microsoft YaHei", system-ui, sans-serif;
}

button {
  color: inherit;
  font: inherit;
}

a {
  color: inherit;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  background:
    radial-gradient(circle at 50% 42%, rgba(80, 135, 150, 0.18), transparent 38%),
    linear-gradient(180deg, #111820 0%, #080b0f 74%);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.start-screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: clamp(24px, 6vw, 82px);
  background:
    linear-gradient(90deg, rgba(4, 7, 11, 0.42) 0%, rgba(4, 7, 11, 0.72) 32%, rgba(4, 7, 11, 0.72) 68%, rgba(4, 7, 11, 0.42) 100%),
    url("./item/start_bg.png") center / cover no-repeat;
}

.start-content {
  display: grid;
  justify-items: center;
  gap: 28px;
  width: min(560px, 100%);
  text-align: center;
}

.start-title span,
.start-menu > span {
  color: var(--blue);
  font-size: 13px;
  letter-spacing: 0.08em;
}

.start-title {
  padding-bottom: 0;
}

.start-title h1 {
  margin-top: 12px;
  font-size: clamp(44px, 7vw, 86px);
  line-height: 0.96;
}

.start-title p {
  margin-top: 16px;
  color: #c5d0dc;
  font-size: 17px;
  line-height: 1.7;
}

.start-menu {
  width: min(360px, 100%);
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(24, 32, 40, 0.78), rgba(6, 9, 13, 0.78)),
    rgba(7, 10, 14, 0.68);
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(14px);
}

.start-actions {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  text-align: left;
}

.start-actions button,
.start-actions a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(10, 15, 20, 0.72);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.start-actions button::after,
.start-actions a::after {
  content: "›";
  color: var(--blue);
  font-size: 24px;
}

.start-actions button:hover,
.start-actions a:hover {
  border-color: rgba(85, 185, 255, 0.72);
  background: rgba(35, 74, 94, 0.5);
}

.codex-modal {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(8px);
}

.pause-menu {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.56);
  backdrop-filter: blur(7px);
}

.pause-panel {
  display: grid;
  gap: 12px;
  width: min(360px, 100%);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(10, 14, 18, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.pause-panel h2 {
  margin-bottom: 4px;
  font-size: 24px;
  text-align: center;
}

.pause-panel button {
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.pause-panel button:hover {
  background: rgba(85, 185, 255, 0.18);
}

.codex-panel {
  width: min(920px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(10, 14, 18, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.52);
}

.codex-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.codex-panel-head h2 {
  font-size: 24px;
}

.codex-panel-head button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

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

.codex-grid article {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.codex-grid img {
  display: block;
  width: 100%;
  height: 180px;
  border-radius: 7px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.22);
}

.codex-grid strong {
  display: block;
  margin-top: 10px;
  font-size: 15px;
}

.codex-grid p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.hud {
  position: absolute;
  z-index: 5;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
}

.topbar {
  top: 18px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1;
}

.topbar p,
.codex p,
.deck {
  color: var(--muted);
}

.topbar p {
  margin-top: 5px;
  font-size: 13px;
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: end;
}

.stats span {
  min-width: 108px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  font-size: 12px;
}

.tutorial-link {
  display: inline-flex;
  align-items: center;
  min-height: 47px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
}

.tutorial-link:hover {
  background: rgba(85, 185, 255, 0.16);
}

.stats strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 17px;
}

.codex {
  top: 104px;
  left: 18px;
  width: 292px;
  padding: 14px;
}

.codex h2 {
  margin-bottom: 10px;
  font-size: 16px;
}

.codex p {
  min-height: 64px;
  font-size: 13px;
  line-height: 1.55;
}

.draw-panel {
  margin: 14px 0;
  padding: 11px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.draw-row,
.building-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.draw-row {
  margin-bottom: 8px;
  font-size: 13px;
}

.draw-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.draw-meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--gold), #ff725a);
  box-shadow: 0 0 18px rgba(225, 185, 90, 0.8);
}

.building-list {
  display: grid;
  gap: 8px;
}

.building-list div {
  padding: 9px 10px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 13px;
}

.building-list b {
  color: var(--text);
}

.building-zone {
  top: 104px;
  right: 18px;
  width: min(438px, calc(100vw - 346px));
  padding: 12px;
}

.shovel-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 10px;
  padding: 9px 0;
  border: 1px dashed rgba(255, 120, 100, 0.32);
  border-radius: 8px;
  background: rgba(255, 80, 60, 0.06);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition:
    background 150ms ease,
    border-color 150ms ease,
    color 150ms ease;
}

.shovel-btn:hover {
  background: rgba(255, 80, 60, 0.12);
  border-color: rgba(255, 120, 100, 0.52);
  color: var(--text);
}

.shovel-btn.active {
  border-style: solid;
  border-color: #ff7864;
  background: rgba(255, 80, 60, 0.18);
  color: #ff9a8a;
  box-shadow: 0 0 16px rgba(255, 100, 80, 0.25);
}

.building-zone-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.building-zone h2 {
  font-size: 16px;
}

.building-zone-head span {
  color: var(--muted);
  font-size: 12px;
}

.building-hand {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  min-height: 112px;
}

.building-card {
  display: grid;
  grid-template-rows: 52px auto auto;
  min-width: 0;
  min-height: 112px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent), transparent 82%), transparent),
    rgba(255, 255, 255, 0.07);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition:
    transform 130ms ease,
    border-color 130ms ease,
    background 130ms ease;
}

.building-card:hover,
.building-card.selected {
  border-color: color-mix(in srgb, var(--accent), white 22%);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent), transparent 70%), transparent),
    rgba(255, 255, 255, 0.1);
  transform: translateY(-3px);
}

.building-card.selected {
  outline: 2px solid rgba(255, 255, 255, 0.82);
}

.building-card.new {
  animation: cardIn 360ms cubic-bezier(0.16, 1, 0.3, 1);
}

.building-icon {
  display: block;
  width: 52px;
  height: 52px;
  padding: 4px;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 38%);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.22);
  object-fit: contain;
}

.building-card strong,
.building-card em {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.building-card strong {
  font-size: 13px;
}

.building-card em {
  align-self: end;
  color: var(--accent);
  font-size: 12px;
  font-style: normal;
}

.hand-zone {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: 14px;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 14px;
  align-items: end;
  width: min(1050px, calc(100vw - 28px));
  padding: 14px 16px 8px;
  border: 1px solid var(--line);
  border-radius: 10px 10px 0 0;
  background:
    radial-gradient(ellipse at 50% 110%, rgba(85, 185, 255, 0.2), transparent 56%),
    rgba(8, 11, 15, 0.86);
  box-shadow: 0 -20px 54px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
}

.deck {
  display: grid;
  justify-items: center;
  gap: 9px;
  font-size: 12px;
}

.deck-card {
  width: 70px;
  height: 100px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 17%, rgba(255, 255, 255, 0.11) 17% 20%, transparent 20% 44%, rgba(255, 255, 255, 0.09) 44% 47%, transparent 47%),
    linear-gradient(155deg, #22303b, #11161d);
  box-shadow:
    4px 4px 0 rgba(255, 255, 255, 0.06),
    8px 8px 0 rgba(255, 255, 255, 0.04);
}

.hand {
  display: flex;
  min-width: 0;
  min-height: 214px;
  align-items: end;
  justify-content: center;
  overflow-x: auto;
  overflow-y: visible;
}

.card {
  position: relative;
  width: 150px;
  height: 201px;
  flex: 0 0 150px;
  margin-left: -12px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #0b0f13;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 130ms ease,
    box-shadow 130ms ease,
    opacity 130ms ease;
  user-select: none;
}

.card:first-child {
  margin-left: 0;
}

.card:hover,
.card.selected {
  z-index: 2;
  transform: translateY(-14px);
  box-shadow: 0 26px 42px rgba(0, 0, 0, 0.5);
}

.card.selected {
  outline: 2px solid rgba(255, 255, 255, 0.86);
}

.card.new {
  animation: cardIn 360ms cubic-bezier(0.16, 1, 0.3, 1);
}

.card-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.card-copy {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.log {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 270px;
  width: min(860px, calc(100vw - 36px));
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 11, 15, 0.74);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.3);
  color: #f4f7fa;
  font-size: 14px;
  text-align: center;
  transform: translateX(-50%);
  backdrop-filter: blur(12px);
}

.game-end {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(8px);
}

.game-end-panel {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(13, 17, 22, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.game-end-panel h2 {
  margin-bottom: 10px;
  font-size: 30px;
}

.game-end-panel p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.game-end-panel button {
  margin-top: 18px;
  padding: 10px 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(85, 185, 255, 0.18);
  cursor: pointer;
}

.game-end-panel button:hover {
  background: rgba(85, 185, 255, 0.28);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translate(80px, 34px) rotate(8deg) scale(0.72);
  }
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .codex {
    top: 162px;
    width: min(292px, calc(100vw - 36px));
  }

  .building-zone {
    top: 162px;
    right: 18px;
    left: auto;
    width: min(438px, calc(100vw - 346px));
  }

  .stats {
    justify-content: start;
  }

  .hand-zone {
    grid-template-columns: 1fr;
  }

  .deck {
    display: none;
  }

  .hand {
    justify-content: start;
  }

  .card {
    width: 130px;
    height: 174px;
    flex-basis: 130px;
  }

  .building-hand {
    min-height: 96px;
  }

  .building-card {
    min-height: 96px;
  }

  .codex-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

}

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

  .game-shell {
    min-height: 1100px;
    height: 1100px;
  }

  .topbar {
    right: 18px;
  }

  .stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }

  .stats span,
  .tutorial-link {
    justify-content: center;
    min-width: 0;
    width: 100%;
  }

  .codex {
    top: 252px;
    right: 18px;
    width: auto;
  }

  .building-zone {
    top: 598px;
    right: 18px;
    left: 18px;
    width: auto;
  }

  .log {
    bottom: 253px;
  }

  .hand-zone {
    bottom: 14px;
  }

  .start-screen {
    position: fixed;
    min-height: 100dvh;
    overflow-y: auto;
    place-items: center;
    padding: 24px 18px;
    background:
      linear-gradient(180deg, rgba(4, 7, 11, 0.08) 0%, rgba(4, 7, 11, 0.72) 46%, rgba(4, 7, 11, 0.96) 100%),
      url("./item/start_bg.png") center / cover no-repeat;
  }

  .start-content {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .start-title h1 {
    font-size: clamp(40px, 13vw, 58px);
  }

  .start-title p {
    font-size: 15px;
  }

  .start-actions {
    width: 100%;
  }

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

  .codex-grid img {
    height: 150px;
  }
}
