:root {
  --sky: #9dddf7;
  --sky-deep: #6ec8f1;
  --grass: #8ed16f;
  --grass-dark: #50a95b;
  --soil: #8d5730;
  --soil-light: #b9773e;
  --cream: #fff8df;
  --ink: #2f2a22;
  --yellow: #ffd950;
  --orange: #f5a33b;
  --red: #f05246;
  --green: #5dbb50;
  --blue: #4aaee8;
  --white: #ffffff;
  --shadow: rgba(51, 37, 20, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Jua", "Arial Rounded MT Bold", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  background:
    linear-gradient(var(--sky), #c9f2ff 52%, #b6e58c 52%, var(--grass));
}

button {
  border: 0;
  border-radius: 999px;
  padding: 14px 28px;
  color: var(--ink);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  background: var(--yellow);
  box-shadow: 0 5px 0 #d89224, 0 10px 20px var(--shadow);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #d89224, 0 14px 24px var(--shadow);
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #d89224, 0 6px 16px var(--shadow);
}

.game-shell {
  width: min(1180px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0 26px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

body[data-screen="start"] {
  overflow: hidden;
  background: #83d8ff;
}

body[data-screen="start"] .game-shell {
  width: 100vw;
  height: 100vh;
  padding: 0;
  grid-template-rows: 1fr;
  gap: 0;
}

body[data-screen="start"] .top-panel {
  display: none;
}

body[data-screen="start"] .stage-wrap {
  min-height: 100vh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body[data-screen="start"] #gameCanvas {
  min-height: 100vh;
}

body[data-screen="start"] .camera-preview {
  display: none;
}

.top-panel {
  display: grid;
  grid-template-columns: 245px minmax(280px, 1fr) 180px;
  gap: 8px;
  align-items: start;
}

.top-panel > div {
  min-width: 0;
  border: 3px solid rgba(255, 255, 255, 0.7);
  border-radius: 18px;
  padding: 10px 12px;
  background: rgba(255, 248, 223, 0.88);
  box-shadow: 0 8px 24px var(--shadow);
}

.top-panel > .time-panel-card {
  grid-column: 1;
  min-height: 78px;
  border: 0;
  border-radius: 0;
  padding: 20px 18px 14px 42%;
  background-color: transparent;
  background-image: url("assets/time-panel.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  box-shadow: none;
}

.top-panel > .time-panel-card .label {
  color: #6b3a17;
  font-size: 0.78rem;
  text-shadow: 0 1px 0 rgba(255, 238, 184, 0.8);
}

.top-panel > .time-panel-card strong {
  color: #3f2514;
  font-size: 1.45rem;
  line-height: 1.05;
  text-shadow: 0 2px 0 rgba(255, 238, 184, 0.72);
}

.top-panel > .harvest-panel-card {
  grid-column: 3;
  min-height: 80px;
  aspect-ratio: 1390 / 620;
  border: 0;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 20px 12px 14px 36%;
  background-color: transparent;
  background-image: url("assets/harvest-panel.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  box-shadow: none;
}

.top-panel > .harvest-panel-card .label {
  margin: 0;
  color: #6b3a17;
  font-size: 0.74rem;
  text-shadow: 0 1px 0 rgba(255, 238, 184, 0.8);
  white-space: nowrap;
}

.top-panel > .harvest-panel-card strong {
  color: #3f2514;
  font-size: 1.08rem;
  line-height: 1.05;
  text-shadow: 0 2px 0 rgba(255, 238, 184, 0.72);
  white-space: nowrap;
}

.label {
  margin: 0 0 3px;
  color: #715338;
  font-size: 0.78rem;
  font-weight: 800;
}

.top-panel strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(0.92rem, 1.5vw, 1.15rem);
}

.gesture-panel {
  grid-column: 2;
  min-height: 78px;
  border: 4px solid #8b4f23;
  border-radius: 22px;
  padding: 12px 20px;
  background:
    linear-gradient(90deg, rgba(255, 244, 199, 0.88), rgba(255, 221, 139, 0.94)),
    repeating-linear-gradient(0deg, rgba(122, 68, 28, 0.12) 0 2px, transparent 2px 15px);
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.36),
    inset 0 -8px 0 rgba(120, 63, 25, 0.12),
    0 8px 18px rgba(51, 37, 20, 0.14);
}

.gesture-panel strong {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  line-height: 1.28;
  font-size: clamp(1.05rem, 2vw, 1.38rem);
  word-break: keep-all;
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  border: 5px solid var(--white);
  border-radius: 24px;
  min-height: 420px;
  background: #bfeeff;
  box-shadow: 0 16px 40px var(--shadow);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 540px;
}

.camera-preview {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 170px;
  aspect-ratio: 4 / 3;
  border: 4px solid var(--cream);
  border-radius: 16px;
  background: #263238;
  object-fit: cover;
  transform: scaleX(-1);
  box-shadow: 0 8px 24px var(--shadow);
}

.toast {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%) translateY(-12px);
  max-width: min(520px, calc(100% - 36px));
  border: 3px solid var(--white);
  border-radius: 999px;
  padding: 10px 18px;
  color: var(--ink);
  font-weight: 900;
  text-align: center;
  background: rgba(255, 217, 80, 0.94);
  box-shadow: 0 8px 24px var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(65, 145, 170, 0.32);
  backdrop-filter: blur(4px);
}

.overlay.is-hidden {
  display: none;
}

.overlay-card {
  width: min(720px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  border: 5px solid var(--white);
  border-radius: 24px;
  padding: 30px 28px;
  text-align: center;
  background: rgba(255, 248, 223, 0.96);
  box-shadow: 0 18px 42px var(--shadow);
}

.overlay.is-guide-screen .overlay-card {
  width: min(1180px, 100%);
  padding: 28px;
  text-align: left;
}

.overlay.is-camera-screen .overlay-card {
  width: min(740px, 82vw);
  aspect-ratio: 1250 / 900;
  max-height: calc(100% - 44px);
  display: grid;
  align-content: end;
  justify-items: center;
  border: 0;
  border-radius: 0;
  padding: 0 0 7%;
  overflow: visible;
  background-color: transparent;
  background-image: url("assets/camera-permission-panel.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  box-shadow: none;
}

.overlay.is-camera-screen .overlay-card h1,
.overlay.is-camera-screen .overlay-card > p,
.overlay.is-camera-screen .overlay-extra {
  display: none;
}

.overlay.is-camera-screen #primaryButton {
  width: min(300px, 48%);
  aspect-ratio: 660 / 220;
  padding: 0;
  border-radius: 0;
  color: transparent;
  font-size: 0;
  background-color: transparent;
  background-image: url("assets/camera-allow-button.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  box-shadow: none;
}

.overlay.is-camera-screen #primaryButton:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: none;
}

.overlay.is-camera-screen #primaryButton:active {
  transform: translateY(2px) scale(0.99);
  box-shadow: none;
}

.overlay.is-opening-screen {
  padding: 18px;
  background: rgba(26, 61, 78, 0.42);
  backdrop-filter: blur(7px);
}

.overlay.is-opening-screen .overlay-card {
  width: min(1040px, 96vw);
  max-height: min(88vh, 760px);
  display: grid;
  gap: 14px;
  justify-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  overflow: visible;
  background: transparent;
  box-shadow: none;
}

.overlay.is-opening-screen .overlay-card h1,
.overlay.is-opening-screen .overlay-card > p {
  display: none;
}

.overlay.is-opening-screen .overlay-extra {
  width: 100%;
  margin: 0;
}

.opening-video-layout {
  width: 100%;
  padding: 10px;
  border: 5px solid rgba(255, 255, 255, 0.9);
  border-radius: 26px;
  background: rgba(255, 248, 223, 0.22);
  box-shadow: 0 18px 42px rgba(37, 28, 17, 0.28);
}

.opening-video {
  display: block;
  width: 100%;
  max-height: min(68vh, 610px);
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 18px;
  background: #111;
}

.overlay.is-opening-screen #primaryButton {
  min-width: 150px;
  padding: 13px 34px;
}

.overlay.is-fail-ending-screen {
  padding: 18px;
  background: rgba(28, 42, 66, 0.5);
  backdrop-filter: blur(7px);
}

.overlay.is-fail-ending-screen .overlay-card {
  width: min(980px, 96vw);
  max-height: min(90vh, 780px);
  display: grid;
  gap: 12px;
  justify-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  overflow: visible;
  background: transparent;
  box-shadow: none;
}

.overlay.is-fail-ending-screen .overlay-card h1 {
  margin: 0;
  color: #fff4df;
  font-size: clamp(1.8rem, 5vw, 3.4rem);
  text-shadow: 0 4px 12px rgba(34, 20, 12, 0.55);
}

.overlay.is-fail-ending-screen .overlay-card > p {
  margin: -4px 0 0;
  color: #fff8e9;
  text-shadow: 0 3px 10px rgba(34, 20, 12, 0.5);
}

.overlay.is-fail-ending-screen .overlay-extra {
  width: 100%;
  margin: 0;
}

.fail-ending-layout {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.fail-ending-video {
  display: block;
  width: min(860px, 100%);
  max-height: min(58vh, 520px);
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 5px solid rgba(255, 255, 255, 0.9);
  border-radius: 24px;
  background: #111;
  box-shadow: 0 18px 42px rgba(20, 20, 35, 0.36);
}

.fail-summary-panel {
  width: min(500px, 92vw);
  min-height: 168px;
  margin: 0;
}

.overlay.is-fail-ending-screen #primaryButton {
  min-width: 150px;
  padding: 13px 34px;
}

.overlay.is-success-ending-screen {
  padding: 18px;
  background: rgba(47, 119, 71, 0.42);
  backdrop-filter: blur(7px);
}

.overlay.is-success-ending-screen .overlay-card {
  width: min(980px, 96vw);
  max-height: min(90vh, 780px);
  display: grid;
  gap: 12px;
  justify-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  overflow: visible;
  background: transparent;
  box-shadow: none;
}

.overlay.is-success-ending-screen .overlay-card h1 {
  margin: 0;
  color: #fff8df;
  font-size: clamp(1.8rem, 5vw, 3.4rem);
  text-shadow: 0 4px 12px rgba(53, 40, 15, 0.48);
}

.overlay.is-success-ending-screen .overlay-card > p {
  margin: -4px 0 0;
  color: #fffbe9;
  text-shadow: 0 3px 10px rgba(53, 40, 15, 0.42);
}

.overlay.is-success-ending-screen .overlay-extra {
  width: 100%;
  margin: 0;
}

.success-ending-layout {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.success-ending-video {
  display: block;
  width: min(860px, 100%);
  max-height: min(58vh, 520px);
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 5px solid rgba(255, 255, 255, 0.92);
  border-radius: 24px;
  background: #111;
  box-shadow: 0 18px 42px rgba(31, 56, 24, 0.32);
}

.success-summary-panel {
  width: min(500px, 92vw);
  min-height: 168px;
  margin: 0;
}

.overlay.is-success-ending-screen #primaryButton {
  min-width: 150px;
  padding: 13px 34px;
}

.overlay.is-guide-screen .overlay-card h1,
.overlay.is-guide-screen .overlay-card > p {
  text-align: center;
}

.overlay-card h1 {
  margin: 0 0 14px;
  color: #5d3a20;
  font-size: clamp(2rem, 7vw, 4.2rem);
  line-height: 1.04;
}

.overlay-card p {
  margin: 0 auto 24px;
  max-width: 38rem;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  line-height: 1.55;
  word-break: keep-all;
}

.overlay-extra {
  margin: -4px 0 24px;
}

.ending-harvest-panel {
  width: min(500px, 100%);
  min-height: 168px;
  margin: 0 auto;
  padding: 40px 44px 28px 182px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 5px;
  background-image: url("assets/harvest-panel.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  color: #4b2b17;
  filter: drop-shadow(0 12px 18px rgba(51, 37, 20, 0.18));
  text-align: left;
}

.ending-harvest-panel span {
  display: block;
  width: 100%;
  font-size: 1.1rem;
  color: #6b3a17;
  text-shadow: 0 1px 0 rgba(255, 238, 184, 0.8);
  white-space: nowrap;
}

.ending-harvest-panel strong {
  display: block;
  width: 100%;
  font-size: 2rem;
  line-height: 1;
  color: #3f2514;
  text-shadow: 0 2px 0 rgba(255, 238, 184, 0.72);
  white-space: nowrap;
}

.ending-harvest-panel small {
  display: block;
  width: 100%;
  font-size: 1rem;
  color: #5d3a20;
  word-break: keep-all;
  white-space: nowrap;
}

.gesture-guide-layout {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(320px, 390px);
  gap: 16px;
  align-items: center;
  justify-content: center;
}

.guide-video-panel {
  min-height: 380px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
  border: 4px solid rgba(255, 255, 255, 0.78);
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 100%, rgba(255, 225, 119, 0.46), transparent 54%),
    linear-gradient(180deg, rgba(172, 229, 255, 0.68), rgba(126, 207, 112, 0.48));
  box-shadow: inset 0 -7px 0 rgba(93, 58, 32, 0.08);
}

.guide-duck-video {
  width: min(290px, 100%);
  max-height: 350px;
  border: 5px solid var(--cream);
  border-radius: 22px;
  background: #9dddf7;
  object-fit: cover;
  box-shadow: 0 14px 28px rgba(51, 37, 20, 0.2);
}

.guide-copy-panel {
  width: min(390px, 100%);
  aspect-ratio: 1024 / 1536;
  min-height: auto;
  border: 0;
  border-radius: 26px;
  padding: 96px 54px 82px;
  background-image: url("assets/guide-panel.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  filter: drop-shadow(0 18px 24px rgba(51, 37, 20, 0.2));
}

.guide-copy-panel h2 {
  margin: 0 0 8px;
  color: #5d3a20;
  font-size: clamp(1.2rem, 2vw, 1.45rem);
  line-height: 1.15;
  text-align: center;
  text-shadow: 0 2px 0 rgba(255, 235, 170, 0.72);
}

.guide-copy-panel p {
  margin: 0 auto 12px;
  max-width: none;
  color: #4f3b2c;
  font-size: clamp(0.82rem, 1.1vw, 0.94rem);
  line-height: 1.38;
  text-align: center;
  word-break: keep-all;
}

.gesture-step-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.guide-step {
  display: grid;
  gap: 2px;
  min-height: 50px;
  border: 2px solid rgba(146, 82, 25, 0.16);
  border-radius: 16px;
  padding: 8px 12px;
  background: rgba(255, 242, 190, 0.46);
  box-shadow: inset 0 -3px 0 rgba(129, 70, 23, 0.07);
}

.guide-step strong {
  color: #5d3a20;
  font-size: 0.92rem;
  text-shadow: 0 1px 0 rgba(255, 240, 190, 0.78);
}

.guide-step span {
  color: #4f3b2c;
  font-size: 0.82rem;
  line-height: 1.35;
  word-break: keep-all;
}

.gesture-guide {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
}

.gesture-card {
  min-height: 116px;
  border: 3px solid rgba(255, 255, 255, 0.86);
  border-radius: 18px;
  padding: 14px 15px;
  background: rgba(255, 255, 255, 0.48);
  box-shadow: inset 0 -4px 0 rgba(93, 58, 32, 0.07);
}

.gesture-card strong {
  display: block;
  margin-bottom: 7px;
  color: #5d3a20;
  font-size: 1.05rem;
}

.gesture-card span {
  display: block;
  color: #4f3b2c;
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: keep-all;
}

@media (max-width: 880px) {
  .top-panel {
    grid-template-columns: repeat(2, 1fr);
  }

  .top-panel > .time-panel-card {
    grid-column: 1;
    min-height: 104px;
    padding-left: 40%;
  }

  .top-panel > .harvest-panel-card {
    grid-column: 2;
    min-height: 88px;
    padding: 22px 14px 15px 38%;
  }

  .gesture-panel {
    grid-column: 1 / -1;
  }

  #gameCanvas {
    min-height: 470px;
  }

  .gesture-guide-layout {
    grid-template-columns: 1fr;
  }

  .guide-copy-panel {
    width: min(360px, 100%);
    aspect-ratio: 1024 / 1536;
    min-height: auto;
    padding: 90px 50px 76px;
  }

  .guide-video-panel {
    min-height: 260px;
  }

  .guide-duck-video {
    width: min(240px, 100%);
    max-height: 240px;
  }
}

@media (max-width: 560px) {
  .game-shell {
    width: calc(100vw - 16px);
    padding-top: 8px;
  }

  .top-panel {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .top-panel > .time-panel-card {
    grid-column: 1 / -1;
    min-height: 82px;
    padding: 21px 18px 14px 40%;
  }

  .top-panel > .harvest-panel-card {
    grid-column: 1 / -1;
    min-height: 88px;
    padding: 22px 18px 15px 38%;
  }

  .top-panel > .time-panel-card strong {
    font-size: 1.35rem;
  }

  .top-panel > .harvest-panel-card strong {
    font-size: 1.12rem;
  }

  .ending-harvest-panel {
    width: min(430px, 94vw);
    min-height: 144px;
    padding: 34px 34px 24px 154px;
  }

  .ending-harvest-panel span {
    font-size: 0.92rem;
  }

  .ending-harvest-panel strong {
    font-size: 1.55rem;
  }

  .ending-harvest-panel small {
    font-size: 0.86rem;
  }

  .gesture-panel {
    grid-column: 1 / -1;
  }

  .top-panel > div {
    border-radius: 14px;
    padding: 8px 9px;
  }

  .stage-wrap {
    border-width: 3px;
    border-radius: 18px;
  }

  #gameCanvas {
    min-height: 420px;
  }

  .camera-preview {
    width: 116px;
    right: 8px;
    bottom: 8px;
    border-width: 3px;
  }

  .overlay-card {
    border-radius: 18px;
    padding: 24px 18px;
  }

  .overlay.is-guide-screen .overlay-card {
    padding: 20px 14px;
  }

  .overlay.is-camera-screen .overlay-card {
    width: min(86vw, 500px);
    padding-bottom: 7%;
  }

  .overlay.is-camera-screen #primaryButton {
    width: min(230px, 50%);
  }

  .overlay.is-opening-screen {
    padding: 12px;
  }

  .overlay.is-opening-screen .overlay-card {
    width: 96vw;
    gap: 10px;
  }

  .opening-video-layout {
    padding: 6px;
    border-width: 3px;
    border-radius: 18px;
  }

  .opening-video {
    max-height: 62vh;
    border-radius: 13px;
  }

  .overlay.is-fail-ending-screen {
    padding: 12px;
  }

  .overlay.is-fail-ending-screen .overlay-card {
    width: 96vw;
    gap: 8px;
  }

  .fail-ending-video {
    max-height: 48vh;
    border-width: 3px;
    border-radius: 16px;
  }

  .fail-summary-panel {
    width: min(430px, 94vw);
  }

  .overlay.is-success-ending-screen {
    padding: 12px;
  }

  .overlay.is-success-ending-screen .overlay-card {
    width: 96vw;
    gap: 8px;
  }

  .success-ending-video {
    max-height: 48vh;
    border-width: 3px;
    border-radius: 16px;
  }

  .success-summary-panel {
    width: min(430px, 94vw);
  }

  .guide-copy-panel {
    width: min(330px, 100%);
    aspect-ratio: 1024 / 1536;
    min-height: auto;
    padding: 78px 34px 62px;
  }

  .guide-step {
    grid-template-columns: 1fr;
    gap: 2px;
    min-height: auto;
  }

  .gesture-guide {
    grid-template-columns: 1fr;
  }

}
