* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: linear-gradient(180deg, #fff8f0 0%, #ffe9d6 100%);
  --primary: #ff7a45;
  --primary-dark: #e85d2f;
  --secondary: #5b8def;
  --accent: #ffd166;
  --success: #10b981;
  --text: #2b2b2b;
  --text-light: #6b6b6b;
  --card: #ffffff;
  --border: #ffd9bd;
  --grid-bg: #fff8ef;
  --grid-line: #ffd9bd;
  --target: rgba(91, 141, 239, 0.18);
  --target-stroke: #5b8def;
  --shadow-sm: 0 2px 8px rgba(255, 122, 69, 0.10);
  --shadow-md: 0 6px 18px rgba(255, 122, 69, 0.14);
  --radius: 14px;
  --font: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', system-ui, sans-serif;
}

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  font-size: 16px;
  line-height: 1.4;
  user-select: none;
}

#app {
  max-width: 540px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
}

.phase { display: none; }
.phase.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== 시작 ===== */
.hero { text-align: center; padding: 48px 16px 24px; }
.hero-emoji {
  font-size: 84px;
  margin-bottom: 12px;
  display: inline-block;
  animation: wiggle 3s ease-in-out infinite;
}
@keyframes wiggle {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
}
.hero h1 {
  font-size: 36px;
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}
.lead { color: var(--text-light); font-size: 17px; }

.start-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
}
.footnote { text-align: center; color: var(--text-light); font-size: 13px; padding: 8px; }

.btn-primary, .btn-secondary, .btn-ghost {
  padding: 14px 22px;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.97); }
.btn-secondary {
  background: var(--secondary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-secondary:active { transform: scale(0.97); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
  font-size: 14px;
  padding: 10px 16px;
}
.btn-icon {
  width: 44px; height: 44px;
  border: none;
  background: var(--card);
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.btn-icon:active { transform: scale(0.92); }

/* ===== 게임 헤더 ===== */
.game-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.mission-info {
  flex: 1;
  text-align: center;
}
.mission-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 2px;
}
.mission-num .mission-sep { color: var(--border); margin: 0 4px; }
.mission-info h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

/* ===== 캔버스 ===== */
.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0 auto 16px;
}
#canvas {
  width: 100%;
  height: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: block;
  touch-action: none;
}
.hint-banner {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translate(-50%, 100%);
  background: var(--accent);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  animation: bounce 0.6s ease;
  z-index: 10;
}
@keyframes bounce {
  0%, 100% { transform: translate(-50%, 100%); }
  50% { transform: translate(-50%, 92%); }
}

/* SVG 도형 */
.shape-current {
  transition: transform 0.35s cubic-bezier(0.4, 0.0, 0.2, 1);
  transform-box: fill-box;
  transform-origin: center;
  cursor: grab;
}
.shape-current:active { cursor: grabbing; }
.shape-target {
  opacity: 0.28;
  pointer-events: none;
}
.target-outline {
  fill: var(--target);
  stroke: var(--target-stroke);
  stroke-width: 3;
  stroke-dasharray: 6 4;
  rx: 12;
  ry: 12;
  pointer-events: none;
}
.success-pulse {
  animation: pulse 0.8s ease;
}
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.grid-line { stroke: var(--grid-line); stroke-width: 1; opacity: 0.6; }
.grid-bg { fill: var(--grid-bg); }

/* ===== 컨트롤 ===== */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.control-group {
  background: var(--card);
  padding: 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.control-group[data-op="translate"] {
  grid-row: 1 / 3;
  grid-column: 1;
}
.control-group[data-op="reflect"] { grid-column: 2; grid-row: 1; }
.control-group[data-op="rotate"]  { grid-column: 2; grid-row: 2; }

.control-group.disabled { opacity: 0.4; pointer-events: none; }
.control-label {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-light);
  margin-bottom: 8px;
}

.dpad {
  display: grid;
  grid-template-rows: 44px 44px 44px;
  gap: 4px;
  width: 152px;
  margin: 0 auto;
}
.dpad-mid {
  display: grid;
  grid-template-columns: 44px 64px 44px;
  gap: 0;
  align-items: center;
}
.dpad .up    { grid-column: 2; grid-row: 1; justify-self: center; }
.dpad-mid    { grid-row: 2; }
.dpad .down  { grid-column: 2; grid-row: 3; justify-self: center; }
.btn-dpad {
  width: 44px; height: 44px;
  border: 2px solid var(--border);
  background: #fff8ef;
  border-radius: 10px;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  color: var(--primary-dark);
  font-family: inherit;
}
.btn-dpad:active { transform: scale(0.92); background: var(--accent); }
.dpad-mid .left { grid-column: 1; }
.dpad-mid .right { grid-column: 3; }

.flip-buttons, .rotate-buttons {
  display: flex;
  gap: 6px;
}
.btn-flip, .btn-rot {
  flex: 1;
  height: 44px;
  border: 2px solid var(--border);
  background: #fff8ef;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  color: var(--primary-dark);
  font-family: inherit;
}
.btn-flip:active, .btn-rot:active { transform: scale(0.95); background: var(--accent); }

/* ===== 액션 바 ===== */
.actions-bar {
  display: flex;
  gap: 8px;
}
.actions-bar button { flex: 1; }
#btn-next {
  font-size: 16px;
  padding: 14px;
  animation: nextPop 0.5s ease;
}
@keyframes nextPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== 완료 화면 ===== */
.done-card {
  text-align: center;
  padding: 60px 24px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  margin-top: 40px;
}
.done-emoji {
  font-size: 90px;
  margin-bottom: 14px;
  animation: bounce-big 1.2s ease infinite;
}
@keyframes bounce-big {
  0%, 100% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-12px) rotate(-6deg); }
  75% { transform: translateY(-12px) rotate(6deg); }
}
.done-card h1 { font-size: 32px; color: var(--primary-dark); margin-bottom: 12px; }
.stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin: 28px 0;
  flex-wrap: wrap;
}
.stats > div {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stats strong {
  font-size: 28px;
  color: var(--primary-dark);
  font-weight: 800;
}
.stats span {
  font-size: 13px;
  color: var(--text-light);
}

/* ===== 좁은 화면 ===== */
@media (max-width: 380px) {
  .hero h1 { font-size: 30px; }
  .mission-info h2 { font-size: 16px; }
  .btn-flip, .btn-rot { font-size: 13px; }
}
