:root {
  --cocoa: #806357;
  --cocoa-dark: #4e3931;
  --ink: #4b3831;
  --grid-empty: #c7bfbc;
  --line: #71574c;
  --sun: #ffbd12;
  --sun-deep: #e99b00;
  --white: #fffdf8;
  --green: #20b914;
  --row-clue: clamp(72px, 22vw, 130px);
  --cell: clamp(34px, calc((100vw - var(--row-clue) - 16px) / 6), 70px);
  --col-clue: clamp(82px, 22vw, 132px);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #342720;
  color: var(--white);
  font-family: "FZLanTingHeiS", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; }

.game-shell {
  position: relative;
  width: min(100vw, 600px);
  height: 100dvh;
  min-height: 620px;
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
  background-color: var(--cocoa);
  background-image: linear-gradient(rgba(128,99,87,.70), rgba(128,99,87,.70)), url("assets/mocha-paper.png");
  background-size: cover, 720px 720px;
  box-shadow: 0 0 60px rgba(0,0,0,.5);
  padding-top: max(18px, env(safe-area-inset-top));
}

.game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle at 50% 44%, transparent 0 36%, rgba(56,35,28,.08) 100%);
  pointer-events: none;
}

.scene {
  position: absolute;
  inset: 0;
  z-index: 40;
  overflow: hidden;
}

.scene.hidden { display: none; }

.cover-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: max(54px, calc(env(safe-area-inset-top) + 34px)) 28px max(56px, calc(env(safe-area-inset-bottom) + 34px));
  background: #563a29;
}

.cover-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(42,25,18,.76) 0%, rgba(42,25,18,.08) 30%, transparent 61%, rgba(42,25,18,.76) 100%);
  pointer-events: none;
}

.cover-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: cover-in 1.2s cubic-bezier(.2,.8,.2,1) both;
}

.cover-copy {
  position: relative;
  z-index: 1;
  width: 100%;
  text-align: center;
  text-shadow: 0 3px 18px rgba(40,22,14,.6);
}

.cover-copy h1 {
  margin: 5px 0 12px;
  font-family: "STSong", "Songti SC", serif;
  font-size: clamp(48px, 13vw, 76px);
  line-height: 1;
  letter-spacing: .12em;
}

.cover-copy p:last-child {
  margin: 0;
  font-size: 15px;
  line-height: 1.8;
  letter-spacing: .12em;
  color: rgba(255,253,248,.82);
}

.cover-kicker {
  margin: 0;
  color: #ffd675;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .34em;
}

.cover-start {
  position: relative;
  z-index: 2;
  width: min(380px, 88%);
  min-height: 58px;
  border: 0;
  color: #503526;
  background: linear-gradient(180deg, #ffd24c, #ffb90f);
  box-shadow: 0 7px 0 #b97908, 0 15px 35px rgba(37,20,13,.35);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: .16em;
}

.cover-start:active { transform: translateY(4px); box-shadow: 0 3px 0 #b97908; }

.level-scene {
  padding: max(46px, calc(env(safe-area-inset-top) + 28px)) 26px max(30px, env(safe-area-inset-bottom));
  background: linear-gradient(rgba(128,99,87,.78), rgba(128,99,87,.78)), url("assets/mocha-paper.png");
  background-size: cover, 640px;
}

.level-heading { position: relative; text-align: center; }
.level-heading p { margin: 0 0 4px; color: #ffd675; font-size: 12px; letter-spacing: .3em; }
.level-heading h1 { margin: 0; font-family: "STSong", "Songti SC", serif; font-size: 38px; letter-spacing: .12em; }
.level-heading span { display: block; margin-top: 8px; color: rgba(255,255,255,.68); font-size: 13px; }

.round-back {
  position: absolute;
  left: 0;
  top: 4px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: var(--white);
  font-family: serif;
  font-size: 38px;
  line-height: 36px;
}

.level-list {
  width: min(460px, 100%);
  margin: clamp(30px, 6vh, 62px) auto 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.level-card {
  position: relative;
  min-height: 142px;
  padding: 22px;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--ink);
  background: #fff9ed;
  box-shadow: 7px 7px 0 rgba(62,39,31,.3);
  animation: card-in .45s both;
  animation-delay: var(--card-delay);
}

.level-card:active { transform: translate(3px,3px); box-shadow: 4px 4px 0 rgba(62,39,31,.3); }
.level-title { font-family: "STSong", "Songti SC", serif; font-size: 28px; font-weight: 800; letter-spacing: .08em; }
.difficulty { margin-top: 9px; padding: 4px 11px; border-radius: 20px; font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.difficulty-简单 { color: #2e7650; background: #dcebdd; }
.difficulty-中等 { color: #97600b; background: #f7e5b9; }
.difficulty-困难 { color: #a34338; background: #f4d4ce; }
.level-status { margin-top: 9px; color: #8c766c; font-size: 12px; }

.level-tip {
  margin: 24px 0 0;
  text-align: center;
  color: rgba(255,255,255,.72);
  font-size: 12px;
}

.ending-scene {
  display: grid;
  place-items: center;
  padding: 32px 26px;
  background: #725548;
}

.ending-rays {
  position: absolute;
  width: 120vmax;
  aspect-ratio: 1;
  background: repeating-conic-gradient(from 0deg, rgba(255,207,92,.2) 0 8deg, transparent 8deg 18deg);
  animation: ray-spin 18s linear infinite;
}

.ending-content { position: relative; z-index: 1; width: min(430px,100%); text-align: center; }
.ending-content h1 { margin: 10px 0 26px; font-family: "STSong", "Songti SC", serif; font-size: 40px; line-height: 1.25; }
.ending-content > p:not(.cover-kicker) { margin: 18px 0 24px; color: #ffe4a0; }
.ending-content .cover-start { width: 100%; }
.ending-replay { margin-top: 16px; border: 0; color: white; background: transparent; text-decoration: underline; text-underline-offset: 5px; }

.ending-gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.ending-tile {
  aspect-ratio: 1;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 1px;
  background: white;
  box-shadow: 4px 4px 0 rgba(58,36,29,.25);
}

.ending-tile span { background: #fff; }
.ending-tile span.on { background: var(--tile-color); }

.topbar {
  position: relative;
  height: 52px;
  margin: 12px 0 0 28px;
  padding-left: 62px;
  display: flex;
  align-items: center;
  border-radius: 30px 0 0 30px;
  background: var(--cocoa-dark);
  box-shadow: inset 0 1px rgba(255,255,255,.06);
}

.menu-button {
  position: absolute;
  left: 0;
  top: 50%;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  transform: translate(-3px,-50%);
  display: grid;
  place-content: center;
  gap: 5px;
  background: var(--white);
  box-shadow: 0 2px 0 rgba(55,38,31,.18);
}

.menu-button span {
  display: block;
  width: 25px;
  height: 4px;
  border-radius: 3px;
  background: var(--ink);
}

.menu-button:active { transform: translate(-3px,-50%) scale(.94); }

.title {
  flex: 1;
  text-align: center;
  font-size: 18px;
  letter-spacing: .04em;
}

.timer {
  width: 72px;
  padding-left: 19px;
  font-size: 18px;
  border-left: 2px solid rgba(255,255,255,.22);
}

.resources { margin-top: 20px; }

.pill {
  height: 34px;
  border-radius: 20px;
  background: rgba(77,55,47,.88);
}

.ticket {
  width: 136px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 18px;
}

.flag-mark {
  position: relative;
  width: 22px;
  height: 22px;
  border: 3px solid white;
  border-radius: 50%;
  background: #2fc9b0;
}

.flag-mark::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 3px;
  width: 2px;
  height: 14px;
  background: white;
}

.flag-mark::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 4px;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 8px solid white;
}

.score-row {
  width: min(468px, calc(100% - 72px));
  height: 32px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 30px 60px 1fr;
  align-items: center;
  border-radius: 20px;
  background: rgba(77,55,47,.86);
  overflow: hidden;
  font-size: 16px;
}

.star-mark {
  width: 25px;
  height: 25px;
  margin-left: 4px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #ffd638;
  background: white;
  font-size: 17px;
}

.score-track {
  height: 17px;
  margin-right: 16px;
  overflow: hidden;
  background: #918b87;
  border: 3px solid #544039;
}

.score-track i {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left;
  background: linear-gradient(90deg,#ffd326,#ffc137);
  transition: transform .25s linear;
}

.puzzle-stage {
  position: absolute;
  inset: 30% 0 auto;
  display: grid;
  place-items: center;
  perspective: 900px;
}

.puzzle-wrap {
  display: grid;
  grid-template-columns: var(--row-clue) calc(var(--cell) * 6);
  grid-template-rows: var(--col-clue) calc(var(--cell) * 6);
  transform-origin: center;
  transition: transform .42s cubic-bezier(.2,.8,.2,1), filter .3s;
}

.corner { grid-area: 1 / 1; }
.column-clues { grid-area: 1 / 2; }
.row-clues { grid-area: 2 / 1; }
.grid { grid-area: 2 / 2; }

.column-clues, .grid {
  display: grid;
  grid-template-columns: repeat(6, var(--cell));
}

.row-clues, .grid {
  display: grid;
  grid-template-rows: repeat(6, var(--cell));
}

.clue {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  color: white;
  background: rgba(72,51,44,.94);
  border: 1px solid var(--line);
  font-size: clamp(12px, 3.3vw, 18px);
  transition: background .22s, transform .22s;
}

.column-clues .clue {
  flex-direction: column;
  padding-bottom: 11px;
}

.row-clues .clue {
  justify-content: flex-end;
  padding-right: 12px;
  align-items: center;
}

.clue.done {
  background: var(--sun);
  color: white;
  transform: scale(.985);
}

.grid {
  touch-action: none;
  outline: 0;
}

.cell {
  position: relative;
  border: 1px solid var(--line);
  background: var(--grid-empty);
  transition: background .08s, transform .13s;
}

.cell.filled { background: var(--ink); }
.cell.painting { transform: scale(.91); }

.cell.touch::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.75);
  transform: translate(-50%,-50%);
  animation: touch-ping .32s ease-out both;
}

.grid.shake { animation: shake .34s ease both; }

.success-check {
  position: absolute;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(.3) rotate(-16deg);
  background: #21b919;
  box-shadow: 0 7px 0 rgba(0,77,0,.25), 0 10px 26px rgba(0,0,0,.3);
  pointer-events: none;
}

.success-check i {
  width: 37px;
  height: 20px;
  border-left: 9px solid white;
  border-bottom: 9px solid white;
  transform: rotate(-45deg) translate(3px,-2px);
}

.success-check.show { animation: check-in .65s cubic-bezier(.2,1.5,.3,1) both; }

.puzzle-stage.reveal::before {
  content: "";
  position: absolute;
  width: min(520px,96vw);
  aspect-ratio: 1;
  background: repeating-conic-gradient(from 0deg, rgba(255,255,255,.16) 0 10deg, transparent 10deg 20deg);
  animation: ray-spin 12s linear infinite;
}

.puzzle-stage.reveal .puzzle-wrap {
  padding: 12px;
  display: block;
  background: white;
  transform: translateY(-2%) scale(.82);
  box-shadow: 0 12px 36px rgba(50,31,24,.25);
}

.puzzle-stage.reveal .corner,
.puzzle-stage.reveal .column-clues,
.puzzle-stage.reveal .row-clues { display: none; }

.puzzle-stage.reveal .grid { position: relative; z-index: 1; }
.puzzle-stage.reveal .cell { border-color: rgba(255,255,255,.56); }
.puzzle-stage.reveal .cell:not(.filled) { background: white; }
.puzzle-stage.reveal .cell.filled { animation: color-tile .55s both; animation-delay: var(--delay); background: var(--tile); }

.result-name {
  position: absolute;
  z-index: 3;
  top: 47%;
  min-width: 110px;
  padding: 8px 18px;
  text-align: center;
  font-size: 24px;
  letter-spacing: .08em;
  background: rgba(25,58,31,.78);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.result-name.show { animation: name-in .45s .65s both; }

.tutorial-layer {
  position: absolute;
  inset: 0;
  z-index: 19;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(48,30,24,.18), transparent 34%, transparent 68%, rgba(48,30,24,.35));
}

.tutorial-layer.hidden { display: none; }

.tutorial-card {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(430px, calc(100% - 36px));
  padding: 22px 24px 18px;
  transform: translateX(-50%);
  text-align: center;
  color: var(--ink);
  background: #fff9ed;
  border: 4px solid var(--sun);
  box-shadow: 9px 9px 0 rgba(62,39,31,.34);
  animation: tutorial-card-in .35s cubic-bezier(.2,1.2,.2,1) both;
  pointer-events: auto;
}

.tutorial-kicker { margin: 0; color: #a96d0b; font-size: 11px; font-weight: 800; letter-spacing: .18em; }
.tutorial-card h2 { margin: 7px 0 8px; font-family: "STSong", "Songti SC", serif; font-size: 26px; }
.tutorial-card > p:not(.tutorial-kicker) { margin: 0 auto 14px; max-width: 330px; font-size: 14px; line-height: 1.65; }

.tutorial-next {
  width: 100%;
  min-height: 46px;
  border: 0;
  color: #56370c;
  background: var(--sun);
  box-shadow: 0 4px 0 #c77d00;
  font-weight: 800;
}

.tutorial-next:disabled { opacity: .65; }
.tutorial-skip { margin-top: 11px; border: 0; color: #8c766c; background: transparent; font-size: 12px; }

.tutorial-layer.guide-mode .tutorial-card {
  bottom: max(8px, env(safe-area-inset-bottom));
  width: min(430px, calc(100% - 18px));
  padding: 8px 14px 6px;
  border-width: 3px;
  box-shadow: 5px 5px 0 rgba(62,39,31,.3);
}

.tutorial-layer.guide-mode .tutorial-kicker { display: none; }
.tutorial-layer.guide-mode .tutorial-card h2 { margin: 0 0 3px; font-size: 18px; }
.tutorial-layer.guide-mode .tutorial-card > p:not(.tutorial-kicker) { margin: 0 auto 3px; max-width: none; font-size: 12px; line-height: 1.35; }
.tutorial-layer.guide-mode .tutorial-skip { margin-top: 0; padding: 2px 0; font-size: 11px; }

.clue.tutorial-focus {
  position: relative;
  z-index: 2;
  outline: 5px solid #fff4b1;
  outline-offset: -5px;
  animation: tutorial-pulse 1s ease-in-out infinite alternate;
}

.cell.tutorial-target {
  z-index: 2;
  outline: 5px solid rgba(255,244,177,.95);
  outline-offset: -5px;
  animation: tutorial-pulse 1s ease-in-out infinite alternate;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  z-index: 8;
  max-width: 80%;
  padding: 10px 18px;
  border-radius: 18px;
  opacity: 0;
  transform: translate(-50%,10px);
  background: rgba(49,34,28,.88);
  font-size: 14px;
  pointer-events: none;
}

.toast.show { animation: toast 1.45s both; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 30px;
  background: rgba(44,29,24,.66);
  backdrop-filter: blur(5px);
  transition: opacity .22s;
}

.overlay.hidden { display: none; }

.panel {
  width: min(380px,100%);
  padding: 30px 28px 26px;
  text-align: center;
  color: var(--ink);
  background: #fff9ed;
  border: 5px solid var(--sun);
  box-shadow: 12px 12px 0 rgba(61,39,30,.28);
  animation: panel-in .35s cubic-bezier(.2,1.2,.2,1) both;
}

.panel h1 { margin: 4px 0 10px; font-size: 30px; }
.panel p { margin: 0 0 22px; line-height: 1.7; }
.eyebrow { color: #b16d00; letter-spacing: .22em; font-size: 12px; }

.panel button {
  width: 100%;
  min-height: 48px;
  margin-top: 9px;
  border: 0;
  font-weight: 700;
}

.primary { color: #fff; background: var(--sun-deep); box-shadow: 0 4px 0 #b66a00; }
.secondary { color: var(--ink); background: #eaded5; }
.text-button { color: #806357; background: transparent; }
.panel button:active { transform: translateY(2px); box-shadow: none; }
.win-panel { border-color: #28b63e; }
.timeout-panel { border-color: #e0664f; }

@keyframes touch-ping { from { opacity: 1; transform: translate(-50%,-50%) scale(.65); } to { opacity: 0; transform: translate(-50%,-50%) scale(1.4); } }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes check-in { 0% { opacity: 0; transform: scale(.3) rotate(-16deg); } 70% { opacity: 1; transform: scale(1.12) rotate(2deg); } 100% { opacity: 1; transform: scale(1); } }
@keyframes ray-spin { to { transform: rotate(360deg); } }
@keyframes color-tile { 0% { transform: scaleY(.15); filter: brightness(.3); } 60% { transform: scaleY(1.08); } 100% { transform: scaleY(1); filter: none; } }
@keyframes name-in { to { opacity: 1; transform: translateY(0); } }
@keyframes toast { 0%,100% { opacity: 0; transform: translate(-50%,10px); } 15%,80% { opacity: 1; transform: translate(-50%,0); } }
@keyframes panel-in { from { opacity: 0; transform: translateY(18px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes cover-in { from { opacity: 0; transform: scale(1.06); } to { opacity: 1; transform: scale(1); } }
@keyframes card-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes tutorial-pulse { from { filter: brightness(1); } to { filter: brightness(1.32); box-shadow: 0 0 22px rgba(255,205,44,.8); } }
@keyframes tutorial-card-in { from { opacity: 0; transform: translate(-50%,18px) scale(.94); } to { opacity: 1; transform: translateX(-50%); } }

@media (max-height: 760px) {
  :root { --col-clue: clamp(62px,14vh,96px); }
  .topbar { margin-top: 4px; }
  .resources { margin-top: 10px; }
  .puzzle-stage { inset: 26% 0 auto; }
  .level-list { margin-top: 22px; gap: 10px; }
  .level-card { min-height: 116px; padding: 14px 8px; }
  .level-title { font-size: 24px; }
  .level-tip { margin-top: 14px; }
  .tutorial-card { width: calc(100% - 12px); padding: 10px 12px 8px; bottom: 7px; }
  .tutorial-kicker { font-size: 10px; }
  .tutorial-card h2 { margin: 2px 0 3px; font-size: 19px; }
  .tutorial-card > p:not(.tutorial-kicker) { margin-bottom: 5px; max-width: none; font-size: 11px; line-height: 1.35; }
  .tutorial-next { min-height: 36px; }
  .tutorial-skip { margin-top: 3px; font-size: 11px; }
}

@media (max-width: 430px) {
  .tutorial-card { width: calc(100% - 12px); padding: 10px 12px 8px; bottom: 18px; }
  .tutorial-kicker { font-size: 10px; }
  .tutorial-card h2 { margin: 2px 0 3px; font-size: 19px; }
  .tutorial-card > p:not(.tutorial-kicker) { margin-bottom: 5px; max-width: none; font-size: 11px; line-height: 1.35; }
  .tutorial-next { min-height: 36px; }
  .tutorial-skip { margin-top: 3px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}
