:root {
  --paper: #f7f2e6;
  --paper-strong: #fffaf1;
  --ink: #1e292d;
  --muted: #657175;
  --line: #d7cebd;
  --green: #1f8a70;
  --green-dark: #146752;
  --amber: #d88b21;
  --red: #c94c3f;
  --blue: #2b6fbb;
  --violet: #7456b7;
  --shadow: 0 18px 42px rgba(31, 42, 46, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background:
    linear-gradient(90deg, rgba(31, 42, 46, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(31, 42, 46, 0.035) 1px, transparent 1px),
    linear-gradient(135deg, #eef4f0 0%, #f6e8cf 52%, #e9f0e4 100%);
  background-size: 20px 20px, 20px 20px, auto;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.brand-lockup,
.logo-mark {
  display: inline-flex;
  align-items: flex-end;
  gap: 7px;
}

.brand-main,
.logo-mark span {
  font-size: 27px;
  font-weight: 900;
  line-height: 1;
}

.brand-sub,
.logo-mark small {
  padding: 3px 6px 4px;
  border: 1px solid rgba(31, 42, 46, 0.18);
  border-radius: 6px;
  background: #fffaf1;
  color: var(--red);
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 8px 18px rgba(31, 42, 46, 0.08);
  font-weight: 900;
}

.game-layout {
  display: grid;
  gap: 10px;
}

.status-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat,
.resource-panel,
.tool-button,
.ad-button,
.control-panel {
  border: 2px solid rgba(31, 42, 46, 0.22);
  border-radius: 6px;
  background: rgba(255, 250, 241, 0.88);
  box-shadow: 4px 4px 0 rgba(31, 42, 46, 0.13);
}

.stat {
  min-height: 58px;
  padding: 9px 10px;
  position: relative;
  overflow: hidden;
}

.stat::after {
  content: "";
  position: absolute;
  inset: 4px auto auto 4px;
  width: 28px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
}

.stat span,
.resource-head span,
.resource-foot,
.tool-button small {
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 21px;
}

.resource-panel {
  padding: 10px;
}

.resource-head,
.resource-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.resource-head {
  margin-bottom: 7px;
}

.resource-foot {
  margin-top: 7px;
}

.resource-head strong {
  color: var(--green-dark);
  font-size: 17px;
}

.meter {
  overflow: hidden;
  height: 12px;
  border: 1px solid rgba(31, 42, 46, 0.14);
  border-radius: 999px;
  background: #e4dccf;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.26) 0 16px, transparent 16px 28px),
    var(--green);
  background-size: 28px 100%, auto;
  transition: width 140ms ease;
}

.board-wrap {
  position: relative;
  overflow: hidden;
  border: 3px solid rgba(31, 42, 46, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(31, 42, 46, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(31, 42, 46, 0.04) 1px, transparent 1px),
    #eee1c8;
  background-size: 44px 44px;
  box-shadow: 6px 6px 0 rgba(31, 42, 46, 0.11), var(--shadow);
  aspect-ratio: 18 / 19;
}

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

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  max-width: calc(100% - 32px);
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(31, 42, 46, 0.9);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
  white-space: nowrap;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

.ad-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tool-button {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 58px;
  gap: 8px;
  padding: 8px;
  border: 2px solid transparent;
  text-align: left;
}

.tool-button.is-selected {
  border-color: var(--green);
  background: #eef8f3;
  box-shadow: 4px 4px 0 rgba(20, 103, 82, 0.22);
}

.tool-button.is-resetting {
  border-color: var(--red);
  background: #fff0ed;
}

.tool-button:disabled {
  color: rgba(31, 42, 46, 0.36);
}

.tool-icon {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid rgba(31, 42, 46, 0.52);
  border-radius: 5px;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 2px 2px 0 rgba(31, 42, 46, 0.22), inset 2px 2px 0 rgba(255,255,255,0.18);
}

.tool-icon.report {
  background: var(--blue);
}

.tool-icon.meeting {
  background: var(--violet);
}

.tool-icon.bug {
  background: var(--red);
}

.tool-icon.ai {
  background: #313b47;
}

.tool-button strong {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.15;
}

.skill-badge {
  display: inline-grid;
  min-width: 18px;
  height: 18px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0 4px;
  border-radius: 5px;
  font-size: 9px;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
  color: #fff;
}

.skill-badge.slow {
  background: #2b6fbb;
}

.skill-badge.single {
  background: #7456b7;
}

.skill-badge.multi {
  background: #c94c3f;
}

.skill-badge.max {
  min-width: 28px;
  background: #1e292d;
  letter-spacing: 0;
}

.ad-button {
  display: grid;
  min-height: 58px;
  place-items: center;
  gap: 3px;
  padding: 8px 6px;
  border: 1px solid rgba(31, 42, 46, 0.14);
  text-align: center;
}

.ad-button span {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border: 2px solid rgba(31, 42, 46, 0.2);
  border-radius: 4px;
  background: #fff4db;
  color: var(--amber);
  font-weight: 900;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,0.4);
}

.ad-button strong {
  font-size: 13px;
  line-height: 1.15;
}

.ad-button:disabled {
  color: rgba(31, 42, 46, 0.34);
}

.ad-button:disabled span {
  background: #ebe4d7;
  color: rgba(31, 42, 46, 0.34);
}

.control-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 8px;
}

.control-panel.has-level-two {
  grid-template-columns: 1fr 1fr;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border-radius: 6px;
  font-weight: 800;
}

.primary-button {
  border: 0;
  background: var(--green);
  color: #fff;
  box-shadow: 3px 3px 0 rgba(31, 42, 46, 0.18);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.share-report-button {
  width: 100%;
  min-height: 42px;
  margin-top: 12px;
  border: 1px dashed rgba(31, 42, 46, 0.24);
  border-radius: 8px;
  background: #fffaf1;
  color: #1e292d;
  font-weight: 900;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(31, 42, 46, 0.48);
  backdrop-filter: blur(7px);
}

.overlay.is-visible {
  display: flex;
}

.dialog {
  width: min(100%, 430px);
  border: 1px solid rgba(31, 42, 46, 0.14);
  border-radius: 8px;
  background: var(--paper-strong);
  box-shadow: var(--shadow);
}

.start-dialog,
.result-dialog {
  padding: 22px;
}

.dialog h1,
.dialog h2 {
  margin: 18px 0 8px;
  font-size: 29px;
  line-height: 1.1;
}

.dialog h2 {
  margin-top: 0;
}

.dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.tutorial-card {
  margin: 14px 0 12px;
  padding: 10px;
  border: 2px solid rgba(31, 42, 46, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(31, 42, 46, 0.045) 1px, transparent 1px),
    linear-gradient(180deg, rgba(31, 42, 46, 0.045) 1px, transparent 1px),
    #f3ead6;
  background-size: 24px 24px;
}

.tutorial-board {
  position: relative;
  overflow: hidden;
  height: 132px;
  border: 2px solid rgba(31, 42, 46, 0.16);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.82);
}

.tutorial-path {
  position: absolute;
  left: 24px;
  top: 35px;
  width: 275px;
  height: 64px;
  border: 9px solid #9b744d;
  border-left: 0;
  border-bottom: 0;
  border-radius: 0 18px 0 0;
}

.tutorial-path::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-top: 3px dashed rgba(31, 42, 46, 0.24);
  border-right: 3px dashed rgba(31, 42, 46, 0.24);
}

.tutorial-enemy,
.tutorial-slot,
.tutorial-operator,
.tutorial-shot {
  position: absolute;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.tutorial-enemy {
  left: 22px;
  top: 24px;
  width: 32px;
  height: 32px;
  border: 2px solid #fffaf1;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  animation: tutorialEnemy 3.2s ease-in-out infinite;
}

.tutorial-slot {
  left: 132px;
  top: 67px;
  width: 58px;
  height: 38px;
  border: 2px solid #b79362;
  border-radius: 8px;
  background: #fff2ce;
  color: rgba(31, 42, 46, 0.42);
  font-size: 12px;
}

.tutorial-operator {
  left: 142px;
  top: 52px;
  width: 42px;
  height: 42px;
  border: 2px solid #fffaf1;
  border-radius: 10px;
  background: #f28bb8;
  color: #fff;
  font-size: 12px;
  animation: tutorialDeploy 3.2s ease-in-out infinite;
}

.tutorial-shot {
  left: 172px;
  top: 50px;
  width: 28px;
  height: 28px;
  border: 2px solid var(--green);
  border-radius: 8px;
  background: #fffaf1;
  color: var(--green-dark);
  animation: tutorialShot 3.2s ease-in-out infinite;
}

.tutorial-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 9px 0 0;
  padding: 0;
  list-style: none;
}

.tutorial-steps li {
  display: grid;
  gap: 4px;
  min-height: 48px;
  place-items: center;
  padding: 6px 4px;
  border-radius: 6px;
  background: rgba(255, 250, 241, 0.8);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.tutorial-steps span {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
}

@keyframes tutorialEnemy {
  0%, 12% {
    transform: translate(0, 0);
  }
  48% {
    transform: translate(218px, 0);
  }
  78%, 100% {
    transform: translate(218px, 58px);
  }
}

@keyframes tutorialDeploy {
  0%, 24% {
    opacity: 0;
    transform: translateY(8px) scale(0.84);
  }
  34%, 100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes tutorialShot {
  0%, 36% {
    opacity: 0;
    transform: translate(0, 0) scale(0.8);
  }
  54% {
    opacity: 1;
    transform: translate(84px, -22px) scale(1);
  }
  70%, 100% {
    opacity: 0;
    transform: translate(116px, -24px) scale(0.88);
  }
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.dialog-actions.single-action {
  grid-template-columns: 1fr;
}

.reward-summary {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: var(--ink);
  font-size: 14px;
}

.reward-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #f1e9db;
}

.poster-dialog {
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 16px;
}

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

.poster-head h2 {
  margin: 0;
  font-size: 22px;
}

.poster-image {
  display: block;
  width: 100%;
  border: 1px solid rgba(31, 42, 46, 0.14);
  border-radius: 8px;
  background: #eee1c8;
}

.share-link-box {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  background: #f1e9db;
}

.share-link-box span {
  color: var(--muted);
  font-size: 12px;
}

.share-link-box strong {
  color: var(--green-dark);
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.poster-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.poster-actions .primary-button {
  grid-column: 1 / -1;
}

.poster-download {
  display: grid;
  place-items: center;
  text-decoration: none;
  color: var(--ink);
}

@media (min-width: 900px) {
  .app-shell {
    width: min(100%, 980px);
  }

  .game-layout {
    grid-template-columns: 300px minmax(420px, 560px);
    align-items: start;
  }

  .status-panel,
  .resource-panel,
  .tool-panel,
  .ad-panel,
  .control-panel {
    grid-column: 1;
  }

  .board-wrap {
    grid-column: 2;
    grid-row: 1 / span 6;
  }
}

@media (max-width: 370px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .tool-panel,
  .ad-panel,
  .control-panel,
  .dialog-actions,
  .tutorial-steps,
  .poster-actions {
    grid-template-columns: 1fr;
  }

  .poster-actions .primary-button {
    grid-column: auto;
  }
}
