:root {
  color-scheme: dark;
  --bg: #14120f;
  --panel: rgba(25, 23, 19, 0.82);
  --panel-strong: rgba(22, 20, 17, 0.95);
  --line: rgba(244, 232, 198, 0.16);
  --text: #f4ead2;
  --muted: #b8ad95;
  --jade: #53b69c;
  --gold: #d8a13a;
  --silver: #c9d0d8;
  --wood: #a36a36;
  --red: #e36353;
  --shadow: rgba(0, 0, 0, 0.42);
  font-family:
    "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Inter, system-ui,
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 520px;
  overflow: hidden;
  background:
    linear-gradient(rgba(244, 232, 198, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(244, 232, 198, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 18% 18%, rgba(83, 182, 156, 0.18), transparent 28%),
    radial-gradient(circle at 82% 76%, rgba(216, 161, 58, 0.15), transparent 32%),
    #14120f;
  background-size: 46px 46px, 46px 46px, auto, auto, auto;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.hud,
.tier-strip,
.actions,
.message-bar {
  position: absolute;
  z-index: 5;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.hud {
  top: 16px;
  left: 16px;
  display: grid;
  grid-template-columns: repeat(5, minmax(76px, 1fr));
  gap: 8px;
  width: min(640px, calc(100vw - 32px));
}

.stat {
  min-height: 58px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 34px var(--shadow);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.1;
}

.stat strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 23px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.tier-strip {
  left: 16px;
  bottom: 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}

.tier {
  min-height: 52px;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 34px var(--shadow);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.tier i {
  width: 20px;
  height: 16px;
  border-radius: 4px;
  box-shadow:
    inset 0 2px rgba(255, 255, 255, 0.22),
    inset 0 -4px rgba(0, 0, 0, 0.25);
}

.tier strong {
  color: var(--text);
  font-size: 13px;
}

.tier-wood i {
  background: var(--wood);
}

.tier-silver i {
  background: var(--silver);
}

.tier-gold i {
  background: var(--gold);
}

.actions {
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
}

.action-button,
.icon-button,
.primary-button,
.touch-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 34px var(--shadow);
  font-weight: 900;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.action-button:hover,
.icon-button:hover,
.primary-button:hover,
.touch-button:hover {
  transform: translateY(-1px);
  border-color: rgba(244, 232, 198, 0.34);
}

.action-button:active,
.icon-button:active,
.primary-button:active,
.touch-button:active {
  transform: translateY(1px) scale(0.99);
}

.action-primary {
  min-width: 92px;
  padding: 0 18px;
  background: rgba(83, 182, 156, 0.88);
  color: #0f1714;
}

.icon-button {
  width: 48px;
  color: var(--text);
  letter-spacing: 0;
}

.message-bar {
  right: 16px;
  bottom: 16px;
  width: min(520px, calc(100vw - 424px));
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 34px var(--shadow);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.message-bar span {
  display: block;
  width: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(20, 18, 15, 0.24), rgba(20, 18, 15, 0.78)),
    rgba(20, 18, 15, 0.32);
}

.overlay.is-hidden {
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transition:
    opacity 180ms ease,
    visibility 180ms ease;
}

.overlay-panel {
  width: min(540px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 34px 90px rgba(0, 0, 0, 0.58);
}

.overlay-panel p:first-child {
  margin: 0 0 10px;
  color: var(--jade);
  font-size: 13px;
  font-weight: 900;
}

.overlay h1 {
  margin: 0;
  color: #fff5dc;
  font-size: clamp(42px, 8vw, 86px);
  line-height: 0.95;
  letter-spacing: 0;
}

.overlay-panel p:not(:first-child) {
  max-width: 34rem;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.65;
}

.primary-button {
  width: min(260px, 100%);
  min-height: 52px;
  margin-top: 20px;
  background: var(--gold);
  color: #1c1409;
}

.touch-controls {
  position: absolute;
  right: 16px;
  bottom: 84px;
  z-index: 6;
  display: none;
  align-items: end;
  gap: 14px;
}

.stick-base {
  position: relative;
  width: 116px;
  height: 116px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(25, 23, 19, 0.52);
  box-shadow: 0 16px 38px var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  touch-action: none;
}

.stick-base span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(244, 232, 198, 0.28);
  border-radius: 50%;
  background: rgba(83, 182, 156, 0.78);
  transform: translate(-50%, -50%);
}

.touch-button {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: rgba(216, 161, 58, 0.9);
  color: #1c1409;
  font-size: 20px;
}

@media (pointer: coarse), (max-width: 840px) {
  .touch-controls {
    display: flex;
  }
}

@media (max-width: 980px) {
  .message-bar {
    left: 16px;
    right: auto;
    bottom: 76px;
    width: min(520px, calc(100vw - 32px));
  }
}

@media (max-width: 720px) {
  .hud {
    top: 10px;
    left: 10px;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    width: calc(100vw - 20px);
    gap: 5px;
  }

  .stat {
    min-height: 50px;
    padding: 7px 6px;
  }

  .stat span {
    font-size: 11px;
  }

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

  .actions {
    top: auto;
    right: 10px;
    bottom: 212px;
    flex-direction: column;
  }

  .action-primary,
  .icon-button {
    width: 52px;
    min-width: 52px;
    padding: 0;
    font-size: 13px;
  }

  .tier-strip {
    left: 10px;
    bottom: 10px;
    grid-template-columns: 1fr;
    width: 112px;
  }

  .tier {
    min-height: 42px;
    grid-template-columns: 20px 1fr;
    gap: 6px;
    padding: 6px 8px;
  }

  .tier strong {
    display: none;
  }

  .message-bar {
    left: 10px;
    bottom: 146px;
    width: calc(100vw - 86px);
    min-height: 48px;
    padding: 8px 10px;
    font-size: 13px;
  }

  .touch-controls {
    right: 10px;
    bottom: 10px;
    gap: 10px;
  }

  .stick-base {
    width: 104px;
    height: 104px;
  }

  .touch-button {
    width: 68px;
    height: 68px;
  }

  .overlay {
    padding: 16px;
  }

  .overlay-panel {
    padding: 22px;
  }
}
