* { box-sizing: border-box; }

:root {
  --cream: #fff8ef;
  --coral: #ff7f63;
  --rose: #ff6f91;
  --amber: #ffb347;
  --brown: #6b4a3a;
  --brown-soft: #a9785d;
  --card: rgba(255, 252, 246, 0.94);
  --line: #ffd3b0;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 620px at 10% -12%, #fff3d6 0%, rgba(255, 243, 214, 0) 62%),
    radial-gradient(900px 520px at 102% 2%, #ffe0ec 0%, rgba(255, 224, 236, 0) 58%),
    linear-gradient(180deg, #fff6ea 0%, #ffeada 46%, #ffe0e5 100%);
  background-attachment: fixed;
  color: var(--brown);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}

body { overflow-x: hidden; }

/* 반짝이는 장식 */
.sparkle-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.sparkle-layer span {
  position: absolute;
  color: #ffc94d;
  opacity: 0;
  text-shadow: 0 0 10px rgba(255, 200, 90, 0.9);
  animation: twinkle 3.6s ease-in-out infinite;
}

.sparkle-layer span:nth-child(1) { left: 6%;  top: 10%; font-size: 15px; animation-delay: 0s; }
.sparkle-layer span:nth-child(2) { left: 88%; top: 18%; font-size: 20px; animation-delay: 0.6s; }
.sparkle-layer span:nth-child(3) { left: 18%; top: 62%; font-size: 13px; animation-delay: 1.2s; }
.sparkle-layer span:nth-child(4) { left: 78%; top: 74%; font-size: 17px; animation-delay: 1.8s; }
.sparkle-layer span:nth-child(5) { left: 46%; top: 5%;  font-size: 14px; animation-delay: 2.4s; }
.sparkle-layer span:nth-child(6) { left: 62%; top: 90%; font-size: 16px; animation-delay: 3s; }

@keyframes twinkle {
  0%, 100% { opacity: 0; transform: scale(0.6) rotate(0deg); }
  50% { opacity: 0.95; transform: scale(1.15) rotate(18deg); }
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
  padding: 16px 14px 26px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 0 2px;
}

.app-header .sparkle {
  font-size: 1rem;
  color: var(--amber);
  animation: twinkle 2.8s ease-in-out infinite;
}

.app-header .sparkle:last-child { animation-delay: 1.4s; }

h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: center;
  background: linear-gradient(92deg, #ff7a59 0%, #ff9f43 42%, #ff6f91 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 6px rgba(255, 138, 107, 0.35));
}

.stage {
  position: relative;
  width: 100%;
  max-width: min(640px, calc(58vh * 4 / 3));
  aspect-ratio: 4 / 3;
  margin: 0 auto;
  background: linear-gradient(160deg, #fffdf9, #ffe9d8);
  border: 2px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow:
    0 10px 28px rgba(255, 150, 110, 0.24),
    0 0 26px rgba(255, 196, 120, 0.45),
    0 0 0 6px rgba(255, 255, 255, 0.45) inset;
}

#cam {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  object-fit: contain;
  background: #fffaf4;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 16px;
  text-align: center;
  font-size: 0.92rem;
  color: var(--brown-soft);
  pointer-events: none;
}

.placeholder.hidden { display: none; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

button {
  flex: 0 1 auto;
  min-width: 96px;
  padding: 11px 18px;
  border: 2px solid #ffc59b;
  border-radius: 999px;
  background: linear-gradient(180deg, #fffdf8, #ffe8d3);
  color: #8a4a2f;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(255, 160, 120, 0.22);
  transition: transform 0.12s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 7px 16px rgba(255, 160, 120, 0.32);
}

button:active:not(:disabled) { transform: translateY(0); }

button:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

button.primary {
  border-color: #ff9a6b;
  background: linear-gradient(180deg, #ffb066, #ff7f63);
  color: #fff8f2;
  box-shadow: 0 6px 16px rgba(255, 122, 89, 0.42);
}

button.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #ffbe7d, #ff8d70);
}

button:focus-visible {
  outline: 3px solid rgba(255, 150, 110, 0.75);
  outline-offset: 2px;
}

.status {
  margin: 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--brown-soft);
}

.error {
  margin: 0;
  padding: 10px 14px;
  border: 2px solid #f0a58f;
  border-radius: 14px;
  background: #fff1ec;
  color: #a8402c;
  font-size: 0.88rem;
  line-height: 1.5;
}

.notice {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.55;
  color: #b58a70;
}

.score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 2px 0 0;
  padding: 12px 14px;
  border: 2px solid #ffd9bd;
  border-radius: 18px;
  background: var(--card);
  box-shadow:
    0 8px 20px rgba(255, 170, 130, 0.22),
    0 0 22px rgba(255, 210, 140, 0.35);
}

.score-label {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #c98a63;
}

.score-value {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(92deg, #ff8a5c, #ffb347 55%, #ff6f91);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.score-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--brown-soft);
}

.ranking-status {
  margin: 4px 0 0;
  min-height: 1.15em;
  text-align: center;
  font-size: 0.84rem;
  font-weight: 700;
  color: #d15a3c;
}

@media (prefers-reduced-motion: reduce) {
  .sparkle-layer span,
  .app-header .sparkle {
    animation: none;
    opacity: 0.7;
  }
  button { transition: none; }
}
