/* 008-makefriends — 8-bit RPG style */

:root {
  --bg: #0d0a1a;
  --card-bg: #ffffff;
  --border: #c084fc;
  --border-dim: #e9d5ff;
  --primary: #9333ea;
  --accent: #f472b6;
  --pink: #ec4899;
  --yellow: #d97706;
  --text: #3b0764;
  --text-dim: #7e22ce;
  --pixel-font: 'Press Start 2P', monospace;
  --body-font: 'Noto Sans TC', -apple-system, sans-serif;
}

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

body {
  font-family: var(--body-font);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  padding: 1rem;
  position: relative;
  overflow-x: hidden;
}

/* 掃描線 */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
}

.container {
  width: 100%;
  max-width: 440px;
  position: relative;
  z-index: 1;
}

/* Screens */
.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: screenIn 0.3s ease;
}

@keyframes screenIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Pixel box — double border RPG style */
.pixel-box {
  background: var(--card-bg);
  border: 3px solid var(--border);
  box-shadow:
    0 0 0 3px var(--card-bg),
    0 0 0 6px var(--border-dim),
    0 0 30px rgba(192, 132, 252, 0.18);
  padding: 1.75rem 1.25rem;
  position: relative;
}

.pixel-box-inner {
  background: #f5f0ff;
  border: 2px solid var(--border-dim);
  padding: 1rem;
}

/* ═══ Start Screen ═══ */
.main-card {
  text-align: center;
  padding: 2.5rem 1.25rem;
}

.title {
  font-family: 'M PLUS Rounded 1c', var(--body-font);
  font-size: clamp(1.73rem, 7.5vw, 2.03rem);
  font-weight: 400;
  line-height: 1.3;
  white-space: normal;
  margin-bottom: 1rem;
  background-image:
    radial-gradient(circle 1.5px at  8% 20%, #fff 0%, transparent 100%),
    radial-gradient(circle 1px   at 18% 70%, #fff 0%, transparent 100%),
    radial-gradient(circle 2px   at 25% 40%, #fff 0%, transparent 100%),
    radial-gradient(circle 1px   at 33% 15%, #e0d0ff 0%, transparent 100%),
    radial-gradient(circle 1.5px at 40% 80%, #fff 0%, transparent 100%),
    radial-gradient(circle 1px   at 47% 30%, #fff 0%, transparent 100%),
    radial-gradient(circle 2px   at 53% 60%, #c4b5fd 0%, transparent 100%),
    radial-gradient(circle 1px   at 60% 10%, #fff 0%, transparent 100%),
    radial-gradient(circle 1.5px at 65% 85%, #fff 0%, transparent 100%),
    radial-gradient(circle 1px   at 72% 45%, #e0d0ff 0%, transparent 100%),
    radial-gradient(circle 2px   at 78% 25%, #fff 0%, transparent 100%),
    radial-gradient(circle 1px   at 83% 65%, #fff 0%, transparent 100%),
    radial-gradient(circle 1.5px at 88% 50%, #c4b5fd 0%, transparent 100%),
    radial-gradient(circle 1px   at 93% 15%, #fff 0%, transparent 100%),
    radial-gradient(circle 1px   at 97% 80%, #fff 0%, transparent 100%),
    radial-gradient(circle 1px   at 12% 50%, #e0d0ff 0%, transparent 100%),
    radial-gradient(circle 1.5px at 56% 50%, #fff 0%, transparent 100%),
    radial-gradient(circle 1px   at 43% 55%, #fff 0%, transparent 100%),
    linear-gradient(135deg, #0d0a1a 0%, #1e0a4a 40%, #0d1a3a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-image {
  margin: 2rem 0;
  font-size: 3rem;
  animation: float 2s ease-in-out infinite alternate;
}

@keyframes float {
  from { transform: translateY(0); }
  to { transform: translateY(-10px); }
}

/* ═══ Buttons ═══ */
.btn-pixel {
  font-family: var(--pixel-font);
  font-size: 0.7rem;
  padding: 0.9rem 2rem;
  border: 3px solid var(--primary);
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  letter-spacing: 0.15em;
  transition: all 0.1s;
  position: relative;
}

#btn-start {
  font-size: 0.875rem;
  font-weight: 700;
}


.btn-pixel:active {
  background: var(--primary);
  color: #fff;
  transform: translate(2px, 2px);
}

.btn-small {
  font-size: 0.87rem;
  font-weight: 700;
  padding: 0.65rem 1.5rem;
}

/* ═══ Stars canvas ═══ */
#stars-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ═══ Question Screen ═══ */
.progress-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: #f3e8ff;
  border: 2px solid var(--border-dim);
  border-radius: 4px;
  overflow: hidden;
}

.progress-label {
  font-family: var(--pixel-font);
  font-size: 0.45rem;
  color: #e9d5ff;
  white-space: nowrap;
  flex-shrink: 0;
}

.progress-inner {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.3s ease;
}

.quiz-content {
  text-align: left;
}

.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.q-num {
  font-family: var(--pixel-font);
  font-size: 0.6rem;
  color: var(--yellow);
}

.btn-prev {
  font-family: var(--pixel-font);
  font-size: 0.5rem;
  padding: 0.4rem 0.75rem;
  border: 2px solid #a78bfa;
  background: transparent;
  color: #e9d5ff;
  cursor: pointer;
  letter-spacing: 0.1em;
  transition: all 0.15s;
}


.dialog-box {
  background: #ffffff;
  border: 2px solid var(--border-dim);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.question-text {
  font-size: 1.125rem;
  line-height: 1.7;
  font-weight: 700;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.option-btn {
  padding: 1rem;
  background: #ffffff;
  border: 2px solid var(--border-dim);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-family: var(--body-font);
  font-size: 1.025rem;
  transition: all 0.2s;
}


.option-btn.selected {
  background: #f5f0ff;
  border-color: var(--primary);
  color: #1a0040;
  animation: optionPop 0.2s ease;
}

@keyframes optionPop {
  0%   { transform: translateX(5px) scale(1); }
  50%  { transform: translateX(5px) scale(1.02); }
  100% { transform: translateX(5px) scale(1); }
}

/* ═══ Result Screen ═══ */
.result-card {
  text-align: center;
}

.result-label {
  font-family: var(--pixel-font);
  font-size: 0.5rem;
  color: var(--yellow);
  letter-spacing: 0.2em;
  margin-bottom: 1rem;
}

.result-title-box h2 {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(90deg, #9333ea, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 0.85rem;
  color: #374151;
  font-style: italic;
  margin-bottom: 1.5rem;
}

/* ═══ 組成元素 Tags ═══ */
.tags-section {
  margin: 1.25rem 0 0.25rem;
  text-align: left;
}

.result-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.result-tag {
  display: inline-block;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: linear-gradient(135deg, #f3e8ff, #fce7f3);
  border: 1.5px solid #c084fc;
  color: #6b21a8;
  letter-spacing: 0.03em;
  line-height: 1.4;
}

/* snapshot 模式下 tag 顏色固定 */
.screen.snapshot-mode .result-tag {
  background: #ede9fe;
  border-color: #a855f7;
  color: #581c87;
}

.stats-section {
  margin: 1.5rem 0;
  text-align: left;
}

.stats-label {
  font-family: var(--pixel-font);
  font-size: 0.65rem;
  color: var(--yellow);
  margin-bottom: 0.5rem;
}

.typical-text {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.apps-section {
  margin-bottom: 1.5rem;
  text-align: left;
}

.apps-label {
  font-family: var(--pixel-font);
  font-size: 0.65rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

#result-apps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.app-rec {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  padding: 0.75rem 0.5rem;
  background: #fff;
  border: 1.5px solid var(--border-dim);
  border-radius: 8px;
}

.app-icon-wrap {
  position: relative;
  flex-shrink: 0;
}

.app-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: block;
  border: 2px solid var(--border-dim);
  background: #fff;
  object-fit: cover;
}

.app-icon-wrap:hover::after {
  content: attr(data-name);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg);
  border: 1px solid var(--border-dim);
  color: var(--text);
  font-size: 0.7rem;
  padding: 3px 8px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}

.app-text {
  width: 100%;
}

.app-rec strong,
.app-name-link {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.25rem;
  text-decoration: none;
}

.app-name-link:hover {
  text-decoration: underline;
  color: var(--pink);
}

.app-rec span {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.result-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  margin-top: 2rem;
}

.result-actions-row {
  display: flex;
  gap: 0.75rem;
}

.result-actions-row .btn-pixel {
  flex: 1;
}

.btn-dark {
  background: #111;
  color: #fff;
  border-color: #111;
}


#btn-save {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}


/* ═══ Mobile tweaks ═══ */
@media (max-width: 380px) {
  .pixel-box {
    padding: 1.25rem 1rem;
  }
}

/* iOS safe area */
.result-actions {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ═══ 下載快照（純色不透明，避免 html2canvas 霧化）═══ */
.screen.snapshot-mode .result-actions {
  display: none;
}
.screen.snapshot-mode .pixel-box {
  background: #f0d9ff;
  border-color: #9333ea;
  box-shadow: 0 0 0 3px #f0d9ff, 0 0 0 6px #a855f7;
}
.screen.snapshot-mode .pixel-box-inner {
  background: #e4c4ff;
  border-color: #a855f7;
}
.screen.snapshot-mode .result-label {
  color: #92400e;
}
.screen.snapshot-mode .result-title-box h2 {
  color: #6b21a8;
  text-shadow: 2px 2px 0 #c084fc;
}
#result-tagline {
  font-weight: 700;
}

.screen.snapshot-mode #result-tagline {
  color: #be185d;
}
.screen.snapshot-mode #result-desc {
  color: #3b0764;
}
.screen.snapshot-mode .stats-label {
  color: #92400e;
}
.screen.snapshot-mode .typical-text {
  color: #4c1d95;
}
.screen.snapshot-mode .apps-label {
  color: #9d174d;
}
.screen.snapshot-mode .app-rec strong {
  color: #6b21a8;
}
.screen.snapshot-mode .app-rec span {
  color: #4c1d95;
}

/* ═══ 魔法變身動畫 ═══ */
.magic-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  background: radial-gradient(ellipse at center, rgba(88, 28, 135, 0.88) 0%, rgba(13, 10, 26, 0.92) 100%);
  animation: magicBgIn 0.4s ease forwards;
  pointer-events: none;
}

.magic-overlay.magic-leaving {
  animation: magicBgOut 0.7s ease forwards;
}

@keyframes magicBgIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes magicBgOut {
  0%   { opacity: 1; }
  40%  { opacity: 1; }
  100% { opacity: 0; }
}

/* 中心水晶球 */
.magic-center {
  font-size: 5rem;
  position: relative;
  z-index: 3;
  animation: magicOrb 1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  filter: drop-shadow(0 0 20px rgba(192, 132, 252, 0.9)) drop-shadow(0 0 40px rgba(236, 72, 153, 0.6));
}

@keyframes magicOrb {
  0%   { transform: scale(0) rotate(-30deg); opacity: 0; filter: blur(8px); }
  50%  { transform: scale(1.2) rotate(10deg); opacity: 1; filter: blur(0); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* 魔法陣光環 */
.magic-ring {
  position: absolute;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 2px solid rgba(192, 132, 252, 0.7);
  box-shadow: 0 0 15px rgba(192, 132, 252, 0.5), inset 0 0 15px rgba(192, 132, 252, 0.2);
  animation: ringExpand 1.4s cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
  z-index: 2;
}

.magic-ring-2 {
  width: 220px;
  height: 220px;
  border-color: rgba(236, 72, 153, 0.5);
  box-shadow: 0 0 12px rgba(236, 72, 153, 0.4);
  animation: ringExpand 1.4s 0.15s cubic-bezier(0.2, 0.8, 0.4, 1) forwards, ringRotate 3s linear infinite;
  border-style: dashed;
}

@keyframes ringExpand {
  0%   { transform: scale(0); opacity: 0; }
  30%  { opacity: 1; }
  100% { transform: scale(1); opacity: 0.85; }
}

@keyframes ringRotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* 符文文字環 */
.magic-rune-ring {
  position: absolute;
  font-size: 0.7rem;
  color: rgba(192, 132, 252, 0.65);
  letter-spacing: 0.5rem;
  white-space: nowrap;
  z-index: 2;
  animation: runeAppear 0.5s 0.3s ease forwards, runeRotate 4s 0.3s linear infinite;
  opacity: 0;
  transform-origin: center;
}

@keyframes runeAppear {
  to { opacity: 1; }
}

@keyframes runeRotate {
  from { transform: rotate(0deg) translateY(-105px) rotate(0deg); }
  to   { transform: rotate(360deg) translateY(-105px) rotate(-360deg); }
}

/* 粒子射出 */
.magic-spark {
  position: absolute;
  animation: sparkShoot 1.1s 0.25s ease forwards;
  opacity: 0;
  z-index: 4;
}

@keyframes sparkShoot {
  0%   { transform: translate(0, 0) scale(0); opacity: 0; }
  20%  { opacity: 1; }
  60%  { opacity: 0.9; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0.5); opacity: 0; }
}

/* 閃光 */
.magic-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.35) 0%, transparent 70%);
  animation: flashPulse 1.8s ease forwards;
  z-index: 1;
}

@keyframes flashPulse {
  0%   { opacity: 0; }
  25%  { opacity: 1; }
  60%  { opacity: 0.3; }
  100% { opacity: 0; }
}
