:root {
  color-scheme: light;
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Noto Sans CJK SC",
    system-ui,
    sans-serif;
  background: #f8efd2;
  color: #273335;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    linear-gradient(180deg, rgba(116, 198, 224, 0.45), transparent 42%),
    radial-gradient(circle at 18% 24%, rgba(255, 212, 83, 0.35), transparent 22%),
    linear-gradient(135deg, #fbf1d6 0%, #cbe7c7 54%, #b6e3ee 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1120px, 100vw);
  height: 100vh;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.top-bar {
  min-height: 64px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255, 253, 243, 0.78);
  border: 2px solid rgba(89, 131, 96, 0.24);
  border-radius: 8px;
  box-shadow: 0 14px 30px rgba(71, 95, 78, 0.16);
  backdrop-filter: blur(16px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #e6b6b8;
  color: #e06a7b;
  font-size: 20px;
  line-height: 1;
  box-shadow: inset 0 -4px 0 rgba(224, 106, 123, 0.13);
}

.brand-title {
  font-size: clamp(18px, 2.1vw, 28px);
  white-space: nowrap;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.level-badge,
.controller-pill {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 999px;
  border: 2px solid rgba(39, 51, 53, 0.1);
  background: #fffdf4;
  color: #3b5659;
  font-weight: 800;
  white-space: nowrap;
}

.level-badge {
  cursor: default;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.level-badge.cheat-mode {
  background: #e9f7ff;
  color: #245465;
  border-color: rgba(75, 167, 212, 0.32);
}

.monster-toggle {
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 8px;
  border-radius: 999px;
  border: 2px solid rgba(39, 51, 53, 0.1);
  background: #fffdf4;
  color: #3b5659;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.monster-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.monster-toggle-track {
  width: 46px;
  height: 26px;
  position: relative;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #cddde0;
  box-shadow: inset 0 2px 5px rgba(39, 51, 53, 0.16);
  transition:
    background 170ms ease,
    box-shadow 170ms ease;
}

.monster-toggle-thumb {
  width: 20px;
  height: 20px;
  position: absolute;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow:
    inset 0 -3px 0 rgba(40, 72, 76, 0.1),
    0 3px 7px rgba(39, 51, 53, 0.18);
  transition: transform 170ms ease;
}

.monster-toggle input:checked + .monster-toggle-track {
  background: #b493e7;
  box-shadow: inset 0 2px 5px rgba(70, 49, 108, 0.24);
}

.monster-toggle input:checked + .monster-toggle-track .monster-toggle-thumb {
  transform: translateX(20px);
}

.monster-toggle:focus-within {
  outline: 3px solid rgba(82, 154, 218, 0.3);
  outline-offset: 2px;
}

.treasure-row {
  min-width: 120px;
  height: 42px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  background: #fff8d7;
  border: 2px solid rgba(224, 156, 47, 0.22);
}

.treasure-row.compact-progress {
  min-width: 68px;
}

.treasure-count {
  color: #734c0e;
  font-weight: 900;
  white-space: nowrap;
}

.star-chip {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: #f4d05d;
  color: #734c0e;
  font-size: 18px;
  line-height: 1;
  box-shadow: inset 0 -3px 0 rgba(112, 76, 14, 0.14);
  transform: scale(1);
  transition:
    transform 160ms ease,
    filter 160ms ease,
    opacity 160ms ease;
}

.star-chip.empty {
  filter: grayscale(0.8);
  opacity: 0.38;
  transform: scale(0.86);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  color: #28484c;
  font-size: 20px;
  font-weight: 900;
  box-shadow:
    inset 0 -4px 0 rgba(40, 72, 76, 0.1),
    0 5px 14px rgba(56, 86, 74, 0.14);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible,
.secondary-button:hover,
.secondary-button:focus-visible {
  outline: 3px solid rgba(82, 154, 218, 0.3);
  outline-offset: 2px;
}

.icon-button:active,
.primary-button:active,
.secondary-button:active {
  transform: translateY(2px);
}

.game-frame {
  position: relative;
  min-height: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #fff7df;
  border: 2px solid rgba(89, 131, 96, 0.22);
  box-shadow:
    0 20px 45px rgba(64, 92, 78, 0.18),
    inset 0 0 0 8px rgba(255, 255, 255, 0.35);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-controls {
  display: none;
  position: absolute;
  left: 50%;
  right: auto;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-controls *,
.touch-button span {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  grid-template-rows: repeat(2, 72px);
  gap: 8px;
  pointer-events: auto;
}

.touch-button {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 253, 244, 0.9);
  color: #244d5a;
  font-size: 38px;
  font-weight: 900;
  line-height: 1;
  box-shadow:
    inset 0 -7px 0 rgba(40, 72, 76, 0.12),
    0 10px 22px rgba(38, 63, 66, 0.2);
  backdrop-filter: blur(12px);
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-button:active,
.touch-button.is-pressed {
  transform: translateY(3px) scale(0.97);
  background: rgba(255, 205, 79, 0.94);
}

.touch-up {
  grid-column: 2;
  grid-row: 1;
}

.touch-left {
  grid-column: 1;
  grid-row: 2;
}

.touch-down {
  grid-column: 2;
  grid-row: 2;
}

.touch-right {
  grid-column: 3;
  grid-row: 2;
}

body.force-touch .touch-controls {
  display: block;
  left: 50%;
  right: auto;
  bottom: 8px;
  transform: translateX(-50%);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(248, 239, 210, 0.55);
  backdrop-filter: blur(5px);
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(420px, 92vw);
  padding: 30px;
  display: grid;
  justify-items: center;
  gap: 18px;
  border-radius: 8px;
  background: #fffdf4;
  border: 2px solid rgba(91, 135, 92, 0.24);
  box-shadow: 0 22px 55px rgba(65, 89, 76, 0.22);
  text-align: center;
}

.panel.compact {
  width: min(340px, 90vw);
}

.parent-panel {
  width: min(520px, 94vw);
}

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

.level-select-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: #fff8d7;
  color: #53380b;
  font-weight: 900;
  box-shadow:
    inset 0 -4px 0 rgba(112, 76, 14, 0.12),
    0 5px 12px rgba(59, 84, 74, 0.12);
  cursor: pointer;
}

.level-select-button.current {
  background: #ffcd4f;
  outline: 3px solid rgba(82, 154, 218, 0.24);
}

.big-mark {
  font-size: 56px;
  line-height: 1;
}

h1,
h2 {
  margin: 0;
  color: #263f42;
  letter-spacing: 0;
}

h1 {
  font-size: 34px;
}

h2 {
  font-size: 30px;
}

.primary-button,
.secondary-button {
  min-width: 168px;
  min-height: 52px;
  padding: 12px 26px;
  border-radius: 999px;
  border: 0;
  font-weight: 900;
  cursor: pointer;
  box-shadow:
    inset 0 -5px 0 rgba(0, 0, 0, 0.12),
    0 10px 18px rgba(59, 84, 74, 0.13);
}

.primary-button {
  background: #ffcd4f;
  color: #53380b;
}

.secondary-button {
  background: #d9f0ff;
  color: #244d5a;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .top-bar {
    min-height: 56px;
    gap: 10px;
  }

  .brand-title {
    display: none;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .hud {
    gap: 6px;
  }

  .level-badge,
  .controller-pill,
  .monster-toggle {
    height: 34px;
    padding: 0 9px;
    font-size: 13px;
  }

  .monster-toggle {
    gap: 5px;
    padding-left: 6px;
  }

  .monster-toggle-track {
    width: 38px;
    height: 22px;
  }

  .monster-toggle-thumb {
    width: 16px;
    height: 16px;
  }

  .monster-toggle input:checked + .monster-toggle-track .monster-toggle-thumb {
    transform: translateX(16px);
  }

  .monster-toggle-label {
    display: none;
  }

  .treasure-row {
    min-width: 86px;
    height: 36px;
    gap: 3px;
    padding: 0 6px;
  }

  .star-chip {
    width: 22px;
    height: 22px;
    font-size: 15px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 17px;
  }

  .panel {
    padding: 24px;
  }

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

@media (hover: none), (pointer: coarse) {
  .app-shell {
    width: 100vw;
    padding: 8px;
    gap: 8px;
  }

  .top-bar {
    min-height: 52px;
    padding: 7px 8px;
    gap: 8px;
  }

  .brand-title {
    display: none;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .hud {
    gap: 6px;
  }

  .controller-pill {
    display: none;
  }

  .level-badge,
  .monster-toggle {
    height: 34px;
    padding: 0 9px;
    font-size: 13px;
  }

  .treasure-row {
    min-width: 84px;
    height: 36px;
    gap: 2px;
    padding: 0 6px;
  }

  .star-chip {
    width: 20px;
    height: 20px;
    font-size: 14px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 17px;
  }

  .monster-toggle {
    gap: 5px;
    padding-left: 6px;
  }

  .monster-toggle-track {
    width: 38px;
    height: 22px;
  }

  .monster-toggle-thumb {
    width: 16px;
    height: 16px;
  }

  .monster-toggle input:checked + .monster-toggle-track .monster-toggle-thumb {
    transform: translateX(16px);
  }

  .monster-toggle-label {
    display: none;
  }

  .touch-controls {
    display: block;
  }

  .game-frame {
    border-radius: 8px;
  }
}

@media (hover: none) and (orientation: portrait), (pointer: coarse) and (orientation: portrait) {
  .app-shell {
    overflow: hidden;
  }

  .top-bar {
    width: 100%;
    min-width: 0;
    justify-content: flex-start;
    gap: 6px;
  }

  .brand {
    display: none;
  }

  .hud {
    width: 100%;
    flex: 1 1 auto;
    justify-content: space-between;
    gap: 4px;
    min-width: 0;
  }

  .level-badge {
    flex: 0 0 auto;
    padding: 0 8px;
    font-size: 12px;
  }

  .treasure-row {
    flex: 0 1 auto;
    min-width: 62px;
    height: 34px;
    padding: 0 8px;
  }

  .treasure-count {
    font-size: 13px;
  }

  .monster-toggle {
    flex: 0 0 auto;
    width: 42px;
    padding: 0;
    justify-content: center;
  }

  .icon-button {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
  }

  .touch-controls,
  body.force-touch .touch-controls {
    position: fixed;
    left: 50vw;
    right: auto;
    bottom: max(10px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    display: grid;
    justify-content: center;
  }

  .touch-pad {
    grid-template-columns: repeat(3, clamp(68px, 22vw, 82px));
    grid-template-rows: repeat(2, clamp(68px, 22vw, 82px));
    gap: 8px;
  }

  .touch-button {
    width: clamp(68px, 22vw, 82px);
    height: clamp(68px, 22vw, 82px);
    font-size: clamp(34px, 11vw, 42px);
  }
}

@media (hover: none) and (orientation: landscape), (pointer: coarse) and (orientation: landscape) {
  .app-shell {
    padding: 6px;
    gap: 6px;
  }

  .top-bar {
    min-height: 46px;
    padding: 5px 7px;
  }

  .touch-controls,
  body.force-touch .touch-controls {
    left: auto;
    right: 12px;
    bottom: 10px;
    transform: none;
  }

  .touch-pad {
    grid-template-columns: repeat(3, 58px);
    grid-template-rows: repeat(2, 58px);
    gap: 6px;
  }

  .touch-button {
    width: 58px;
    height: 58px;
    font-size: 31px;
    background: rgba(255, 253, 244, 0.82);
  }

  .panel {
    transform: scale(0.9);
  }
}
