:root {
  --paper: #f9f6ec;
  --paper-deep: #eee6d2;
  --ink: #172033;
  --ink-soft: #35405a;
  --muted: #697080;
  --line: rgba(23, 32, 51, 0.14);
  --gold: #e5b83e;
  --gold-light: #f7dc82;
  --gold-deep: #a97713;
  --green: #2f624d;
  --orange: #d85a36;
  --shadow: rgba(18, 28, 47, 0.28);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

:lang(ja) body {
  font-family: Inter, "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
}

body {
  display: flex;
  min-width: 280px;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding: env(safe-area-inset-top) 12px calc(14px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% -12%, rgba(255, 255, 255, 0.96) 0, rgba(255, 255, 255, 0) 42%),
    linear-gradient(180deg, #c7e7f1 0%, #edf4e4 54%, var(--paper) 100%);
  color: var(--ink);
  font-family: Inter, Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button,
a {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  display: flex;
  width: 100%;
  max-width: 500px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px 10px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 850;
  text-decoration: none;
}

.back-link img {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(23, 32, 51, 0.16);
  border-radius: 8px;
  box-shadow: 0 3px 9px rgba(23, 32, 51, 0.14);
}

.challenge-label {
  color: rgba(23, 32, 51, 0.78);
  font-size: 0.64rem;
  font-weight: 950;
  letter-spacing: 0.12em;
}

.game-shell {
  width: 100%;
  max-width: 500px;
}

.stage {
  position: relative;
  isolation: isolate;
  width: 100%;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  border: 1px solid rgba(23, 32, 51, 0.1);
  border-radius: 26px;
  background: #bee2ee;
  box-shadow:
    0 24px 60px -30px rgba(17, 26, 48, 0.72),
    0 2px 0 rgba(255, 255, 255, 0.7) inset;
  cursor: default;
  image-rendering: pixelated;
  touch-action: auto;
}

.hud {
  position: absolute;
  z-index: 2;
  top: 18px;
  right: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.hud-pill {
  position: relative;
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  padding: 8px 13px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 999px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  box-shadow:
    0 9px 24px -12px rgba(17, 26, 48, 0.5),
    0 1px 0 rgba(255, 255, 255, 0.78) inset;
  backdrop-filter: blur(9px) saturate(1.08);
}

.hud-pill::after {
  position: absolute;
  top: 0;
  left: 12%;
  width: 48%;
  height: 1px;
  background: rgba(255, 255, 255, 0.92);
  content: "";
}

.best-pill {
  background: rgba(23, 32, 51, 0.88);
  color: #fffaf0;
}

.best-pill .hud-label {
  color: var(--gold-light);
}

.wood-pill {
  background: rgba(249, 246, 236, 0.9);
}

.wood-pill img {
  width: 30px;
  height: auto;
  image-rendering: pixelated;
}

.hud-label {
  font-size: 0.63rem;
  font-weight: 950;
  letter-spacing: 0.08em;
}

.hud-pill strong {
  font-size: 1.03rem;
  font-weight: 950;
}

.wood-pill.score-pop {
  animation: hud-pop 320ms cubic-bezier(0.18, 0.9, 0.3, 1.35);
}

.best-pill.record-pop {
  animation: record-glow 780ms ease both;
}

.controls {
  margin-top: 13px;
  text-align: center;
}

.chop-btn {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 72px;
  place-content: center;
  gap: 1px;
  overflow: hidden;
  padding: 10px 22px 12px;
  border: 1px solid rgba(101, 70, 8, 0.3);
  border-radius: 19px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0) 0 38%, rgba(255, 255, 255, 0.28) 50%, rgba(255, 255, 255, 0) 62%) -120% 0 / 180% 100% no-repeat,
    linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 54%, #c9931c 100%);
  color: #342307;
  cursor: pointer;
  box-shadow:
    0 6px 0 #8c6310,
    0 15px 28px -15px rgba(126, 83, 5, 0.76),
    0 1px 0 rgba(255, 255, 255, 0.72) inset;
  text-shadow: 0 1px rgba(255, 255, 255, 0.34);
  transition: transform 70ms ease, box-shadow 70ms ease, filter 140ms ease;
  user-select: none;
}

.chop-btn:hover {
  filter: saturate(1.08) brightness(1.02);
}

.chop-btn:active {
  transform: translateY(4px);
  box-shadow:
    0 2px 0 #8c6310,
    0 8px 18px -12px rgba(126, 83, 5, 0.7),
    0 1px 0 rgba(255, 255, 255, 0.72) inset;
}

.button-kicker {
  font-size: 0.61rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  opacity: 0.68;
}

.button-label {
  font-size: 1.28rem;
  font-weight: 950;
  letter-spacing: -0.02em;
}

.hint {
  margin: 13px 4px 2px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

kbd {
  padding: 1px 6px 2px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 850;
}

.result-overlay {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  align-items: safe center;
  overflow-y: auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 8%, rgba(229, 184, 62, 0.18), transparent 34%),
    rgba(12, 20, 36, 0.72);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  backdrop-filter: blur(10px) saturate(0.82);
  transition: opacity 260ms ease, visibility 260ms ease;
}

.result-overlay[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.result-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  min-width: 0;
  overflow: hidden;
  padding: 25px 25px 24px;
  border: 1px solid rgba(229, 184, 62, 0.72);
  border-radius: 27px;
  background:
    radial-gradient(circle at 100% 0, rgba(229, 184, 62, 0.18), transparent 32%),
    linear-gradient(145deg, #fffdf5 0%, var(--paper) 64%, #eee5cf 100%);
  color: var(--ink);
  box-shadow:
    0 34px 80px -30px rgba(0, 0, 0, 0.78),
    0 0 0 5px rgba(249, 246, 236, 0.09),
    0 1px 0 rgba(255, 255, 255, 0.9) inset;
  text-align: center;
  transform: translateY(18px) scale(0.965);
  transition: transform 330ms cubic-bezier(0.17, 0.84, 0.28, 1.2);
}

.result-card::before {
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(169, 119, 19, 0.2);
  border-radius: 20px;
  content: "";
  pointer-events: none;
}

.result-overlay[aria-hidden="false"] .result-card {
  transform: none;
}

.card-shine {
  position: absolute;
  top: -80px;
  right: -45px;
  width: 180px;
  height: 230px;
  background: linear-gradient(115deg, transparent 20%, rgba(255, 255, 255, 0.65) 49%, transparent 73%);
  opacity: 0.48;
  transform: rotate(18deg);
  pointer-events: none;
}

.result-brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 23px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(23, 32, 51, 0.12);
  text-align: left;
}

.result-brand img {
  width: 58px;
  height: 58px;
  border: 1px solid rgba(23, 32, 51, 0.16);
  border-radius: 15px;
  box-shadow: 0 8px 18px -9px rgba(23, 32, 51, 0.65);
}

.result-brand div {
  display: grid;
  gap: 2px;
}

.result-brand span {
  color: var(--gold-deep);
  font-size: 0.59rem;
  font-weight: 950;
  letter-spacing: 0.14em;
}

.result-brand strong {
  font-size: 1rem;
  font-weight: 950;
  letter-spacing: -0.02em;
}

.result-eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.61rem;
  font-weight: 950;
  letter-spacing: 0.1em;
}

.new-record {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  padding: 6px 12px;
  border: 1px solid rgba(169, 119, 19, 0.34);
  border-radius: 999px;
  background: linear-gradient(180deg, #fff7cf, #f3d774);
  color: #6c4908;
  font-size: 0.77rem;
  font-weight: 950;
  box-shadow: 0 5px 14px -8px rgba(126, 83, 5, 0.7);
}

.new-record.record-arrive {
  animation: badge-arrive 680ms 180ms cubic-bezier(0.18, 0.9, 0.3, 1.3) both;
}

.new-record[hidden] {
  display: none;
}

.result-score {
  display: grid;
  gap: 3px;
  margin: 0;
}

.result-score-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.result-score > strong {
  display: block;
  font-size: clamp(2.7rem, 12vw, 4.2rem);
  font-weight: 950;
  letter-spacing: -0.075em;
  line-height: 1.08;
}

.result-score small {
  margin-left: 4px;
  font-size: 0.43em;
  letter-spacing: -0.04em;
}

.result-best {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  margin: 9px 0 10px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(23, 32, 51, 0.06);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.result-best strong {
  color: var(--ink);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.result-tier {
  max-width: 340px;
  margin: 0 auto 8px;
  color: var(--gold-deep);
  font-size: clamp(1.08rem, 4.8vw, 1.38rem);
  font-weight: 950;
  line-height: 1.2;
  text-wrap: balance;
  text-shadow: 0 1px rgba(255, 255, 255, 0.72);
}

.result-copy {
  min-height: 42px;
  margin: 0 auto 22px;
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.55;
}

.result-actions {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 9px;
}

.action-btn,
.store-btn {
  display: inline-flex;
  min-width: 0;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 13px;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 900;
  text-decoration: none;
  transition: transform 120ms ease, background-color 120ms ease, filter 120ms ease;
}

.action-btn:hover,
.store-btn:hover {
  transform: translateY(-1px);
}

.action-btn:active,
.store-btn:active {
  transform: translateY(1px);
}

.retry-btn {
  border: 1px solid rgba(23, 32, 51, 0.17);
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink);
}

.share-btn {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
}

.share-btn:disabled {
  cursor: wait;
  opacity: 0.7;
}

.image-btn {
  grid-column: 1 / -1;
  border: 1px solid rgba(23, 32, 51, 0.24);
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
}

.image-btn:disabled {
  cursor: wait;
  opacity: 0.62;
}

.image-panel {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid rgba(23, 32, 51, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
}

.image-panel p {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 780;
  line-height: 1.45;
}

.image-panel img {
  display: block;
  width: 100%;
  max-height: min(62vh, 560px);
  object-fit: contain;
  border-radius: 10px;
  background: #111a30;
  -webkit-user-select: auto;
  user-select: auto;
  -webkit-touch-callout: default;
}

.store-btn {
  grid-column: 1 / -1;
  border: 1px solid #825e0e;
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  color: #382805;
  box-shadow: 0 8px 16px -10px rgba(126, 83, 5, 0.75);
}

.toast {
  position: fixed;
  z-index: 100;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  max-width: 430px;
  margin-inline: auto;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(23, 32, 51, 0.94);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 750;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: none;
}

body.is-embedded {
  min-height: 0;
  padding: 6px 5px 10px;
  background: transparent;
}

.is-embedded .topbar {
  display: none;
}

.is-embedded canvas {
  border-radius: 23px;
}

@keyframes hud-pop {
  0% { transform: scale(1); }
  38% { transform: scale(1.17) rotate(1deg); filter: brightness(1.1); }
  100% { transform: scale(1); }
}

@keyframes record-glow {
  0%, 100% { box-shadow: 0 9px 24px -12px rgba(17, 26, 48, 0.5); }
  42% { box-shadow: 0 0 0 5px rgba(229, 184, 62, 0.28), 0 10px 28px -10px rgba(17, 26, 48, 0.6); }
}

@keyframes badge-arrive {
  from { opacity: 0; transform: translateY(5px) scale(0.75); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 420px) {
  .hud {
    top: 14px;
    right: 13px;
    left: 13px;
  }

  .hud-pill {
    min-height: 39px;
    gap: 5px;
    padding: 7px 10px;
  }

  .hud-label {
    font-size: 0.56rem;
  }

  .hud-pill strong {
    font-size: 0.93rem;
  }

  .wood-pill img {
    width: 25px;
  }

  .chop-btn {
    min-height: 65px;
  }

  .hint {
    font-size: 0.72rem;
  }

  .result-overlay {
    padding-inline: 12px;
  }

  .result-card {
    padding: 20px 19px 19px;
    border-radius: 23px;
  }

  .result-brand {
    margin-bottom: 17px;
    padding-bottom: 14px;
  }

  .result-brand img {
    width: 50px;
    height: 50px;
    border-radius: 13px;
  }

  .result-copy {
    margin-bottom: 17px;
  }
}

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