:root {
  color-scheme: light;
  --ink: #2f302b;
  --muted: #817b70;
  --cream: #fff8ed;
  --paper: #fffdf8;
  --line: #eadfce;
  --orange: #ef8e45;
  --orange-dark: #d96d29;
  --green: #6d9868;
  --shadow: 0 18px 50px rgba(99, 71, 38, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--cream);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 10%, rgba(248, 199, 120, 0.26), transparent 27rem),
    radial-gradient(circle at 88% 72%, rgba(121, 168, 124, 0.18), transparent 30rem),
    var(--cream);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(239, 142, 69, 0.35);
  outline-offset: 3px;
}

.page-decoration {
  position: fixed;
  z-index: 0;
  width: 220px;
  height: 220px;
  border: 1px solid rgba(172, 129, 76, 0.13);
  border-radius: 50%;
  pointer-events: none;
}

.page-decoration::before,
.page-decoration::after {
  position: absolute;
  content: "";
  border-radius: 50%;
  border: inherit;
}

.page-decoration::before {
  inset: 28px;
}

.page-decoration::after {
  inset: 62px;
}

.decoration-left {
  top: 18%;
  left: -130px;
}

.decoration-right {
  right: -95px;
  bottom: 8%;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100% - 32px, 960px);
  margin: 0 auto;
  padding: 44px 0 26px;
}

.hero {
  width: min(100%, 830px);
  margin: 0 auto 22px;
}

.eyebrow,
.panel-kicker,
.overlay-kicker {
  color: var(--orange-dark);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.eyebrow span {
  margin-right: 7px;
  font-size: 8px;
  vertical-align: 2px;
}

.hero-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-top: 7px;
}

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

h1 {
  margin-bottom: 5px;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(36px, 6vw, 55px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.03em;
}

.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--green);
  background: rgba(255, 253, 248, 0.8);
  box-shadow: 0 8px 24px rgba(86, 64, 36, 0.08);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

.icon-button:hover {
  transform: translateY(-2px);
  background: white;
}

.icon-button.is-muted {
  color: #aaa196;
}

.score-strip {
  display: grid;
  width: min(100%, 830px);
  margin: 0 auto 14px;
  padding: 12px 16px;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(255, 253, 248, 0.78);
  box-shadow: 0 10px 35px rgba(92, 67, 38, 0.06);
  backdrop-filter: blur(12px);
}

.score-item {
  display: flex;
  min-width: 0;
  align-items: baseline;
  justify-content: center;
  gap: 9px;
}

.score-label {
  color: var(--muted);
  font-size: 12px;
}

.score-item strong {
  overflow: hidden;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-current strong {
  color: var(--orange-dark);
}

.crown-score {
  color: #b47b20;
}

.score-divider {
  width: 1px;
  height: 27px;
  background: var(--line);
}

.game-layout {
  display: grid;
  width: min(100%, 830px);
  margin: 0 auto;
  grid-template-columns: minmax(0, 485px) minmax(240px, 1fr);
  align-items: start;
  gap: 18px;
}

.board-card,
.level-panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.board-card {
  overflow: hidden;
}

.board-topbar {
  display: flex;
  min-height: 71px;
  padding: 10px 16px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #fffaf2;
}

.next-box {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.next-avatar {
  display: grid;
  width: 46px;
  height: 46px;
  overflow: hidden;
  place-items: center;
  border: 3px solid #f3a34a;
  border-radius: 50%;
  background: #f4e7d5;
  box-shadow: 0 4px 12px rgba(87, 60, 28, 0.13);
  transition: border-color 180ms ease, transform 180ms ease;
}

.next-avatar.is-changing {
  transform: scale(0.85) rotate(-5deg);
}

.next-avatar img,
.level-list img,
.overlay-photo-stack img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 35%;
}

.next-box span,
.next-box strong {
  display: block;
}

.next-box span {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
}

.next-box strong {
  font-size: 15px;
}

.tip-badge {
  padding: 7px 10px;
  border: 1px dashed #d8c8b2;
  border-radius: 999px;
  color: #85796b;
  font-size: 11px;
  white-space: nowrap;
}

.canvas-wrap {
  position: relative;
  background: #f7efe3;
  contain: paint;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(67vh, 640px);
  aspect-ratio: 390 / 560;
  background: #f8efe3;
  cursor: crosshair;
  touch-action: none;
  transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#gameCanvas.is-excavating {
  cursor: crosshair;
  outline: 4px solid rgba(229, 183, 63, 0.72);
  outline-offset: -4px;
}

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  padding: 24px;
  place-items: center;
  background: rgba(249, 241, 229, 0.77);
  backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms ease, visibility 220ms ease;
}

.game-overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.overlay-card {
  width: min(100%, 320px);
  padding: 25px 22px 22px;
  text-align: center;
  border: 1px solid rgba(225, 207, 183, 0.9);
  border-radius: 24px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 22px 60px rgba(75, 55, 32, 0.16);
  transform: translateY(10px) scale(0.98);
  transition: transform 260ms ease;
}

.game-overlay.is-visible .overlay-card {
  transform: translateY(0) scale(1);
}

.overlay-photo-stack {
  display: flex;
  margin: 0 auto 20px;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.overlay-photo-stack img {
  width: 48px;
  height: 48px;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(67, 47, 26, 0.18);
}

.overlay-photo-stack img:last-child {
  width: 60px;
  height: 60px;
  border-color: #ed796f;
}

.overlay-photo-stack span {
  color: #a59684;
  font-weight: 800;
}

.overlay-card .overlay-kicker {
  margin-bottom: 8px;
}

.overlay-card h2 {
  margin-bottom: 9px;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 29px;
}

.overlay-card > p:not(.overlay-kicker) {
  margin-bottom: 19px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.primary-button,
.drop-button,
.secondary-button {
  border: 0;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.primary-button {
  width: 100%;
  padding: 13px 20px;
  border-radius: 14px;
  color: white;
  background: var(--orange);
  box-shadow: 0 8px 20px rgba(220, 111, 39, 0.25);
  font-weight: 750;
}

.primary-button:hover,
.drop-button:hover {
  background: var(--orange-dark);
  box-shadow: 0 10px 25px rgba(220, 111, 39, 0.3);
  transform: translateY(-1px);
}

.result-emoji {
  margin: 0 auto 8px;
  color: #d69a36;
  font-size: 34px;
}

.result-card strong {
  color: var(--orange-dark);
}

.achievement-toast {
  position: absolute;
  z-index: 6;
  top: 20px;
  left: 50%;
  display: flex;
  padding: 10px 16px 10px 12px;
  align-items: center;
  gap: 10px;
  border: 1px solid #e9c874;
  border-radius: 15px;
  background: #fff9dc;
  box-shadow: 0 12px 35px rgba(105, 76, 27, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -20px) scale(0.9);
  transition: opacity 250ms ease, transform 380ms cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

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

.achievement-toast > span {
  font-size: 25px;
}

.achievement-toast small,
.achievement-toast strong {
  display: block;
  white-space: nowrap;
}

.achievement-toast small {
  color: #8d7950;
  font-size: 10px;
}

.achievement-toast strong {
  margin-top: 1px;
  font-size: 14px;
}

.board-actions {
  display: grid;
  padding: 12px 14px 14px;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: #fffaf2;
}

.helper-strip {
  display: grid;
  min-height: 72px;
  padding: 9px 13px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: linear-gradient(90deg, #fff8df, #f3f7e9);
}

.sister-crew {
  display: flex;
  min-width: 67px;
  align-items: center;
}

.sister-crew img {
  width: 43px;
  height: 43px;
  object-fit: cover;
  object-position: center 32%;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(76, 56, 28, 0.16);
  filter: grayscale(0.9);
  opacity: 0.52;
  transition: filter 180ms ease, opacity 180ms ease, transform 180ms ease;
}

.sister-crew img + img {
  margin-left: -16px;
}

.sister-crew img.is-ready {
  z-index: 2;
  filter: none;
  opacity: 1;
  transform: translateY(-2px);
}

.sister-crew img.is-used {
  filter: grayscale(1);
  opacity: 0.3;
}

.helper-copy {
  min-width: 0;
}

.helper-copy span,
.helper-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.helper-copy span {
  margin-bottom: 3px;
  color: #7f6b39;
  font-size: 12px;
  font-weight: 800;
}

.helper-copy small {
  color: var(--muted);
  font-size: 10px;
}

.excavator-button {
  display: grid;
  min-width: 82px;
  min-height: 49px;
  padding: 5px 9px;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: center;
  gap: 0 5px;
  border: 1px solid #dfbd54;
  border-radius: 13px;
  color: #644c18;
  background: #ffd95a;
  box-shadow: 0 6px 15px rgba(144, 101, 17, 0.16);
  cursor: pointer;
}

.excavator-button > span {
  grid-row: 1 / 3;
  font-size: 23px;
}

.excavator-button strong,
.excavator-button small {
  line-height: 1.1;
}

.excavator-button strong {
  font-size: 11px;
}

.excavator-button small {
  font-size: 9px;
}

.excavator-button:disabled {
  border-color: #ddd3b7;
  background: #eee7d5;
  box-shadow: none;
  cursor: not-allowed;
  filter: grayscale(0.7);
  opacity: 0.7;
}

.excavator-button.is-active {
  color: #fff;
  background: #d69220;
  box-shadow: 0 0 0 4px rgba(229, 183, 63, 0.28);
  transform: translateY(-1px);
}

.drop-button,
.secondary-button {
  min-height: 45px;
  border-radius: 13px;
  font-weight: 700;
}

.drop-button {
  color: white;
  background: var(--orange);
  box-shadow: 0 7px 18px rgba(220, 111, 39, 0.2);
}

.drop-button span {
  display: inline-block;
  margin-right: 5px;
  font-size: 18px;
  transition: transform 150ms ease;
}

.drop-button:active span {
  transform: translateY(3px);
}

.secondary-button {
  padding: 0 16px;
  border: 1px solid var(--line);
  color: #6f675d;
  background: #fffdf8;
}

.secondary-button:hover {
  background: #f5ecdf;
}

.level-panel {
  padding: 19px 17px 17px;
}

.level-heading {
  display: flex;
  padding: 0 3px 14px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.level-heading h2 {
  margin: 3px 0 0;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 23px;
}

.level-count {
  padding: 5px 8px;
  border-radius: 8px;
  color: #8e826f;
  background: #f4ecdf;
  font-size: 11px;
}

.level-list {
  display: grid;
  margin: 0;
  padding: 13px 0 0;
  gap: 7px;
  list-style: none;
}

.level-list li {
  position: relative;
  display: grid;
  min-height: 55px;
  padding: 6px 7px;
  grid-template-columns: 20px 43px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 13px;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.level-list li.is-reached {
  border-color: color-mix(in srgb, var(--level-color) 35%, white);
  background: color-mix(in srgb, var(--level-color) 9%, white);
  transform: translateX(2px);
}

.level-list li.is-current {
  border-color: var(--level-color);
  background: color-mix(in srgb, var(--level-color) 13%, white);
}

.level-number {
  color: var(--level-color);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.level-list img {
  width: 43px;
  height: 43px;
  border: 3px solid var(--level-color);
  border-radius: 50%;
  box-shadow: 0 3px 9px rgba(65, 45, 28, 0.12);
}

.level-list strong,
.level-list small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-list strong {
  margin-bottom: 1px;
  font-size: 14px;
}

.level-list small {
  color: var(--muted);
  font-size: 10px;
}

.level-final {
  padding-right: 30px !important;
}

.crown {
  position: absolute;
  right: 10px;
  color: #bd852c;
  font-size: 17px;
}

.desktop-help {
  margin-top: 14px;
  padding: 13px;
  border-radius: 13px;
  background: #f6efe4;
}

.desktop-help span {
  display: inline-block;
  margin-bottom: 4px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

.desktop-help p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

footer {
  padding-top: 19px;
  color: #9b9185;
  font-size: 11px;
  text-align: center;
}

@media (max-width: 720px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    min-height: 100dvh;
    background: #f8efe3;
  }

  .page-decoration,
  .level-panel,
  footer,
  .eyebrow,
  .hero p {
    display: none;
  }

  .app-shell {
    display: flex;
    width: 100%;
    height: 100dvh;
    margin: 0;
    padding: env(safe-area-inset-top) 0 0;
    flex-direction: column;
    overflow: hidden;
  }

  .hero {
    flex: 0 0 50px;
    width: 100%;
    margin: 0;
    padding: 5px 12px 4px 16px;
    border-bottom: 1px solid rgba(223, 199, 165, 0.8);
    background: linear-gradient(90deg, #fff7e8, #f3f7e9);
  }

  .hero-title-row {
    height: 100%;
    margin: 0;
    align-items: center;
  }

  h1 {
    margin: 0;
    font-size: 25px;
    line-height: 1;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.72);
    box-shadow: none;
  }

  .score-strip {
    flex: 0 0 52px;
    width: 100%;
    margin: 0;
    padding: 7px 8px;
    border-width: 0 0 1px;
    border-radius: 0;
    background: #fffdf8;
    box-shadow: none;
    backdrop-filter: none;
  }

  .game-overlay {
    background: rgba(249, 241, 229, 0.95);
    backdrop-filter: none;
  }

  .score-item {
    display: block;
    text-align: center;
  }

  .score-label {
    display: block;
    margin-bottom: 2px;
    font-size: 10px;
  }

  .score-item strong {
    font-size: 17px;
  }

  .game-layout {
    display: block;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    margin: 0;
  }

  .board-card {
    display: flex;
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    flex-direction: column;
    box-shadow: none;
  }

  .board-topbar {
    flex: 0 0 52px;
    min-height: 0;
    padding: 5px 12px;
    background: rgba(255, 250, 242, 0.96);
  }

  .next-avatar {
    width: 40px;
    height: 40px;
  }

  .canvas-wrap {
    display: grid;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  #gameCanvas {
    width: 100%;
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
  }

  .helper-strip {
    flex: 0 0 60px;
    min-height: 0;
    padding-inline: 10px;
    gap: 7px;
  }

  .sister-crew {
    min-width: 57px;
  }

  .sister-crew img {
    width: 38px;
    height: 38px;
  }

  .excavator-button {
    min-width: 74px;
    min-height: 44px;
    padding-inline: 7px;
  }

  .board-actions {
    flex: 0 0 calc(58px + env(safe-area-inset-bottom));
    padding: 7px 10px max(7px, env(safe-area-inset-bottom));
    background: #fffaf2;
  }
}

@media (max-width: 390px) {
  .tip-badge {
    padding-inline: 8px;
    font-size: 10px;
  }

  .overlay-card {
    padding-inline: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
