:root {
  --ink: #163b41;
  --ink-2: #245a60;
  --teal: #1d8a8d;
  --teal-dark: #146b70;
  --coral: #ef6a4f;
  --coral-dark: #d9533c;
  --amber: #f6b73c;
  --sky: #d9f1ee;
  --paper: #f4fbf9;
  --line: #b7d8d5;
  --danger: #c63f38;
  --win: #279b62;
  --shadow: 0 18px 45px rgba(29, 78, 84, 0.18);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 6%, rgba(246, 183, 60, 0.14) 0, transparent 26%),
    radial-gradient(circle at 92% 12%, rgba(29, 138, 141, 0.16) 0, transparent 30%),
    linear-gradient(180deg, #e9f8f6 0%, #f8fcfb 100%);
  letter-spacing: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

.page-shell {
  min-height: 100vh;
}

.screen {
  display: none;
  width: 100%;
}

.screen.active {
  display: flex;
}

.home-screen {
  min-height: 100vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 16px 38px;
}

.home-arts {
  width: min(720px, 92vw);
  line-height: 0;
}

#heroCanvas {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 12px 22px rgba(22, 59, 65, 0.14));
}

.home-main {
  width: min(680px, 94vw);
  text-align: center;
  margin-top: -2px;
}

.eyebrow {
  display: inline-block;
  padding: 5px 14px;
  color: var(--coral-dark);
  background: #ffe4d9;
  border: 1px solid #f8c2b1;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
}

.title-block h1 {
  margin: 0 0 12px;
  line-height: 0.98;
  font-weight: 900;
  font-size: 76px;
  letter-spacing: 0;
}

.title-block h1 span,
.title-block h1 em {
  display: block;
  font-style: normal;
}

.title-block h1 span {
  color: var(--ink);
}

.title-block h1 em {
  color: var(--coral);
  -webkit-text-stroke: 2px var(--coral-dark);
  text-shadow: 5px 5px 0 #ffd7c7;
}

.home-intro {
  margin: 4px auto 20px;
  max-width: 560px;
  color: var(--ink-2);
  font-size: 17px;
  line-height: 1.7;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.btn {
  min-height: 48px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 22px;
  font-weight: 800;
  font-size: 17px;
  color: #fff;
  box-shadow: 0 5px 0 rgba(22, 59, 65, 0.18);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(22, 59, 65, 0.18);
}

.btn-primary {
  background: var(--coral);
}

.btn-primary:hover {
  background: var(--coral-dark);
}

.btn-secondary {
  background: var(--teal);
}

.btn-secondary:hover {
  background: var(--teal-dark);
}

.btn-ghost {
  color: var(--teal-dark);
  background: #fff;
  border: 2px solid var(--teal);
  box-shadow: none;
}

.btn-ghost:hover {
  background: #e5f5f2;
}

.btn-danger {
  background: var(--danger);
}

.btn-start {
  background: var(--coral);
  font-size: 18px;
  min-width: 150px;
}

.btn-start:disabled,
.tool-btn:disabled,
.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

.btn-icon {
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.home-save-tip {
  margin-top: 16px;
  min-height: 22px;
  color: var(--ink-2);
  font-size: 14px;
}

.home-settings {
  margin: 18px auto 0;
  max-width: 560px;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 18px;
  background: rgba(255, 255, 255, 0.72);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}

.setting-line {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
}

.setting-line select {
  min-height: 34px;
  padding: 0 10px;
  border: 2px solid var(--teal);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.check-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.level-screen {
  min-height: 100vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 26px 18px;
}

.level-head {
  width: min(860px, 94vw);
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--ink);
  font-size: 21px;
  line-height: 1;
  flex: 0 0 auto;
}

.icon-btn:hover {
  background: var(--sky);
}

.level-title {
  font-size: 30px;
  font-weight: 900;
}

.level-subtitle {
  color: var(--ink-2);
  font-size: 15px;
}

.level-grid {
  width: min(880px, 94vw);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.level-card {
  min-height: 118px;
  border: 2px solid var(--ink);
  background: #fff;
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
  color: var(--ink);
  box-shadow: 4px 4px 0 rgba(22, 59, 65, 0.12);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.level-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 7px 7px 0 rgba(22, 59, 65, 0.12);
}

.level-card .card-index {
  color: var(--coral);
  font-size: 14px;
  font-weight: 900;
}

.level-card .card-name {
  font-size: 19px;
  font-weight: 900;
}

.level-card .card-note {
  color: var(--ink-2);
  font-size: 13px;
  margin-top: 4px;
}

.level-card.locked {
  background: #edf4f3;
  color: #78918f;
  border-style: dashed;
  box-shadow: none;
}

.level-card.locked:hover {
  transform: none;
  box-shadow: none;
}

.game-screen {
  min-height: 100vh;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 12px 14px 18px;
}

.game-top {
  width: min(970px, 96vw);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  position: relative;
}

.level-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  max-width: 68%;
  white-space: nowrap;
}

.level-copy strong {
  font-size: 21px;
  text-align: center;
}

.level-copy span {
  color: var(--ink-2);
  font-size: 14px;
  text-align: center;
}

.top-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-btn {
  min-height: 34px;
  padding: 0 11px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.mini-btn:hover {
  background: var(--sky);
}

.top-actions .status-pill {
  grid-column: auto;
  justify-self: auto;
  padding: 7px 13px;
  background: #dff2ef;
  border: 1px solid #a9cfcb;
  border-radius: var(--radius);
  color: var(--teal-dark);
  font-weight: 800;
  font-size: 14px;
  min-width: 92px;
  text-align: center;
}

.status-pill.running {
  color: #7a4a04;
  background: #fff0cb;
  border-color: #e6c262;
}

.status-pill.won {
  color: #11633a;
  background: #d8f3e3;
  border-color: #8dd2ab;
}

.status-pill.failed {
  color: #a52f29;
  background: #ffe0dc;
  border-color: #eaa098;
}

.canvas-holder {
  position: relative;
  width: min(970px, 96vw);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
  background: #e7f5f2;
  box-shadow: var(--shadow);
}

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

.canvas-toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  border: 2px solid var(--coral);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  max-width: 82%;
  text-align: center;
}

.canvas-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.battery-notice {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: 76%;
  padding: 9px 14px;
  background: #fff4dc;
  border: 2px solid #d8821d;
  border-radius: var(--radius);
  color: #7c4400;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(124, 68, 0, 0.18);
}

.battery-notice[hidden] {
  display: none;
}

body[data-device="phone"] .page-shell {
  max-width: 560px;
  margin: 0 auto;
}

body[data-device="phone"] .home-arts {
  width: min(500px, 94vw);
}

body[data-device="phone"] .title-block h1 {
  font-size: 54px;
}

body[data-device="phone"] .game-top,
body[data-device="phone"] .canvas-holder,
body[data-device="phone"] .game-bottom,
body[data-device="phone"] .level-head,
body[data-device="phone"] .level-grid,
body[data-device="phone"] .home-main,
body[data-device="phone"] .home-settings {
  width: 100%;
}

body[data-device="tablet"] .page-shell {
  max-width: 900px;
  margin: 0 auto;
}

body[data-device="tablet"] .game-top,
body[data-device="tablet"] .canvas-holder,
body[data-device="tablet"] .game-bottom {
  width: 100%;
}

body[data-device="desktop"] .page-shell {
  max-width: 1240px;
  margin: 0 auto;
}

body[data-device="screen"] .game-top,
body[data-device="screen"] .canvas-holder,
body[data-device="screen"] .game-bottom {
  width: min(1500px, 96vw);
}

.game-bottom {
  width: min(970px, 96vw);
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hint-line {
  color: var(--ink-2);
  font-size: 15px;
  font-weight: 700;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.tool-row[hidden] {
  display: none;
}

.tool-btn {
  min-height: 44px;
  padding: 0 15px;
  border-radius: var(--radius);
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-size: 15px;
}

.tool-btn:hover {
  background: var(--sky);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(13, 47, 51, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(400px, 94vw);
  background: #fffdfa;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  padding: 26px 24px 24px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(10, 42, 46, 0.34);
  animation: modal-pop 0.2s ease-out;
}

@keyframes modal-pop {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-card h2 {
  margin: 4px 0 8px;
  font-size: 28px;
}

.modal-card p {
  margin: 0 0 20px;
  color: var(--ink-2);
  line-height: 1.6;
  font-size: 16px;
}

.modal-symbol {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffddd7;
  color: var(--danger);
  border: 3px solid var(--danger);
  border-radius: 50%;
  font-size: 38px;
  font-weight: 900;
}

.modal-symbol.success {
  background: #d8f3e3;
  color: var(--win);
  border-color: var(--win);
}

.confirm-symbol {
  background: #fff0cb;
  color: #8b5a00;
  border-color: var(--amber);
  font-size: 32px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-card.compact {
  padding-bottom: 20px;
}

@media (max-width: 720px) {
  .title-block h1 {
    font-size: 52px;
  }

  .home-screen {
    padding-top: 18px;
  }

  .game-top {
    grid-template-columns: auto 1fr;
  }

  .top-actions {
    grid-column: 1 / -1;
    justify-self: end;
  }

  .game-bottom {
    justify-content: center;
  }

  .hint-line {
    width: 100%;
    text-align: center;
  }

  .tool-row {
    width: 100%;
    justify-content: center;
  }

  .tool-btn {
    flex: 1 1 auto;
  }
}
