:root {
  color-scheme: light;
  --orange: #f47b20;
  --orange-dark: #d85e0a;
  --ink: #171717;
  --muted: #77736f;
  --paper: #f5f4f2;
  --line: #e1ddd8;
  --blue: #063b70;
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { background: #dedbd7; }
body { margin: 0; color: var(--ink); background: #dedbd7; }
button { font: inherit; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #0b74c9; outline-offset: 3px; }
[hidden] { display: none !important; }
.modal-open { overflow: hidden; }

.game-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 0 40px rgba(38, 32, 27, .16);
}

.topbar {
  min-height: 74px;
  padding: max(18px, env(safe-area-inset-top)) 22px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  border: 0;
  padding: 0;
  color: #ed7100;
  background: transparent;
  font: italic 900 clamp(25px, 7vw, 38px)/1 Arial, sans-serif;
  letter-spacing: -1.5px;
  cursor: pointer;
}
.brand:focus-visible { outline: 2px solid rgba(244, 123, 32, .42); outline-offset: 5px; border-radius: 4px; }
.top-actions { display: flex; gap: 10px; }
.round-action {
  width: 48px;
  height: 48px;
  border: 1.5px solid var(--orange);
  border-radius: 50%;
  color: var(--orange-dark);
  background: #fff;
  font-size: 12px;
  font-weight: 800;
}

.task-copy {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 14px;
  padding: 18px 22px 10px;
}
.eyebrow { margin: 0 0 7px; color: var(--orange-dark); font-size: 11px; font-weight: 900; letter-spacing: .14em; }
.task-copy h1 { margin: 0; max-width: 350px; font-size: clamp(24px, 6.7vw, 34px); line-height: 1.28; letter-spacing: -.04em; }
.task-copy > div > p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.timer {
  width: 74px;
  height: 74px;
  flex: 0 0 auto;
  border-radius: 22px 0 0 22px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  padding-top: 15px;
  color: #fff;
  background: var(--orange);
  box-shadow: 0 9px 22px rgba(244, 123, 32, .26);
}
.timer strong { font: 900 35px/1 Arial, sans-serif; }
.timer span { margin-left: 2px; font-size: 11px; font-weight: 700; }
.timer.is-urgent { background: #d83127; animation: urgentPulse .8s ease-in-out infinite alternate; }

.progress-panel { padding: 10px 22px 2px; }
.progress-copy { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 700; }
.progress-copy strong { color: var(--ink); }
.progress-copy b { color: var(--orange-dark); font-size: 17px; }
.progress-track { height: 5px; margin-top: 7px; overflow: hidden; border-radius: 99px; background: #dedbd7; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--orange); transition: width .35s ease; }

.cabinet-board { position: relative; width: 100%; aspect-ratio: 943 / 1677; margin-top: 2px; }
.cabinet-background { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cabinet-slots { position: absolute; inset: 0; }
.cabinet-slot {
  position: absolute;
  width: 18.7%;
  height: 8.25%;
  overflow: hidden;
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 12px;
  color: var(--ink);
  background: transparent;
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.cabinet-slot.is-active { border-color: var(--orange); box-shadow: 0 0 0 5px rgba(244, 123, 32, .17); animation: slotPulse 1s ease-in-out infinite alternate; }
.cabinet-slot.is-drop-hover { border-color: #28a465; background: rgba(255, 255, 255, .92); box-shadow: 0 0 0 7px rgba(40, 164, 101, .24); transform: scale(1.08); animation: none; }
.cabinet-slot.is-complete { border-color: #28a465; background: rgba(255, 255, 255, .93); }
.cabinet-slot img { width: 100%; height: calc(100% - 17px); display: block; object-fit: contain; border-radius: 8px; background: #fff; }
.cabinet-slot span { display: block; height: 17px; overflow: hidden; color: #2f2d2b; font-size: 8px; font-weight: 800; line-height: 17px; white-space: nowrap; text-overflow: ellipsis; }
.slot-1 { left: 26.8%; top: 22.1%; }
.slot-2 { left: 57.3%; top: 29.1%; }
.slot-3 { left: 26.8%; top: 36.3%; }
.slot-4 { left: 57.3%; top: 43.4%; }
.slot-5 { left: 26.8%; top: 50.2%; }
.slot-6 { left: 57.3%; top: 57.4%; }
.slot-7 { left: 26.8%; top: 64.3%; }

.product-dock {
  position: relative;
  z-index: 2;
  margin-top: -66px;
  padding: 22px 0 calc(26px + env(safe-area-inset-bottom));
  border: 1.5px solid var(--orange);
  border-width: 1.5px 0 0;
  border-radius: 28px 28px 0 0;
  background: #fff;
  box-shadow: 0 -16px 34px rgba(77, 54, 35, .12);
}
.dock-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 0 22px 14px; }
.dock-heading h2 { margin: 0; font-size: 23px; }
.dock-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.dock-actions { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.hint-button, .shuffle-button { min-height: 44px; border: 0; padding: 8px 10px; border-radius: 10px; font-size: 11px; font-weight: 800; }
.hint-button { color: #fff; background: var(--orange); box-shadow: 0 5px 12px rgba(244, 123, 32, .22); }
.hint-button:disabled { color: #aaa39c; background: #ece9e5; box-shadow: none; }
.shuffle-button { border: 0; padding: 8px 10px; color: var(--orange-dark); background: #fff0e5; border-radius: 10px; font-size: 11px; font-weight: 800; }
.product-tray { display: flex; gap: 12px; overflow-x: auto; padding: 0 22px 12px; scrollbar-width: none; }
.product-tray::-webkit-scrollbar { display: none; }
.product-card {
  width: 148px;
  min-width: 148px;
  min-height: 166px;
  padding: 8px 8px 11px;
  overflow: hidden;
  border: 2px solid var(--orange);
  border-radius: 20px;
  color: #fff;
  background: var(--orange);
  box-shadow: 0 10px 20px rgba(221, 96, 14, .2);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}
.product-card:active { cursor: grabbing; }
.product-card.is-dragging { opacity: .45; }
.product-card img { pointer-events: none; -webkit-user-drag: none; }
.product-drag-ghost {
  position: fixed;
  z-index: 80;
  margin: 0;
  pointer-events: none;
  opacity: .94;
  transform: scale(.88) rotate(-2deg);
  transform-origin: center;
  box-shadow: 0 16px 30px rgba(108, 52, 12, .3);
}
body.is-product-dragging { user-select: none; }
.product-card.is-wrong { animation: wrongShake .35s ease; }
.product-card.is-hinted { border-color: #ff3e4d; box-shadow: 0 0 0 4px rgba(255, 62, 77, .2), 0 10px 20px rgba(221, 96, 14, .2); animation: hintPulse .75s ease-in-out 3 alternate; }
.product-image { height: 113px; display: block; padding: 6px; border-radius: 13px; background: #fff; }
.product-image img { width: 100%; height: 100%; object-fit: contain; }
.product-card strong { display: block; margin-top: 9px; overflow: hidden; font-size: 12px; line-height: 1.3; white-space: nowrap; text-overflow: ellipsis; }

.overlay { position: fixed; z-index: 50; inset: 0; display: flex; align-items: flex-end; justify-content: center; }
.overlay-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(18, 15, 13, .68); }
.sheet, .claw-sheet {
  position: relative;
  width: min(100%, 520px);
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 30px 24px calc(28px + env(safe-area-inset-bottom));
  border-radius: 30px 30px 0 0;
  background: #fff;
  box-shadow: 0 -22px 60px rgba(0, 0, 0, .22);
  animation: sheetIn .32s ease both;
}
.sheet h2, .claw-sheet h2 { margin: 0; font-size: 29px; line-height: 1.16; }
.sheet ol { list-style: none; margin: 24px 0; padding: 0; display: grid; gap: 18px; }
.sheet li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; color: #514d49; font-size: 14px; line-height: 1.6; }
.sheet li b { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--orange); }
.primary-button { width: 100%; min-height: 54px; border: 0; border-radius: 15px; color: #fff; background: var(--orange); font-weight: 900; }
.compact-sheet { text-align: center; }
.compact-sheet > p:not(.eyebrow) { color: var(--muted); }

.claw-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.unlocked { padding: 8px 10px; border-radius: 99px; color: var(--orange-dark); background: #fff0e5; font-size: 11px; font-weight: 900; }
.unlocked b { font-size: 18px; }
.machine-frame { position: relative; margin: 16px auto 10px; border: 2px solid var(--orange); border-radius: 24px; background: #f8f8f6; }
.real-machine { width: min(100%, 430px); max-height: 54dvh; aspect-ratio: 1122 / 1402; overflow: hidden; touch-action: none; }
.machine-background { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: cover; }
.machine-prize { position: absolute; z-index: 2; width: 17.5%; height: auto; filter: drop-shadow(0 5px 5px rgba(116, 56, 15, .24)); transition: opacity .2s, transform .45s; }
.machine-prize.is-caught { opacity: 0; transform: scale(.7); }
.prize-value { left: 23.2%; top: 49.7%; }
.prize-speed { left: 15.5%; top: 61.7%; }
.prize-quality { left: 31.3%; top: 61.7%; }
.claw-unit { position: absolute; z-index: 4; left: 50%; top: -10%; width: 25%; aspect-ratio: 887 / 1774; transform: translateX(-50%); transition: left .85s cubic-bezier(.22,.74,.24,1), top .9s cubic-bezier(.35,.05,.2,1); will-change: left, top; }
.claw-unit.is-free { transition: none; }
.claw-sprite { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: contain; filter: drop-shadow(0 5px 4px rgba(66, 34, 14, .28)); }
.carried-prize { position: absolute; z-index: -1; left: 50%; top: 68%; width: 58%; height: auto; transform: translateX(-50%); filter: drop-shadow(0 5px 5px rgba(72, 38, 14, .3)); }
.position-slider-label { display: block; color: var(--muted); text-align: center; font-size: 11px; font-weight: 700; }
.position-slider { width: 100%; height: 30px; margin: 2px 0 0; accent-color: var(--orange); cursor: ew-resize; }
.position-slider:disabled { opacity: .48; }
.claw-tip { margin: 12px 0; color: var(--muted); text-align: center; font-size: 13px; }
.claw-controls { display: grid; grid-template-columns: 1fr 1.45fr 1fr; gap: 9px; }
.claw-controls button { min-height: 50px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: #f5f4f2; font-weight: 800; touch-action: none; user-select: none; }
.claw-controls .grab-button { border-color: var(--orange); color: #fff; background: var(--orange); }
.claw-controls button:disabled { opacity: .6; }
.text-button { width: 100%; margin-top: 12px; border: 0; color: var(--muted); background: transparent; font-size: 12px; }
.result-sheet { text-align: center; }
.result-sheet img { width: min(58%, 250px); max-height: 35dvh; display: block; margin: -6px auto 14px; object-fit: contain; }
.result-sheet > p:not(.eyebrow) { color: var(--muted); }
.result-sheet small { display: block; margin-top: 14px; color: #a09b96; }

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  max-width: min(88vw, 430px);
  padding: 12px 17px;
  border-radius: 13px;
  color: #fff;
  background: #252321;
  box-shadow: 0 10px 28px rgba(0,0,0,.23);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transform: translate(-50%, 20px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast[data-type="success"] { background: #168754; }
.toast[data-type="error"] { background: #c6372d; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes slotPulse { to { box-shadow: 0 0 0 8px rgba(244, 123, 32, .24); } }
@keyframes urgentPulse { to { transform: scale(1.05); } }
@keyframes wrongShake { 25% { transform: translateX(-6px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
@keyframes hintPulse { to { transform: translateY(-5px); } }
@keyframes sheetIn { from { transform: translateY(22px); opacity: 0; } }

@media (min-width: 800px) {
  body { padding: 26px 0; }
  .game-shell { border-radius: 28px; }
  .product-dock { border-radius: 28px; }
}

@media (max-width: 359px) {
  .topbar { min-height: 68px; padding-right: 16px; padding-left: 16px; }
  .brand { font-size: 23px; letter-spacing: -1px; }
  .top-actions { gap: 7px; }
  .round-action { width: 48px; height: 48px; }

  .task-copy {
    grid-template-columns: minmax(0, 1fr) 62px;
    gap: 8px;
    padding-right: 16px;
    padding-left: 16px;
  }
  .task-copy h1 { font-size: 22px; line-height: 1.24; }
  .task-copy > div > p:last-child { font-size: 12px; }
  .timer { width: 62px; height: 62px; padding-top: 13px; border-radius: 18px 0 0 18px; }
  .timer strong { font-size: 30px; }
  .progress-panel { padding-right: 16px; padding-left: 16px; }

  .dock-heading { gap: 8px; padding-right: 16px; padding-left: 16px; }
  .dock-heading h2 { font-size: 21px; }
  .dock-heading p { font-size: 12px; }
  .dock-actions { gap: 5px; }
  .hint-button, .shuffle-button { padding: 8px; }
  .product-tray { gap: 10px; padding-right: 16px; padding-left: 16px; }
  .product-card { width: 136px; min-width: 136px; min-height: 156px; }
  .product-image { height: 104px; }
}

@media (max-height: 650px) and (orientation: portrait) {
  .claw-sheet {
    max-height: 100vh;
    max-height: 100dvh;
    padding: 18px 18px calc(16px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
  }
  .claw-sheet h2 { font-size: 25px; }
  .real-machine { width: auto; height: 44vh; height: 44dvh; max-width: 100%; max-height: none; margin: 10px auto 6px; }
  .claw-tip { margin: 7px 0; font-size: 12px; }
  .claw-controls { gap: 7px; }
  .claw-controls button { min-height: 46px; font-size: 13px; }
  .text-button { margin-top: 7px; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .overlay { align-items: center; }
  .claw-sheet {
    width: min(94vw, 760px);
    max-height: 100vh;
    max-height: 100dvh;
    padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    display: grid;
    grid-template-columns: minmax(220px, .88fr) minmax(280px, 1.12fr);
    grid-template-rows: auto auto auto auto auto auto;
    column-gap: 20px;
    align-items: center;
    border-radius: 24px;
  }
  .claw-heading { grid-column: 2; grid-row: 1; align-self: end; }
  .claw-sheet h2 { font-size: 25px; }
  .real-machine {
    grid-column: 1;
    grid-row: 1 / 7;
    width: auto;
    height: calc(100vh - 28px);
    height: calc(100dvh - 28px);
    max-width: 100%;
    max-height: 430px;
    margin: 0 auto;
  }
  .position-slider-label { grid-column: 2; grid-row: 2; margin-top: 4px; }
  .position-slider { grid-column: 2; grid-row: 3; }
  .claw-tip { grid-column: 2; grid-row: 4; margin: 5px 0 8px; font-size: 12px; }
  .claw-controls { grid-column: 2; grid-row: 5; width: 100%; gap: 7px; }
  .claw-controls button { min-height: 46px; font-size: 13px; }
  .text-button { grid-column: 2; grid-row: 6; margin-top: 5px; }
}

@media (max-width: 600px) and (orientation: portrait) {
  .game-shell {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .topbar {
    min-height: 0;
    flex: 0 0 auto;
    padding: max(8px, env(safe-area-inset-top)) 16px 4px;
  }
  .brand { font-size: 22px; letter-spacing: -1px; }
  .top-actions { gap: 6px; }
  .round-action { width: 44px; height: 44px; font-size: 11px; }

  .task-copy {
    flex: 0 0 auto;
    grid-template-columns: minmax(0, 1fr) 52px;
    align-items: center;
    gap: 8px;
    padding: 5px 16px 3px;
  }
  .task-copy .eyebrow,
  .task-copy > div > p:last-child { display: none; }
  .task-copy h1 { max-width: none; font-size: clamp(18px, 5.2vw, 22px); line-height: 1.18; letter-spacing: -.035em; }
  .timer { width: 52px; height: 52px; padding-top: 11px; border-radius: 16px 0 0 16px; }
  .timer strong { font-size: 28px; }
  .timer span { font-size: 9px; }

  .progress-panel { flex: 0 0 auto; padding: 3px 16px 0; }
  .progress-copy { font-size: 10px; }
  .progress-copy b { font-size: 14px; }
  .progress-track { height: 4px; margin-top: 3px; }

  .cabinet-board {
    width: auto;
    max-width: 100%;
    min-height: 0;
    flex: 1 1 0;
    align-self: center;
    margin-top: 0;
  }

  .product-dock {
    flex: 0 0 auto;
    margin-top: -32px;
    padding: 10px 0 calc(8px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -10px 24px rgba(77, 54, 35, .12);
  }
  .dock-heading { align-items: center; gap: 7px; padding: 0 16px 7px; }
  .dock-heading h2 { font-size: 18px; line-height: 1.1; }
  .dock-heading p { margin-top: 2px; font-size: 10px; line-height: 1.25; }
  .dock-actions { gap: 5px; }
  .hint-button, .shuffle-button { min-height: 40px; padding: 7px 8px; font-size: 10px; }
  .product-tray { gap: 8px; padding: 0 16px 3px; }
  .product-card {
    width: 112px;
    min-width: 112px;
    min-height: 114px;
    padding: 6px 6px 8px;
    border-radius: 15px;
    box-shadow: 0 6px 13px rgba(221, 96, 14, .18);
  }
  .product-image { height: 70px; padding: 4px; border-radius: 10px; }
  .product-card strong { margin-top: 6px; font-size: 10px; }
}

@media (max-width: 600px) and (max-height: 650px) and (orientation: portrait) {
  .topbar { padding-bottom: 2px; }
  .brand { font-size: 21px; }
  .round-action { width: 40px; height: 40px; }
  .task-copy { grid-template-columns: minmax(0, 1fr) 48px; padding-top: 3px; padding-bottom: 2px; }
  .task-copy h1 { font-size: 17px; }
  .timer { width: 48px; height: 48px; padding-top: 10px; }
  .timer strong { font-size: 26px; }
  .product-dock { margin-top: -24px; padding-top: 7px; padding-bottom: calc(4px + env(safe-area-inset-bottom)); }
  .dock-heading { padding-bottom: 5px; }
  .dock-heading h2 { font-size: 17px; }
  .hint-button, .shuffle-button { min-height: 36px; padding: 6px 7px; }
  .product-card { width: 98px; min-width: 98px; min-height: 100px; padding: 5px 5px 6px; border-radius: 13px; }
  .product-image { height: 61px; padding: 3px; border-radius: 8px; }
  .product-card strong { margin-top: 4px; font-size: 9px; }
}

@media (orientation: landscape) and (max-height: 600px) {
  body { padding: 0; }
  .game-shell {
    width: min(100%, 960px);
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(210px, .78fr) minmax(360px, 1.22fr);
    grid-template-rows: auto auto auto 1fr;
    overflow: hidden;
    border-radius: 0;
  }
  .topbar { grid-column: 2; grid-row: 1; min-height: 53px; padding: max(7px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 3px 14px; }
  .brand { padding-top: 3px; font-size: 21px; line-height: 1.2; }
  .round-action { width: 40px; height: 40px; }
  .task-copy { grid-column: 2; grid-row: 2; grid-template-columns: 1fr 50px; padding: 3px max(16px, env(safe-area-inset-right)) 2px 14px; }
  .task-copy .eyebrow,
  .task-copy > div > p:last-child { display: none; }
  .task-copy h1 { font-size: 18px; line-height: 1.16; }
  .timer { width: 50px; height: 50px; padding-top: 10px; border-radius: 15px 0 0 15px; }
  .timer strong { font-size: 27px; }
  .progress-panel { grid-column: 2; grid-row: 3; padding: 3px max(16px, env(safe-area-inset-right)) 0 14px; }
  .progress-track { margin-top: 3px; }
  .cabinet-board { grid-column: 1; grid-row: 1 / 5; width: auto; height: 100vh; height: 100dvh; max-width: 100%; margin: 0 auto; }
  .product-dock { grid-column: 2; grid-row: 4; min-height: 0; margin: 0; padding: 9px 0 max(7px, env(safe-area-inset-bottom)); border-radius: 20px 0 0 0; overflow: hidden; }
  .dock-heading { align-items: center; padding: 0 max(16px, env(safe-area-inset-right)) 7px 14px; }
  .dock-heading h2 { font-size: 18px; }
  .dock-heading p { margin-top: 2px; font-size: 10px; }
  .hint-button, .shuffle-button { min-height: 38px; padding: 7px 9px; }
  .product-tray { gap: 8px; padding: 0 max(16px, env(safe-area-inset-right)) 3px 14px; }
  .product-card { width: 112px; min-width: 112px; min-height: 120px; padding: 6px; border-radius: 15px; }
  .product-image { height: 77px; }
  .product-card strong { margin-top: 5px; font-size: 10px; }
}

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