:root {
  color-scheme: light;
  --ink: #24352e;
  --muted: #66766e;
  --paper: #fffdf5;
  --cream: #f8efd9;
  --leaf: #4a7c59;
  --lime: #bed96f;
  --red: #e7573e;
  --orange: #f2a93b;
  --food-size: clamp(49px, 14.5vw, 74px);
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overscroll-behavior: none; background: #f4ead1; color: var(--ink); -webkit-tap-highlight-color: transparent; }
body {
  min-height: 100svh;
  background:
    linear-gradient(90deg, rgba(132,96,50,.045) 1px, transparent 1px),
    linear-gradient(rgba(132,96,50,.045) 1px, transparent 1px),
    #f4ead1;
  background-size: 22px 22px;
}
button { font: inherit; }
button:focus-visible { outline: 3px solid #167b8d; outline-offset: 2px; }

.app { width: min(100%, 760px); min-height: 100svh; margin: 0 auto; padding: env(safe-area-inset-top) 10px calc(env(safe-area-inset-bottom) + 12px); }
.topbar { height: 66px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; min-width: 0; }
.brand img { width: 45px; height: 45px; flex: 0 0 auto; object-fit: contain; }
.brand div { display: flex; flex-direction: column; line-height: 1; }
.brand span { font-size: 19px; font-weight: 950; white-space: nowrap; }
.brand small { margin-top: 5px; color: var(--muted); font-size: 10px; font-weight: 700; white-space: nowrap; }
.level-pill { height: 36px; min-width: 76px; padding: 0 12px; display: flex; align-items: baseline; justify-content: center; gap: 3px; border: 2px solid var(--ink); border-radius: 18px; background: var(--paper); box-shadow: 0 3px 0 var(--ink); font-size: 12px; font-weight: 850; }
.level-pill strong { color: var(--red); font-size: 22px; }
.header-actions { display: flex; justify-content: flex-end; gap: 7px; }
.icon-button { width: 37px; height: 37px; padding: 0; border: 2px solid var(--ink); border-radius: 50%; background: var(--paper); color: var(--ink); box-shadow: 0 2px 0 var(--ink); font-weight: 950; cursor: pointer; }
.icon-button:active { transform: translateY(2px); box-shadow: none; }
.sound-off { display: none; }
.sound-muted .sound-on { display: none; }
.sound-muted .sound-off { display: inline; }

.game { display: flex; flex-direction: column; gap: 8px; }
.game-status { display: grid; grid-template-columns: minmax(98px, 1fr) minmax(100px, 2fr) auto; align-items: center; gap: 9px; min-height: 42px; }
.status-copy, .score { display: flex; flex-direction: column; }
.status-copy span, .score span { color: var(--muted); font-size: 10px; font-weight: 750; }
.status-copy strong { margin-top: 2px; font-size: 13px; }
.score { text-align: right; }
.score strong { color: var(--red); font-size: 20px; font-variant-numeric: tabular-nums; }
.progress-track { height: 9px; overflow: hidden; border: 2px solid var(--ink); border-radius: 5px; background: #fff; }
.progress-track i { display: block; width: 0; height: 100%; background: var(--lime); transition: width .3s ease; }

.kitchen-stage {
  position: relative;
  isolation: isolate;
  width: 100%;
  aspect-ratio: 1 / 1.03;
  max-height: min(61svh, 620px);
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #a7c9ba;
  box-shadow: 0 6px 0 rgba(36,53,46,.24);
  touch-action: pan-x;
  user-select: none;
}
.counter-pattern { position: absolute; z-index: -2; inset: 0; background: linear-gradient(145deg, transparent 0 54%, rgba(255,255,255,.19) 54% 57%, transparent 57%), repeating-linear-gradient(90deg, rgba(255,255,255,.13) 0 2px, transparent 2px 44px); }
.kitchen-stage::before { content: ""; position: absolute; z-index: -1; left: -4%; right: -4%; bottom: -7%; height: 29%; border-top: 3px solid var(--ink); background: #d6a765; transform: rotate(-1deg); }
.kitchen-stage::after { content: ""; position: absolute; z-index: -1; left: 8%; right: 8%; bottom: 11%; height: 13%; border-radius: 50%; background: rgba(47,49,44,.24); filter: blur(5px); }
.steam { position: absolute; z-index: 1; top: 4%; width: 23px; height: 62px; border-left: 5px solid rgba(255,255,255,.6); border-radius: 50%; opacity: .8; animation: steam 2.2s ease-in-out infinite; pointer-events: none; }
.steam::after { content: ""; position: absolute; left: 5px; top: 22px; width: 19px; height: 39px; border-left: 4px solid rgba(255,255,255,.55); border-radius: 50%; }
.steam-one { left: 25%; }
.steam-two { right: 26%; animation-delay: -.9s; transform: scale(.8); }

.wok-wrap { position: absolute; z-index: 2; left: 50%; top: 43%; width: min(91%, 610px); aspect-ratio: 1 / .77; transform: translate(-50%, -50%); transform-origin: 50% 78%; transition: transform .12s ease; }
.wok-wrap.tossing { animation: wok-toss .62s cubic-bezier(.35,.02,.25,1); }
.wok { position: absolute; inset: 0 8% 0 0; border: 4px solid #1d2925; border-radius: 49% 49% 46% 46% / 37% 37% 61% 61%; background: linear-gradient(145deg, #4b5652, #141d1a 58%, #31413b); box-shadow: inset 0 0 0 6px #6f7d76, inset 0 12px 20px rgba(255,255,255,.18), 0 10px 0 #141d1a, 0 20px 25px rgba(29,41,37,.34); overflow: hidden; }
.wok-inner { position: absolute; inset: 6% 5% 12%; overflow: hidden; border: 3px solid #121b18; border-radius: 49% 49% 46% 46% / 39% 39% 60% 60%; background: radial-gradient(ellipse at 45% 38%, #83714a 0 8%, #574e38 28%, #222b27 70%); box-shadow: inset 0 9px 18px rgba(0,0,0,.55); }
.oil-shine { position: absolute; inset: 7% 10% 12%; border-radius: 50%; background: radial-gradient(ellipse at 36% 35%, rgba(255,220,104,.22), transparent 46%); pointer-events: none; }
.wok-handle { position: absolute; z-index: -1; right: -1%; top: 39%; width: 26%; height: 18%; border: 4px solid #1d2925; border-radius: 0 22px 22px 0; background: linear-gradient(#4c5954, #1a2521); transform: rotate(7deg); box-shadow: 0 7px 0 #141d1a; }
.wok-handle i { position: absolute; right: 9%; top: 50%; width: 25%; height: 8px; border-radius: 5px; background: #9aa69f; transform: translateY(-50%); }
.food-pile { position: absolute; inset: 2% 2% 5%; }
.food-piece { --x: 50%; --y: 50%; --rot: 0deg; --scale: 1; position: absolute; z-index: 1; left: var(--x); top: var(--y); width: var(--food-size); aspect-ratio: 1; padding: 0; border: 0; border-radius: 50%; background: transparent; transform: translate(-50%,-50%) rotate(var(--rot)) scale(var(--scale)); clip-path: circle(48% at 50% 50%); cursor: pointer; touch-action: none; filter: drop-shadow(0 5px 3px rgba(0,0,0,.36)); transition: left .28s ease, top .28s ease, transform .28s ease, opacity .18s ease; }
.food-piece::before { content: ""; position: absolute; inset: 7%; border-radius: 50%; background: radial-gradient(circle at 38% 30%, rgba(255,255,255,.32), rgba(255,255,255,.07) 46%, rgba(0,0,0,.08)); }
.food-piece:active { filter: brightness(1.12) drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.food-icon { position: relative; z-index: 1; display: grid; place-items: center; width: 100%; height: 100%; font-size: calc(var(--food-size) * .78); line-height: 1; }
.food-piece.pick-out { opacity: 0; transform: translate(-50%,-50%) rotate(var(--rot)) scale(.45); pointer-events: none; }
.food-piece.tossing .food-icon { --drift: 0px; --lift: -80px; --spin: 90deg; animation: food-toss .58s cubic-bezier(.25,.05,.2,1) both; animation-delay: var(--delay, 0ms); }
.food-piece.hint .food-icon { animation: food-hint .8s ease 2; }

.toss-button { position: absolute; z-index: 20; left: 50%; bottom: 4.5%; height: 42px; min-width: 130px; padding: 0 18px; display: flex; align-items: center; justify-content: center; gap: 8px; transform: translateX(-50%); border: 2px solid var(--ink); border-radius: 7px; background: var(--orange); color: var(--ink); box-shadow: 0 4px 0 var(--ink); cursor: pointer; touch-action: manipulation; }
.toss-button:active:not(:disabled) { transform: translate(-50%,3px); box-shadow: 0 1px 0 var(--ink); }
.toss-button:disabled { opacity: .55; }
.toss-button strong { font-size: 15px; }
.toss-pan { font-size: 20px; }
.toss-arrows { font-size: 15px; line-height: 1; animation: arrows 1s ease infinite; }
.board-message { position: absolute; z-index: 30; left: 50%; top: 7%; transform: translate(-50%,-8px) scale(.92); padding: 7px 13px; border: 2px solid var(--ink); border-radius: 18px; background: var(--paper); box-shadow: 0 3px 0 rgba(36,53,46,.3); font-size: 12px; font-weight: 900; opacity: 0; pointer-events: none; transition: .2s ease; white-space: nowrap; }
.board-message.show { opacity: 1; transform: translate(-50%,0) scale(1); }

.powerups { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; }
.power-button { position: relative; height: 43px; padding: 0 9px; display: flex; align-items: center; justify-content: center; gap: 6px; border: 2px solid var(--ink); border-radius: 7px; background: var(--paper); color: var(--ink); box-shadow: 0 3px 0 var(--ink); font-weight: 900; cursor: pointer; }
.power-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.power-button:disabled { opacity: .37; filter: grayscale(1); cursor: not-allowed; }
.power-icon { font-size: 22px; line-height: 1; }
.move-icon { color: var(--red); }
.power-label { font-size: 13px; }
.power-count { position: absolute; right: 4px; top: 3px; width: 17px; height: 17px; border-radius: 50%; background: var(--red); color: #fff; font-size: 10px; line-height: 17px; }

.tray-section { padding-top: 1px; }
.tray-heading { height: 27px; display: flex; align-items: center; justify-content: space-between; }
.tray-heading span { font-size: 13px; font-weight: 950; }
.tray-heading small { color: var(--muted); font-size: 10px; }
.tray { --tray-gap: 4px; min-height: 57px; padding: 5px; display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); gap: var(--tray-gap); border: 3px solid var(--ink); border-radius: 8px; background: #c88c4e; box-shadow: inset 0 5px 0 rgba(83,43,14,.18), 0 5px 0 rgba(36,53,46,.2); }
.tray-slot { position: relative; min-width: 0; aspect-ratio: 1; display: grid; place-items: center; border: 1.5px dashed rgba(74,38,14,.42); border-radius: 5px; background: rgba(255,255,255,.3); }
.tray-item { position: absolute; inset: 1px; display: grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 50%; background: var(--paper); box-shadow: 0 2px 0 var(--ink); font-size: clamp(22px,7vw,39px); animation: tray-in .22s cubic-bezier(.2,.9,.3,1.25); }
.tray-item.matching { animation: match-out .3s ease forwards; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 22px); max-width: calc(100% - 38px); transform: translate(-50%,10px); padding: 9px 15px; border-radius: 6px; background: var(--ink); color: #fff; opacity: 0; pointer-events: none; font-size: 13px; font-weight: 800; transition: .2s ease; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.modal-backdrop { position: fixed; z-index: 200; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(22,35,30,.72); backdrop-filter: blur(5px); transition: opacity .2s ease; }
.modal-backdrop.hidden { opacity: 0; pointer-events: none; }
.modal { width: min(100%,390px); padding: 22px; border: 3px solid var(--ink); border-radius: 8px; background: var(--paper); box-shadow: 0 10px 0 rgba(13,45,34,.4); text-align: center; transition: transform .25s ease; }
.hidden .modal { transform: translateY(16px) scale(.96); }
.modal-art { height: 110px; margin-top: -64px; pointer-events: none; }
.modal-art img { width: 128px; height: 118px; object-fit: contain; }
.modal-kicker { margin: 8px 0 3px; color: var(--red); font-size: 12px; font-weight: 900; }
.modal h1 { margin: 0; font-size: 28px; letter-spacing: 0; }
.modal-copy { max-width: 300px; margin: 9px auto 17px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.modal-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 18px; }
.modal-stats.hidden { display: none; }
.modal-stats div { padding: 10px; border: 1px solid #ced8d1; border-radius: 6px; background: #f3f5ee; }
.modal-stats strong { display: block; color: var(--red); font-size: 22px; }
.modal-stats span { color: var(--muted); font-size: 10px; }
.modal-actions { display: grid; gap: 9px; }
.primary-button,.secondary-button { min-height: 46px; border: 2px solid var(--ink); border-radius: 6px; font-weight: 950; cursor: pointer; }
.primary-button { background: var(--lime); color: var(--ink); box-shadow: 0 3px 0 var(--ink); }
.secondary-button { background: transparent; color: var(--muted); }
.primary-button:active,.secondary-button:active { transform: translateY(2px); }

@keyframes steam { 0% { opacity: 0; transform: translateY(18px) scale(.75); } 45% { opacity: .8; } 100% { opacity: 0; transform: translateY(-22px) scale(1.12); } }
@keyframes wok-toss { 0%,100% { transform: translate(-50%,-50%) rotate(0); } 22% { transform: translate(-52%,-55%) rotate(-6deg); } 48% { transform: translate(-49%,-49%) rotate(4deg); } 70% { transform: translate(-50%,-52%) rotate(-2deg); } }
@keyframes food-toss { 0% { transform: translate(0,0) rotate(0) scale(1); } 42% { transform: translate(var(--drift),var(--lift)) rotate(var(--spin)) scale(1.1); } 100% { transform: translate(0,0) rotate(var(--spin)) scale(1); } }
@keyframes food-hint { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-10px) scale(1.12); } }
@keyframes arrows { 0%,100% { transform: translateY(2px); opacity: .55; } 50% { transform: translateY(-2px); opacity: 1; } }
@keyframes tray-in { from { opacity: 0; transform: scale(.55) translateY(-18px); } }
@keyframes match-out { to { opacity: 0; transform: scale(.3) rotate(15deg); } }

@media (min-width: 680px) {
  :root { --food-size: 70px; }
  .app { padding-left: 18px; padding-right: 18px; }
  .kitchen-stage { aspect-ratio: 1.28 / 1; }
  .wok-wrap { width: min(80%,610px); top: 44%; }
  .tray { min-height: 82px; }
  .tray-item { font-size: 38px; }
}

@media (max-width: 420px) {
  .app { padding-left: 8px; padding-right: 8px; }
  .topbar { height: 59px; }
  .brand img { width: 39px; height: 39px; }
  .brand span { font-size: 17px; }
  .brand small { display: none; }
  .icon-button { width: 34px; height: 34px; }
  .level-pill { min-width: 68px; padding: 0 9px; }
  .game-status { min-height: 38px; }
  .kitchen-stage { aspect-ratio: 1 / 1.01; }
  .power-button { height: 40px; }
  .tray-heading small { font-size: 9px; }
}

@media (max-height: 720px) and (orientation: portrait) {
  :root { --food-size: clamp(44px,12.8vw,50px); }
  .topbar { height: 52px; }
  .game { gap: 6px; }
  .game-status { min-height: 34px; }
  .kitchen-stage { max-height: 49svh; aspect-ratio: 1.1 / 1; }
  .wok-wrap { width: 86%; top: 42%; }
  .toss-button { height: 36px; bottom: 3.5%; }
  .power-button { height: 37px; }
  .tray-heading { height: 23px; }
  .tray { min-height: 48px; }
}

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