:root {
  color-scheme: dark;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #121b1f;
  color: #f4ead2;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background:
    linear-gradient(90deg, rgba(235, 201, 103, .05) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(180deg, #17262b 0%, #10191d 52%, #0b1114 100%);
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

[hidden] {
  display: none !important;
}

.app {
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  -webkit-user-select: none;
  user-select: none;
}

.play-area {
  width: min(1180px, 100%);
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  margin: 0 0 6px;
  color: #f0c15c;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .12em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: #fff4d6;
  font-size: 30px;
  line-height: 1.06;
  letter-spacing: 0;
}

.mission {
  max-width: 720px;
  margin: 7px 0 0;
  color: rgba(244, 234, 210, .72);
  font-size: 14px;
  line-height: 1.45;
}

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

.top-actions button,
.choice-row button {
  border: 2px solid rgba(255, 244, 214, .24);
  border-radius: 8px;
  color: #fff4d6;
  background: rgba(255, 255, 255, .08);
  cursor: pointer;
}

.top-actions button {
  width: 44px;
  height: 44px;
  font-size: 24px;
  font-weight: 900;
}

#manualButton {
  font-size: 20px;
}

.top-actions button:hover,
.choice-row button:hover {
  border-color: #f0c15c;
  background: rgba(240, 193, 92, .18);
}

.game-shell {
  min-height: 0;
  display: grid;
  grid-template-columns: auto 330px;
  gap: 14px;
  justify-content: center;
  align-items: start;
}

.board-panel,
.side-panel {
  border: 1px solid rgba(255, 244, 214, .14);
  border-radius: 8px;
  background: rgba(255, 255, 255, .055);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .22);
}

.board-panel {
  width: min(clamp(460px, calc(100svh - 128px), 700px), calc(100vw - 410px));
  min-height: 0;
  display: grid;
  gap: 10px;
  padding: 12px;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  background: #141719;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.mobile-pad {
  display: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.side-panel {
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  padding: 14px;
  display: grid;
  gap: 12px;
  align-content: start;
}

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

.stats div,
.keys,
.guide,
.inspect,
.log {
  border: 1px solid rgba(255, 244, 214, .12);
  border-radius: 8px;
  background: rgba(13, 18, 20, .48);
}

.stats div {
  min-height: 70px;
  padding: 10px;
  display: grid;
  align-content: center;
  gap: 4px;
}

.stats span,
.label {
  color: rgba(244, 234, 210, .62);
  font-size: 12px;
  font-weight: 800;
}

.stats strong {
  color: #fff4d6;
  font-size: 24px;
  line-height: 1;
}

.keys {
  min-height: 48px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 8px;
}

.keys span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #fff4d6;
  font-size: 18px;
  font-weight: 900;
}

.key-dot {
  width: 17px;
  height: 17px;
  border: 2px solid #1c272b;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 1px rgba(255, 244, 214, .2);
}

.key-dot.yellow {
  background: #f0c15c;
}

.key-dot.blue {
  background: #65c6d1;
}

.key-dot.red {
  background: #e66b61;
}

.inspect {
  min-height: 144px;
  padding: 14px;
}

.guide {
  min-height: 78px;
  padding: 12px;
}

.label {
  margin-bottom: 7px;
  letter-spacing: .08em;
}

#guideText {
  margin-bottom: 0;
  color: #fff4d6;
  font-size: 15px;
  font-weight: 780;
  line-height: 1.48;
}

h2 {
  margin-bottom: 8px;
  color: #f0c15c;
  font-size: 22px;
  line-height: 1.18;
  letter-spacing: 0;
}

#inspectText {
  margin-bottom: 0;
  color: rgba(244, 234, 210, .82);
  font-size: 14px;
  line-height: 1.55;
}

.choice-row {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.choice-row button {
  min-height: 40px;
  padding: 0 12px;
  color: #18262b;
  font-size: 14px;
  font-weight: 900;
  background: #f0c15c;
}

.choice-row button:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.log {
  min-height: 76px;
  padding: 13px;
}

#logText {
  margin-bottom: 0;
  color: rgba(244, 234, 210, .76);
  font-size: 14px;
  line-height: 1.55;
}

.battle-modal,
.handbook-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 8, 9, .72);
}

.handbook-modal {
  z-index: 30;
}

.handbook-card {
  width: min(680px, 100%);
  max-height: calc(100svh - 32px);
  border: 1px solid rgba(240, 193, 92, .42);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  background: rgba(15, 23, 26, .97);
  box-shadow: 0 22px 60px rgba(0, 0, 0, .42);
}

.handbook-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.handbook-head h2 {
  margin-bottom: 0;
}

#handbookCloseButton {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 244, 214, .22);
  border-radius: 8px;
  color: #fff4d6;
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  background: rgba(255, 255, 255, .08);
  cursor: pointer;
}

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

.handbook-tabs button {
  min-height: 38px;
  border: 1px solid rgba(255, 244, 214, .16);
  border-radius: 8px;
  color: #fff4d6;
  font-weight: 900;
  background: rgba(255, 255, 255, .07);
  cursor: pointer;
}

.handbook-tabs button.is-active {
  border-color: rgba(240, 193, 92, .7);
  color: #17262b;
  background: #f0c15c;
}

.handbook-content {
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  display: grid;
  gap: 10px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.handbook-section {
  display: grid;
  gap: 8px;
}

.handbook-row {
  border: 1px solid rgba(255, 244, 214, .12);
  border-radius: 8px;
  min-height: 66px;
  padding: 9px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  background: rgba(13, 18, 20, .48);
}

.handbook-icon {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 244, 214, .14);
  border-radius: 7px;
  display: block;
  background: #17262b;
  image-rendering: pixelated;
}

.handbook-icon-empty {
  opacity: 0;
}

.handbook-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.handbook-row strong {
  color: #fff4d6;
  font-size: 15px;
  line-height: 1.2;
}

.handbook-row span,
.handbook-row p {
  margin-bottom: 0;
  color: rgba(244, 234, 210, .76);
  font-size: 13px;
  line-height: 1.42;
}

.handbook-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.monster-stat {
  color: #f0c15c;
  font-weight: 900;
}

.battle-card {
  width: min(560px, 100%);
  border: 1px solid rgba(240, 193, 92, .48);
  border-radius: 8px;
  padding: 16px;
  background: rgba(15, 23, 26, .96);
  box-shadow: 0 22px 60px rgba(0, 0, 0, .42);
}

.battle-card.is-animating {
  border-color: rgba(240, 193, 92, .78);
  box-shadow: 0 0 0 1px rgba(240, 193, 92, .18), 0 22px 60px rgba(0, 0, 0, .42);
}

.battle-lineup {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.fighter {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 8px;
  color: #fff4d6;
  text-align: center;
}

.fighter canvas {
  width: 96px;
  height: 96px;
  border: 1px solid rgba(255, 244, 214, .16);
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.fighter strong {
  font-size: 18px;
  line-height: 1.1;
}

.fighter span {
  color: rgba(244, 234, 210, .72);
  font-size: 13px;
  line-height: 1.35;
}

.versus {
  color: #f0c15c;
  font-size: 22px;
  font-weight: 950;
}

.battle-fx {
  min-height: 28px;
  margin-top: 12px;
  border: 1px solid rgba(240, 193, 92, .22);
  border-radius: 8px;
  padding: 6px 10px;
  display: grid;
  place-items: center;
  color: #f4ead2;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.1;
  background: rgba(240, 193, 92, .08);
}

.battle-card.is-animating .versus {
  animation: pulseVs .58s steps(2, end) infinite;
}

.battle-result {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.battle-result span {
  min-height: 52px;
  border: 1px solid rgba(255, 244, 214, .12);
  border-radius: 8px;
  padding: 9px;
  display: grid;
  align-content: center;
  gap: 3px;
  color: rgba(244, 234, 210, .62);
  font-size: 12px;
}

.battle-result b {
  color: #fff4d6;
  font-size: 21px;
}

.battle-hint {
  margin: 12px 0 0;
  color: rgba(244, 234, 210, .82);
  font-size: 14px;
  line-height: 1.45;
}

.battle-actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.battle-actions button {
  min-height: 44px;
  border: 1px solid rgba(255, 244, 214, .22);
  border-radius: 8px;
  color: #fff4d6;
  font-weight: 900;
  background: rgba(255, 255, 255, .08);
  cursor: pointer;
}

#battleFightButton {
  color: #17262b;
  background: #f0c15c;
}

#battleSkipButton {
  color: #17262b;
  background: #f0c15c;
}

#battleFightButton:disabled {
  opacity: .48;
  cursor: not-allowed;
}

@keyframes pulseVs {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.12);
  }
}

@media (max-width: 900px) {
  .app {
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .play-area {
    gap: 6px;
  }

  .topbar {
    align-items: center;
  }

  h1 {
    font-size: 24px;
  }

  .mission {
    max-width: 300px;
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.35;
  }

  .top-actions button {
    width: 40px;
    height: 40px;
  }

  .game-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 6px;
    min-height: 0;
    overflow: hidden;
    align-content: start;
  }

  .board-panel {
    width: min(calc(100vw - 16px), calc(100svh - 224px));
    min-width: 280px;
    margin: 0 auto;
    padding: 6px;
    gap: 0;
    align-self: start;
  }

  .mobile-pad {
    display: block;
    position: relative;
    grid-area: pad;
    align-self: center;
    justify-self: end;
    width: 148px;
    height: 148px;
    padding: 0;
    border: 0;
    background: transparent;
    backdrop-filter: blur(5px);
  }

  .pad-key,
  .pad-center {
    position: absolute;
    min-width: 0;
    min-height: 0;
    border-radius: 8px;
  }

  .pad-key {
    --key-x: 0px;
    --key-y: 0px;
    width: 54px;
    height: 54px;
    border: 1px solid rgba(244, 234, 210, .34);
    color: #17262b;
    font-size: 20px;
    font-weight: 950;
    line-height: 1;
    background: #f4ead2;
    box-shadow: 0 4px 0 rgba(0, 0, 0, .34);
    cursor: pointer;
    touch-action: none;
    transform: translate(var(--key-x), var(--key-y));
  }

  .pad-key:active,
  .pad-key.is-pressed {
    transform: translate(var(--key-x), calc(var(--key-y) + 3px));
    box-shadow: 0 1px 0 rgba(0, 0, 0, .34);
    background: #f0c15c;
  }

  .pad-center {
    left: 50%;
    top: 50%;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(244, 234, 210, .14);
    background:
      linear-gradient(90deg, transparent 46%, rgba(244, 234, 210, .18) 47% 53%, transparent 54%),
      linear-gradient(0deg, transparent 46%, rgba(244, 234, 210, .18) 47% 53%, transparent 54%),
      rgba(12, 17, 19, .58);
    transform: translate(-50%, -50%);
  }

  .pad-up {
    left: 50%;
    top: 0;
    --key-x: -50%;
  }

  .pad-left {
    left: 0;
    top: 50%;
    --key-y: -50%;
  }

  .pad-right {
    right: 0;
    top: 50%;
    --key-y: -50%;
  }

  .pad-down {
    left: 50%;
    bottom: 0;
    --key-x: -50%;
  }

  .side-panel {
    grid-template-columns: minmax(0, 1fr) 154px;
    grid-template-areas:
      "stats pad"
      "keys pad"
      "guide pad";
    max-height: none;
    min-height: 0;
    padding: 8px;
    gap: 6px;
    overflow: hidden;
  }

  .stats {
    grid-area: stats;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .stats div {
    min-height: 40px;
    padding: 5px 7px;
  }

  .stats span,
  .label {
    font-size: 9px;
  }

  .stats strong {
    font-size: 16px;
  }

  .keys {
    grid-area: keys;
    min-height: 32px;
    padding: 5px;
  }

  .keys span {
    font-size: 14px;
  }

  .key-dot {
    width: 14px;
    height: 14px;
  }

  .guide {
    grid-area: guide;
    min-height: 50px;
    padding: 7px 9px;
  }

  #guideText {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 12px;
    line-height: 1.28;
  }

  .inspect {
    display: none;
    min-height: 92px;
    padding: 9px 10px;
  }

  .side-panel.is-shop .guide {
    display: none;
  }

  .side-panel.is-shop .inspect {
    display: block;
    grid-area: guide;
    min-height: 50px;
    padding: 6px;
  }

  .side-panel.is-shop .inspect .label,
  .side-panel.is-shop .inspect h2,
  .side-panel.is-shop #inspectText {
    display: none;
  }

  .side-panel.is-shop .choice-row {
    margin-top: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .side-panel.is-shop .choice-row button {
    min-height: 38px;
    padding: 0 4px;
    font-size: 10px;
    line-height: 1.08;
  }

  h2 {
    margin-bottom: 5px;
    font-size: 18px;
  }

  #inspectText {
    font-size: 12px;
    line-height: 1.38;
  }

  .choice-row {
    margin-top: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .choice-row button {
    min-height: 34px;
    padding: 0 6px;
    font-size: 12px;
  }

  .battle-modal {
    align-items: end;
    padding: 8px;
  }

  .handbook-modal {
    align-items: end;
    padding: 8px;
  }

  .handbook-card {
    max-height: calc(100svh - 16px);
    padding: 12px;
    gap: 9px;
  }

  .handbook-tabs {
    gap: 6px;
  }

  .handbook-tabs button {
    min-height: 34px;
    font-size: 13px;
  }

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

  .handbook-row {
    min-height: 58px;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 8px;
    padding: 7px;
  }

  .handbook-icon {
    width: 40px;
    height: 40px;
  }

  .handbook-row strong {
    font-size: 14px;
  }

  .handbook-row span,
  .handbook-row p {
    font-size: 12px;
    line-height: 1.36;
  }

  .battle-card {
    padding: 12px;
  }

  .battle-lineup {
    gap: 8px;
  }

  .fighter canvas {
    width: 70px;
    height: 70px;
  }

  .fighter strong {
    font-size: 15px;
  }

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

  .versus {
    font-size: 17px;
  }

  .battle-fx {
    min-height: 24px;
    margin-top: 8px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .battle-result {
    margin-top: 10px;
    gap: 6px;
  }

  .battle-result span {
    min-height: 42px;
    padding: 7px;
    font-size: 10px;
  }

  .battle-result b {
    font-size: 17px;
  }

  .battle-hint {
    margin-top: 9px;
    font-size: 12px;
    line-height: 1.34;
  }

  .battle-actions {
    margin-top: 10px;
    gap: 8px;
  }

  .battle-actions button {
    min-height: 40px;
    font-size: 14px;
  }

  .log {
    display: none;
  }

  #logText {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 11px;
    line-height: 1.24;
  }
}

@media (max-width: 560px) {
  .brand {
    font-size: 10px;
    margin-bottom: 3px;
  }

  .stats div {
    min-height: 43px;
  }

  .stats strong {
    font-size: 17px;
  }
}

@media (max-height: 720px) and (max-width: 900px) {
  .mission {
    display: none;
  }

  h1 {
    font-size: 22px;
  }

  .top-actions button {
    width: 36px;
    height: 36px;
  }

  .board-panel {
    width: min(calc(100vw - 16px), calc(100svh - 186px));
  }

  .mobile-pad {
    width: 132px;
    height: 132px;
  }

  .pad-key {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }

  .pad-center {
    width: 30px;
    height: 30px;
  }

  .side-panel {
    grid-template-columns: minmax(0, 1fr) 138px;
    padding: 7px;
    gap: 5px;
  }

  .stats {
    gap: 5px;
  }

  .stats div {
    min-height: 34px;
    padding: 4px 6px;
  }

  .stats strong {
    font-size: 14px;
  }

  .keys {
    min-height: 28px;
    padding: 4px;
  }

  .guide {
    min-height: 42px;
    padding: 6px 8px;
  }

  #guideText {
    font-size: 12px;
    line-height: 1.28;
  }

  .inspect {
    min-height: 76px;
    padding: 7px 9px;
  }

  h2 {
    font-size: 16px;
  }

  #inspectText {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 11px;
    line-height: 1.28;
  }

  .log {
    display: none;
  }

  .battle-card {
    padding: 10px;
  }

  .fighter canvas {
    width: 58px;
    height: 58px;
  }

  .battle-result span {
    min-height: 36px;
  }

  .battle-actions button {
    min-height: 36px;
  }

  .battle-fx {
    min-height: 22px;
    margin-top: 6px;
    font-size: 11px;
  }
}
