:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --ink: #18352e;
  --muted: #718078;
  --paper: #fffdf8;
  --jade: #347b64;
  --jade-dark: #1f5c4a;
  --line: rgba(43, 91, 74, 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 4%, rgba(255, 255, 255, 0.9), transparent 26rem),
    radial-gradient(circle at 90% 90%, rgba(99, 157, 132, 0.18), transparent 34rem),
    linear-gradient(145deg, #edf3eb 0%, #dbe8df 45%, #cfded5 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 540px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.eyebrow {
  margin: 0 0 2px;
  color: #638073;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(30px, 7vw, 40px);
  line-height: 1;
  letter-spacing: 0.08em;
}

.level-pill,
.remaining-pill {
  border: 1px solid rgba(42, 96, 76, 0.15);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 8px 24px rgba(39, 75, 61, 0.08);
  backdrop-filter: blur(10px);
}

.level-pill {
  padding: 9px 14px;
  color: #60756b;
  font-size: 13px;
}

.level-pill strong {
  color: var(--jade-dark);
  font-size: 18px;
}

.game-card {
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 28px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow:
    0 24px 70px rgba(38, 72, 59, 0.16),
    inset 0 1px 0 #fff;
}

.status-row {
  min-height: 66px;
  padding: 12px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.status-row > div:first-child {
  display: grid;
  gap: 2px;
}

.status-label {
  color: #7d8a83;
  font-size: 11px;
  letter-spacing: 0.12em;
}

.status-row strong {
  font-size: 17px;
}

.remaining-pill {
  flex: 0 0 auto;
  padding: 7px 11px;
  color: #718078;
  font-size: 12px;
}

.remaining-pill strong {
  color: var(--jade-dark);
  font-variant-numeric: tabular-nums;
}

.canvas-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 720 / 1000;
  overflow: hidden;
  background: #e9f0e9;
  isolation: isolate;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas.is-dragging {
  cursor: grabbing;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 24px;
  z-index: 3;
  max-width: calc(100% - 36px);
  padding: 9px 14px;
  border-radius: 999px;
  color: #fff;
  background: rgba(27, 61, 51, 0.9);
  box-shadow: 0 10px 28px rgba(21, 55, 44, 0.22);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

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

.win-panel {
  position: absolute;
  inset: 0;
  z-index: 4;
  padding: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(240, 247, 241, 0.9);
  backdrop-filter: blur(12px);
  animation: reveal 300ms ease both;
}

.win-panel[hidden] {
  display: none;
}

.win-panel h2 {
  margin: 6px 0 10px;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(30px, 8vw, 44px);
}

.win-panel > p:not(.eyebrow) {
  max-width: 300px;
  color: #65776e;
  font-size: 14px;
  line-height: 1.7;
}

.win-medal {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(159, 112, 26, 0.28);
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, #f8d979, #b67a1b);
  box-shadow: 0 14px 30px rgba(148, 100, 24, 0.24), inset 0 2px 2px rgba(255, 255, 255, 0.7);
  font-size: 38px;
  font-weight: 900;
}

.win-panel button {
  margin-top: 8px;
  padding: 11px 26px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #387b65, #235b4a);
  box-shadow: 0 10px 24px rgba(35, 91, 74, 0.2);
  font-weight: 800;
  cursor: pointer;
}

.control-row {
  min-height: 58px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.control-row p {
  margin-bottom: 0;
  color: #6d7c74;
  font-size: 11px;
  line-height: 1.45;
}

.control-row p span {
  color: var(--jade);
  font-size: 17px;
  vertical-align: -1px;
}

.control-row button {
  flex: 0 0 auto;
  padding: 8px 11px;
  border: 1px solid rgba(47, 105, 83, 0.2);
  border-radius: 12px;
  color: var(--jade-dark);
  background: #f7fbf8;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.control-row button:active,
.win-panel button:active {
  transform: translateY(1px);
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
}

@media (max-height: 760px) and (min-width: 380px) {
  .app-shell {
    width: min(100%, 480px);
    padding-top: 10px;
    gap: 8px;
  }

  .topbar {
    min-height: 42px;
  }

  .topbar .eyebrow {
    display: none;
  }

  h1 {
    font-size: 30px;
  }

  .game-card {
    border-radius: 22px;
  }

  .status-row {
    min-height: 52px;
    padding-block: 7px;
  }

  .control-row {
    min-height: 48px;
    padding-block: 7px;
  }
}

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