:root {
  --brand: #FF8A3D;
  --brand-deep: #EF6D1E;
  --brand-soft: #FFE7D2;
  --ink: #3D2A1C;
  --ink-soft: #6F5542;
  --muted: #A38A76;
  --paper: #FFFBF4;
  --line: #F3DFC9;
  --good: #4CB782;
  --bad: #E25348;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #FFF5E6;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  background:
    radial-gradient(120% 70% at 100% 0%, #FFDFBC 0%, rgba(255, 223, 188, 0) 52%),
    radial-gradient(95% 60% at 0% 4%, #FFF1DC 0%, rgba(255, 241, 220, 0) 56%),
    linear-gradient(180deg, #FFF9EF 0%, #FFEFDA 54%, #FFF7EA 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(203, 139, 86, 0.16) 1px, transparent 1.2px);
  background-size: 19px 19px;
  -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5), transparent 42%);
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5), transparent 42%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom));
}

.game {
  width: 100%;
  max-width: 446px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  animation: rise 0.42s ease both;
}

/* ---------------- board ---------------- */
.board {
  position: relative;
  padding: 7px;
  border-radius: 27px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF6E9 100%);
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    0 22px 42px -20px rgba(181, 101, 42, 0.42),
    0 6px 16px -6px rgba(181, 101, 42, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.scene {
  position: relative;
  overflow: hidden;
  border-radius: 21px;
  background: #F9E8D4;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 0 0 1px rgba(102, 57, 23, 0.07);
  transition: transform 0.14s ease;
}

.scene:active { transform: scale(0.995); }

.scene:focus-visible {
  outline: 3px solid rgba(255, 138, 61, 0.55);
  outline-offset: 2px;
}

.scene img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.scene.shake img { animation: shake 0.42s ease; }

.marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.mark {
  position: absolute;
  width: 54px;
  height: 54px;
  transform: translate(-50%, -50%);
  animation: markIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.mark-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--brand);
  background: rgba(255, 255, 255, 0.16);
  box-shadow:
    0 0 0 4px rgba(255, 138, 61, 0.22),
    0 0 18px rgba(255, 138, 61, 0.5),
    inset 0 0 12px rgba(255, 255, 255, 0.35);
}

.mark-check {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid #FFFDF8;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 7px rgba(196, 89, 18, 0.4);
}

.mark-check .mp-icon {
  width: 12px;
  height: 12px;
  color: #FFFFFF;
}

.wrong-mark {
  position: absolute;
  width: 36px;
  height: 36px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(226, 83, 72, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 6px rgba(226, 83, 72, 0.18);
  animation: wrongOut 0.62s ease-out forwards;
  z-index: 4;
}

.wrong-mark .mp-icon {
  width: 19px;
  height: 19px;
  color: #FFFFFF;
}

.penalty {
  position: absolute;
  transform: translate(-50%, -50%);
  color: #FFFFFF;
  background: rgba(217, 73, 61, 0.95);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 10px rgba(160, 40, 30, 0.3);
  animation: penaltyUp 0.7s ease-out forwards;
  z-index: 5;
}

.seam {
  position: relative;
  height: 31px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.seam::before {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  top: 50%;
  border-top: 1.5px dashed #EFD1AF;
}

.seam-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px 5px;
  border-radius: 999px;
  background: #FFF1DF;
  border: 1px solid #FFDAB7;
  color: #B25B1F;
  font-size: 11.5px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 2px 5px rgba(179, 99, 39, 0.09);
}

.seam-pill b { font-weight: 800; }

.seam-pill .mp-icon {
  width: 14px;
  height: 14px;
  color: #E8792F;
}

/* ---------------- status ---------------- */
.status {
  margin-top: 11px;
  padding: 13px 15px 12px;
  border-radius: 22px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF8ED 100%);
  border: 1px solid #F7E3CE;
  box-shadow:
    0 12px 26px -20px rgba(152, 84, 30, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.status-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.level {
  flex: 1;
  min-width: 0;
}

.eyebrow {
  margin: 0;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.11em;
  color: #B29175;
}

.eyebrow b { color: #C46A28; font-weight: 800; }

.level h2 {
  margin: 3px 0 0;
  font-size: 18px;
  line-height: 1.18;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 88px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #FFF3E2;
  border: 1px solid #FFDFC3;
  color: #BE5D1E;
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  box-shadow: inset 0 1px 0 #FFFFFF;
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.timer .mp-icon { width: 17px; height: 17px; }

.timer.danger {
  color: #D8483D;
  background: #FFEEEA;
  border-color: #FFD1C9;
  animation: timerPulse 1s ease-in-out infinite;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px dashed #F0DCC6;
}

.dots {
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #F8EADA;
  border: 1.5px solid #EBD4B9;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.dot .mp-icon {
  width: 12px;
  height: 12px;
  color: #FFFFFF;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dot.on {
  background: var(--brand);
  border-color: var(--brand);
  box-shadow: 0 3px 8px rgba(255, 138, 61, 0.36);
  animation: dotPop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dot.on .mp-icon { opacity: 1; transform: scale(1); }

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  color: #A08873;
  font-size: 11.5px;
  font-weight: 600;
}

.meta b {
  color: #4E3523;
  font-size: 12.5px;
  font-weight: 800;
}

.meta .sep {
  width: 1px;
  height: 11px;
  background: #E8D2B9;
}

/* ---------------- footer ---------------- */
.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding: 0 4px;
}

.tip {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  color: #AB927D;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.3;
}

.tip .mp-icon {
  width: 14px;
  height: 14px;
  color: #C9AB8E;
}

.reset {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: #AD8A6D;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.reset .mp-icon { width: 15px; height: 15px; }

.reset:active {
  background: #F8E7D4;
  transform: scale(0.95);
}

/* ---------------- result overlay ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  background: rgba(56, 32, 16, 0.54);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
}

.result {
  position: relative;
  width: 100%;
  max-width: 332px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 25px 22px 22px;
  border-radius: 30px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF4E3 100%);
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 30px 70px -22px rgba(54, 24, 4, 0.66);
  text-align: center;
  transform: translateY(18px) scale(0.94);
  transition: transform 0.34s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay.show .result { transform: translateY(0) scale(1); }

.result::before {
  content: "";
  position: absolute;
  top: -74px;
  left: 50%;
  width: 240px;
  height: 170px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 214, 166, 0.9), rgba(255, 214, 166, 0) 70%);
  pointer-events: none;
}

.result-badge {
  position: relative;
  width: 74px;
  height: 74px;
  margin: 0 auto 14px;
  border-radius: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(140deg, #FFB069 0%, #FF7C2E 100%);
  box-shadow:
    0 14px 26px -10px rgba(239, 109, 30, 0.65),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
  transform: rotate(-4deg);
}

.result-badge .mp-icon {
  width: 40px;
  height: 40px;
  color: #FFFFFF;
}

.result-badge.fail {
  background: linear-gradient(140deg, #FF9D8A 0%, #E25348 100%);
  box-shadow:
    0 14px 26px -10px rgba(200, 65, 54, 0.55),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

.result-kicker {
  position: relative;
  margin: 0 0 5px;
  color: #C18B5D;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.result h2 {
  position: relative;
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.result-sub {
  position: relative;
  margin: 8px 0 0;
  color: #967C68;
  font-size: 13px;
  line-height: 1.55;
}

.stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 17px 0 2px;
  min-height: 44px;
}

.star {
  width: 39px;
  height: 39px;
  color: #F5C44B;
  opacity: 0.2;
  transform: scale(0.7);
  filter: drop-shadow(0 5px 7px rgba(206, 146, 22, 0.28));
}

.star.on { animation: starPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both; }

.result-stats {
  display: flex;
  gap: 8px;
  margin: 16px 0 18px;
}

.result-stats div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 8px;
  border-radius: 14px;
  background: #FFF8EC;
  border: 1px solid #F1DBC2;
}

.result-stats span {
  font-size: 10px;
  font-weight: 700;
  color: #A98D77;
}

.result-stats b {
  font-size: 15px;
  font-weight: 800;
  color: #4A3120;
}

.primary {
  position: relative;
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  border: 0;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: linear-gradient(180deg, #FF9E58 0%, #FF7A2E 100%);
  color: #FFFFFF;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow:
    0 11px 20px -8px rgba(230, 100, 20, 0.68),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary:active {
  transform: scale(0.97);
  box-shadow:
    0 5px 11px -6px rgba(230, 100, 20, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
}

.primary .mp-icon {
  width: 20px;
  height: 20px;
  color: #FFFFFF;
}

/* ---------------- motion ---------------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes markIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.35); }
  70% { opacity: 1; }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes dotPop {
  0% { transform: scale(0.7); }
  60% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

@keyframes starPop {
  0% { opacity: 0; transform: scale(0.3) rotate(-18deg); }
  65% { opacity: 1; transform: scale(1.16) rotate(4deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

@keyframes wrongOut {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.15); }
}

@keyframes penaltyUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  25% { opacity: 1; transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(0.95); }
}

@keyframes timerPulse {
  0%, 100% { box-shadow: inset 0 1px 0 #FFFFFF, 0 0 0 0 rgba(226, 83, 72, 0.18); }
  50% { box-shadow: inset 0 1px 0 #FFFFFF, 0 0 0 5px rgba(226, 83, 72, 0); }
}

@media (max-height: 720px) {
  .app { padding-top: calc(5px + env(safe-area-inset-top)); }
  .status { padding: 11px 14px 10px; }
  .status-row { margin-top: 9px; padding-top: 9px; }
  .level h2 { font-size: 17px; }
}

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