@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --ink: #344f40;
  --muted: #819589;
  --green: #5ca978;
  --glass: rgba(255, 255, 255, .76);
  --line: rgba(255, 255, 255, .86);
  --shadow: 0 12px 36px rgba(45, 86, 61, .13);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #eaf7ee;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 45%, rgba(44, 83, 57, .055) 100%);
}

#stage { position: fixed; inset: 0; z-index: 0; }
#stage canvas { display: block; }

.glass-panel {
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(1.12);
  -webkit-backdrop-filter: blur(16px) saturate(1.12);
}

#colorPanel {
  position: fixed;
  z-index: 5;
  top: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  width: 190px;
  padding: 15px;
  border-radius: 20px;
}

#colorPanel strong { font-size: 13px; font-weight: 700; letter-spacing: .04em; }
#colorPanel input {
  width: 100%;
  height: 39px;
  padding: 3px;
  border: 1px solid #dce9df;
  border-radius: 11px;
  background: white;
  cursor: pointer;
}
#colorPanel span { color: var(--muted); font-size: 11px; }

#cameraWindow {
  position: fixed;
  z-index: 6;
  top: 20px;
  right: 20px;
  width: 238px;
  overflow: hidden;
  border-radius: 20px;
}
#cameraHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 39px;
  padding: 0 13px;
  color: #496a54;
  font-size: 12px;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
#cameraHeader:active { cursor: grabbing; }
#cameraStatus {
  max-width: 132px;
  overflow: hidden;
  color: #819586;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#cameraView {
  position: relative;
  height: 150px;
  overflow: hidden;
  background: linear-gradient(135deg, #e7f1e8, #dbe9df);
}
#cameraView video {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  transform: scaleX(-1);
}
#handOverlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#welcome {
  position: fixed;
  z-index: 4;
  top: 50%;
  left: 50%;
  width: min(460px, calc(100% - 34px));
  padding: 32px 32px 27px;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 29px;
  background: rgba(255,255,255,.86);
  box-shadow: 0 22px 70px rgba(43,83,57,.18);
  text-align: center;
  backdrop-filter: blur(20px) saturate(1.15);
  -webkit-backdrop-filter: blur(20px) saturate(1.15);
  transform: translate(-50%, -50%);
}
#welcome.hidden { display: none; }
.eyebrow {
  color: #8aa492;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2.6px;
}
#welcome h1 {
  margin: 11px 0 8px;
  color: #477451;
  font-size: clamp(31px, 4vw, 40px);
  font-weight: 800;
  letter-spacing: .04em;
}
#welcome p { margin: 0 0 20px; color: #718477; font-size: 14px; }
.guide {
  display: grid;
  gap: 11px;
  margin: 21px 0 23px;
  color: #536d5b;
  font-size: 13px;
  text-align: left;
}
.guide div { display: flex; align-items: center; gap: 9px; }
.guide div span { width: 20px; text-align: center; }

#startButton {
  min-width: 142px;
  padding: 12px 25px;
  border: 0;
  border-radius: 999px;
  color: white;
  background: linear-gradient(120deg, #79bd83, #50a879);
  box-shadow: 0 8px 20px rgba(79,160,108,.25);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
}
#startButton span { display: inline-block; margin-left: 5px; transition: transform .2s ease; }
#startButton:hover { filter: brightness(1.04); transform: translateY(-2px); box-shadow: 0 11px 24px rgba(79,160,108,.3); }
#startButton:hover span { transform: translateX(3px); }
#startButton:active { transform: translateY(0); }
#startStatus { display: block; margin-top: 13px; color: #91a094; font-size: 11px; }

#hud {
  position: fixed;
  z-index: 3;
  bottom: 20px;
  left: 50%;
  display: grid;
  gap: 5px;
  width: min(460px, calc(100% - 32px));
  padding: 14px 19px;
  border-radius: 19px;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}
#hud strong { color: #477451; font-size: 15px; font-weight: 800; }
#hud span { color: #65796b; font-size: 12px; }

@media (max-width: 600px) {
  #colorPanel { top: 10px; left: 10px; width: 145px; padding: 10px; border-radius: 15px; }
  #cameraWindow { top: 10px; right: 10px; width: 166px; border-radius: 15px; }
  #cameraHeader { min-height: 34px; padding: 0 9px; }
  #cameraView { height: 105px; }
  #welcome { padding: 25px 20px 22px; border-radius: 23px; }
  .guide { gap: 9px; font-size: 12px; }
  #hud { bottom: 10px; }
}

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

/* ===== V1 mobile adaptation: layout only; game/gesture logic stays untouched ===== */
html, body {
  min-height: 100%;
  min-height: 100dvh;
  overscroll-behavior: none;
}

#stage {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#stage canvas {
  width: 100% !important;
  height: 100% !important;
  touch-action: manipulation;
}

@media (max-width: 700px) {
  #colorPanel {
    top: max(9px, env(safe-area-inset-top));
    left: max(9px, env(safe-area-inset-left));
    width: clamp(112px, 34vw, 148px);
    gap: 6px;
    padding: 9px 10px;
    border-radius: 15px;
  }

  #colorPanel strong { font-size: 11px; }
  #colorPanel input { height: 30px; padding: 2px; border-radius: 8px; }
  #colorPanel span { font-size: 9px; line-height: 1.35; }

  #cameraWindow {
    top: max(9px, env(safe-area-inset-top));
    right: max(9px, env(safe-area-inset-right));
    width: clamp(126px, 38vw, 168px);
    border-radius: 15px;
  }

  #cameraHeader {
    height: 31px;
    padding: 0 9px;
    font-size: 10px;
  }

  #cameraStatus { max-width: 76px; font-size: 9px; }
  #cameraView { height: clamp(78px, 24vw, 108px); }

  #welcome {
    top: 50%;
    width: min(440px, calc(100vw - 28px));
    max-height: calc(100dvh - 30px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: clamp(19px, 5vw, 25px) clamp(17px, 5vw, 22px);
    border-radius: 22px;
    -webkit-overflow-scrolling: touch;
  }

  .eyebrow { font-size: 9px; letter-spacing: 1.8px; }
  #welcome h1 { margin: 7px 0; font-size: clamp(27px, 8vw, 34px); }
  #welcome p { margin-bottom: 13px; font-size: 12px; }
  .guide { gap: 8px; margin: 14px 0 17px; font-size: clamp(10px, 3.1vw, 12px); line-height: 1.45; }
  #startButton { padding: 11px 25px; font-size: 14px; }
  #startStatus { margin-top: 10px; font-size: 10px; line-height: 1.4; }

  #hud {
    bottom: max(9px, env(safe-area-inset-bottom));
    width: min(420px, calc(100vw - 24px));
    gap: 3px;
    padding: 9px 13px;
    border-radius: 14px;
  }
  #hud strong { font-size: 13px; }
  #hud span { font-size: 10px; line-height: 1.35; }
}

/* Very narrow phones: stack the small controls so they never collide. */
@media (max-width: 380px) {
  #colorPanel { width: 108px; }
  #cameraWindow { width: 126px; }
  #cameraView { height: 76px; }
  #cameraStatus { max-width: 57px; font-size: 8px; }
  #welcome { width: calc(100vw - 22px); }
  .guide { font-size: 10px; }
}

/* Landscape phones have little vertical room; keep the welcome card scrollable. */
@media (max-height: 520px) and (orientation: landscape) {
  #colorPanel {
    top: max(6px, env(safe-area-inset-top));
    left: max(7px, env(safe-area-inset-left));
    width: 124px;
    padding: 7px 9px;
    gap: 4px;
  }
  #colorPanel input { height: 25px; }
  #cameraWindow {
    top: max(6px, env(safe-area-inset-top));
    right: max(7px, env(safe-area-inset-right));
    width: 142px;
  }
  #cameraHeader { height: 27px; }
  #cameraView { height: 75px; }
  #welcome {
    width: min(430px, calc(100vw - 300px));
    max-height: calc(100dvh - 16px);
    padding: 13px 20px;
  }
  #welcome h1 { margin: 4px 0; font-size: 25px; }
  #welcome p { margin-bottom: 8px; font-size: 11px; }
  .guide { gap: 4px; margin: 8px 0; font-size: 10px; }
  #startButton { padding: 7px 19px; font-size: 12px; }
  #startStatus { margin-top: 5px; font-size: 9px; }
  #hud { bottom: max(5px, env(safe-area-inset-bottom)); padding: 7px 12px; }
}
