/* =============================================
   調色大師 (Color Master) — Stylesheet
   ============================================= */

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

:root {
  --bg-dark: #0c0e1a;
  --glass: rgba(255,255,255,0.06);
  --glass-border: rgba(255,255,255,0.1);
  --text-primary: #f0f0f5;
  --text-secondary: rgba(240,240,245,0.6);
  --text-dim: rgba(240,240,245,0.35);
  --accent: #7c5cfc;
  --accent-glow: rgba(124,92,252,0.4);
  --accent-light: #a78bfa;
  --red: #ff6b6b;
  --green: #51cf66;
  --blue: #339af0;
  --gold: #fcc419;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --transition: 0.3s cubic-bezier(0.4,0,0.2,1);
  --font-main: 'Inter','Noto Sans TC',sans-serif;
}

html, body {
  width: 100%; height: 100%;
  font-family: var(--font-main);
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#bg-canvas { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

/* ---- Flash overlay ---- */
.target-flash {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity 0.4s, visibility 0.4s;
}
.target-flash.active { opacity: 1; visibility: visible; }
.flash-content { display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 1; }
.flash-icon { font-size: 48px; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100%{transform:scale(1);opacity:1} 50%{transform:scale(1.1);opacity:.8} }
.flash-text { font-size: 22px; font-weight: 700; color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,.5); letter-spacing: 2px; }
.flash-countdown { font-size: 56px; font-weight: 900; color: #fff; text-shadow: 0 4px 20px rgba(0,0,0,.5); }

/* ---- Screens ---- */
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px; opacity: 0; visibility: hidden; transform: scale(.96);
  transition: opacity .5s, transform .5s, visibility .5s;
}
.screen.active { opacity: 1; visibility: visible; transform: scale(1); }

/* ---- START ---- */
.logo-container { text-align: center; margin-bottom: 12px; }
.logo-icon { font-size: 64px; animation: float 3s ease-in-out infinite; filter: drop-shadow(0 8px 24px rgba(124,92,252,.35)); }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-10px)} }
.logo-title { font-size: 48px; font-weight: 900; letter-spacing: -1px; background: linear-gradient(135deg,#a78bfa,#7c5cfc 40%,#339af0); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; line-height: 1.2; }
.logo-subtitle { font-size: 13px; font-weight: 600; letter-spacing: 8px; color: var(--text-dim); margin-top: 4px; }
.tagline { color: var(--text-secondary); font-size: 15px; text-align: center; margin-bottom: 28px; font-weight: 300; }

.difficulty-select { margin-bottom: 20px; text-align: center; }
.difficulty-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 3px; margin-bottom: 12px; font-weight: 600; }
.difficulty-options { display: flex; gap: 10px; }
.btn-difficulty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 20px; background: var(--glass); border: 1px solid var(--glass-border); border-radius: var(--radius); color: var(--text-secondary); cursor: pointer; transition: var(--transition); min-width: 105px; backdrop-filter: blur(12px); }
.btn-difficulty:hover { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); transform: translateY(-2px); }
.btn-difficulty.active { background: rgba(124,92,252,.15); border-color: var(--accent); color: var(--text-primary); box-shadow: 0 0 24px var(--accent-glow); }
.diff-icon { font-size: 22px; }
.diff-name { font-size: 14px; font-weight: 700; }
.diff-desc { font-size: 11px; color: var(--text-dim); font-weight: 400; }
.btn-difficulty.active .diff-desc { color: var(--accent-light); }

.rounds-select { margin-bottom: 24px; text-align: center; }
.rounds-options { display: flex; gap: 10px; justify-content: center; }
.btn-rounds { width: 48px; height: 48px; border-radius: 50%; background: var(--glass); border: 1px solid var(--glass-border); color: var(--text-secondary); font-size: 18px; font-weight: 800; font-family: var(--font-main); cursor: pointer; transition: var(--transition); backdrop-filter: blur(12px); }
.btn-rounds:hover { background: rgba(255,255,255,.08); transform: translateY(-2px); }
.btn-rounds.active { background: rgba(124,92,252,.15); border-color: var(--accent); color: var(--text-primary); box-shadow: 0 0 24px var(--accent-glow); }

.btn-start { padding: 14px 52px; font-size: 17px; font-weight: 700; color: #fff; background: linear-gradient(135deg,#7c5cfc,#5b3cc4); border: none; border-radius: 50px; cursor: pointer; transition: var(--transition); box-shadow: 0 4px 24px var(--accent-glow); font-family: var(--font-main); letter-spacing: 1px; }
.btn-start:hover { transform: translateY(-3px) scale(1.03); box-shadow: 0 8px 36px rgba(124,92,252,.55); }
.btn-start:active { transform: translateY(0) scale(.98); }

/* ---- GAME ---- */
#screen-game { justify-content: flex-start; padding-top: 12px; }
.game-header { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 600px; padding: 10px 16px; background: var(--glass); border: 1px solid var(--glass-border); border-radius: var(--radius); backdrop-filter: blur(16px); margin-bottom: 10px; flex-shrink: 0; transition: opacity .3s, visibility .3s; }
.game-header.header-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.game-body.hard-mode .game-header { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20; width: auto; min-width: 280px; }
.header-left { display: flex; align-items: baseline; gap: 4px; }
.round-badge { font-size: 16px; font-weight: 800; color: var(--accent-light); }
.round-total { font-size: 12px; color: var(--text-dim); font-weight: 500; }

.timer-container { position: relative; width: 40px; height: 40px; display: none; }
.timer-container.visible { display: flex; align-items: center; justify-content: center; }
.timer-ring { position: absolute; width: 40px; height: 40px; transform: rotate(-90deg); }
.timer-bg { fill: none; stroke: rgba(255,255,255,.08); stroke-width: 3; }
.timer-fg { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 106.81; stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear, stroke .3s; }
.timer-fg.danger { stroke: var(--red); }
.timer-text { font-size: 14px; font-weight: 800; color: var(--text-primary); z-index: 1; }
.timer-text.danger { color: var(--red); }
.header-right { display: flex; align-items: baseline; gap: 5px; }
.score-label { font-size: 11px; color: var(--text-dim); font-weight: 500; }
.score-value { font-size: 20px; font-weight: 800; color: var(--gold); }

.game-body { display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 600px; gap: 10px; flex: 1; min-height: 0; }

/* Color compare */
.color-compare { display: flex; align-items: center; gap: 12px; width: 100%; flex-shrink: 0; }
.color-compare.hidden-hard { display: none; }
.color-card { flex: 1; background: var(--glass); border: 1px solid var(--glass-border); border-radius: var(--radius); padding: 10px; text-align: center; backdrop-filter: blur(12px); }
.color-swatch { width: 100%; aspect-ratio: 1.6; border-radius: var(--radius-sm); background: #808080; margin-bottom: 6px; box-shadow: inset 0 2px 8px rgba(0,0,0,.25); transition: background-color .1s; position: relative; overflow: hidden; }
.color-swatch::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 1px 0 rgba(255,255,255,.1); pointer-events: none; }
.color-card.target-hidden .color-swatch { background: repeating-conic-gradient(rgba(255,255,255,.06) 0% 25%, rgba(255,255,255,.02) 0% 50%) 50%/20px 20px !important; }
.color-card.target-hidden .color-hex { color: var(--text-dim); }
.color-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 2px; }
.color-hex { font-size: 13px; font-weight: 700; font-family: 'JetBrains Mono','Fira Code',monospace; color: var(--text-primary); letter-spacing: 1px; }
.vs-badge { font-size: 14px; font-weight: 900; color: var(--text-dim); flex-shrink: 0; letter-spacing: 2px; }

/* Similarity */
.similarity-bar-container { width: 100%; transition: opacity .3s, max-height .3s; overflow: hidden; flex-shrink: 0; }
.similarity-bar-container.hidden { opacity: 0; max-height: 0; margin: 0; pointer-events: none; }
.similarity-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
.similarity-value { font-weight: 800; color: var(--accent-light); transition: color var(--transition); }
.similarity-bar { width: 100%; height: 6px; background: rgba(255,255,255,.06); border-radius: 100px; overflow: hidden; }
.similarity-fill { height: 100%; width: 0%; border-radius: 100px; background: linear-gradient(90deg,var(--red),var(--gold),var(--green)); transition: width .15s; position: relative; }
.similarity-fill::after { content: ''; position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 0 8px rgba(255,255,255,.4); opacity: 0; transition: opacity .2s; }
.similarity-fill.has-value::after { opacity: 1; }

/* ---- Picker ---- */
.picker-container { display: flex; gap: 12px; align-items: stretch; padding: 12px; background: var(--glass); border: 1px solid var(--glass-border); border-radius: var(--radius); backdrop-filter: blur(12px); user-select: none; touch-action: none; flex-shrink: 0; }
.picker-main-wrap { position: relative; width: 260px; height: 260px; border-radius: var(--radius-sm); overflow: hidden; cursor: crosshair; box-shadow: inset 0 2px 6px rgba(0,0,0,.3); }
.picker-canvas { display: block; width: 100%; height: 100%; border-radius: inherit; }
.picker-cursor { position: absolute; width: 20px; height: 20px; border: 3px solid #fff; border-radius: 50%; transform: translate(-50%,-50%); pointer-events: none; box-shadow: 0 0 4px rgba(0,0,0,.5), inset 0 0 2px rgba(0,0,0,.3); top: 50%; left: 50%; z-index: 2; }
.picker-hue-wrap { position: relative; width: 28px; height: 260px; border-radius: 14px; overflow: hidden; cursor: pointer; box-shadow: inset 0 2px 6px rgba(0,0,0,.3); }
.picker-hue { display: block; width: 100%; height: 100%; border-radius: inherit; }
.hue-cursor { position: absolute; left: -3px; right: -3px; height: 8px; border: 3px solid #fff; border-radius: 4px; transform: translateY(-50%); pointer-events: none; box-shadow: 0 0 4px rgba(0,0,0,.5); top: 0; z-index: 2; }

/* Hard mode fullscreen picker */
.picker-container.fullscreen-picker {
  position: fixed; inset: 0; z-index: 10;
  padding: 0; border-radius: 0; border: none;
  background: transparent; backdrop-filter: none;
}
.picker-container.fullscreen-picker .picker-main-wrap {
  width: 100%; height: 100%; border-radius: 0;
}

.btn-confirm { padding: 12px 44px; font-size: 15px; font-weight: 700; color: #fff; background: linear-gradient(135deg,#7c5cfc,#5b3cc4); border: none; border-radius: 50px; cursor: pointer; transition: var(--transition); box-shadow: 0 4px 20px var(--accent-glow); font-family: var(--font-main); letter-spacing: .5px; flex-shrink: 0; z-index: 20; }
.btn-confirm:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 6px 28px rgba(124,92,252,.5); }
.btn-confirm:active { transform: translateY(0) scale(.97); }

/* Hard mode: confirm floats at bottom */
.game-body.hard-mode .btn-confirm {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
  z-index: 20; box-shadow: 0 4px 24px rgba(0,0,0,.5), 0 0 20px var(--accent-glow);
}
.game-body.hard-mode .btn-confirm:hover { transform: translateX(-50%) translateY(-2px) scale(1.02); }

/* ---- RESULT ---- */
.result-card { text-align: center; padding: 32px; background: var(--glass); border: 1px solid var(--glass-border); border-radius: 24px; backdrop-filter: blur(20px); animation: popIn .5s cubic-bezier(.34,1.56,.64,1); min-width: 300px; }
@keyframes popIn { 0%{opacity:0;transform:scale(.8) translateY(20px)} 100%{opacity:1;transform:scale(1) translateY(0)} }
.result-emoji { font-size: 56px; margin-bottom: 6px; animation: bounce .6s ease; }
@keyframes bounce { 0%,100%{transform:translateY(0)} 40%{transform:translateY(-18px)} 60%{transform:translateY(-6px)} }
.result-score-big { font-size: 64px; font-weight: 900; background: linear-gradient(135deg,var(--gold),#f59f00); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; line-height: 1.1; }
.result-text { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 20px; }
.result-colors { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 24px; }
.result-swatch-group { text-align: center; }
.result-swatch { width: 56px; height: 56px; border-radius: var(--radius-sm); margin-bottom: 4px; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.result-swatch-group span { font-size: 11px; color: var(--text-dim); font-weight: 500; }
.result-arrow { font-size: 18px; color: var(--text-dim); margin-top: -18px; }
.btn-next { padding: 11px 36px; font-size: 14px; font-weight: 700; color: #fff; background: linear-gradient(135deg,#7c5cfc,#5b3cc4); border: none; border-radius: 50px; cursor: pointer; transition: var(--transition); font-family: var(--font-main); box-shadow: 0 4px 20px var(--accent-glow); }
.btn-next:hover { transform: translateY(-2px); box-shadow: 0 6px 28px rgba(124,92,252,.5); }

/* ---- FINAL ---- */
.final-card { text-align: center; padding: 32px; background: var(--glass); border: 1px solid var(--glass-border); border-radius: 24px; backdrop-filter: blur(20px); animation: popIn .5s cubic-bezier(.34,1.56,.64,1); min-width: 320px; }
.final-trophy { font-size: 56px; margin-bottom: 6px; }
.final-title { font-size: 24px; font-weight: 800; margin-bottom: 20px; color: var(--text-primary); }
.final-score-container { display: flex; justify-content: center; margin-bottom: 12px; }
.final-score-ring { position: relative; width: 120px; height: 120px; }
.final-score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255,255,255,.06); stroke-width: 8; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 326.73; stroke-dashoffset: 326.73; transition: stroke-dashoffset 1.5s cubic-bezier(.4,0,.2,1); }
.final-score-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.final-score-num { font-size: 28px; font-weight: 900; color: var(--text-primary); }
.final-score-max { font-size: 11px; color: var(--text-dim); font-weight: 500; }
.final-grade { font-size: 42px; font-weight: 900; margin: 6px 0; background: linear-gradient(135deg,var(--gold),#f59f00); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.final-message { font-size: 15px; color: var(--text-secondary); margin-bottom: 16px; font-weight: 500; }
.final-stats { display: flex; justify-content: center; gap: 20px; margin-bottom: 24px; flex-wrap: wrap; }
.stat-item { text-align: center; }
.stat-value { display: block; font-size: 18px; font-weight: 800; color: var(--accent-light); }
.stat-label { font-size: 10px; color: var(--text-dim); font-weight: 500; text-transform: uppercase; letter-spacing: 1px; }
.btn-restart { padding: 12px 40px; font-size: 15px; font-weight: 700; color: #fff; background: linear-gradient(135deg,#7c5cfc,#5b3cc4); border: none; border-radius: 50px; cursor: pointer; transition: var(--transition); font-family: var(--font-main); box-shadow: 0 4px 20px var(--accent-glow); }
.btn-restart:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 6px 28px rgba(124,92,252,.5); }

/* Confetti */
.confetti { position: fixed; z-index: 100; pointer-events: none; width: 10px; height: 10px; border-radius: 2px; animation: confettiFall 1.2s ease-out forwards; }
@keyframes confettiFall { 0%{opacity:1;transform:translateY(0) rotate(0) scale(1)} 100%{opacity:0;transform:translateY(120vh) rotate(720deg) scale(.5)} }

/* ---- Mobile RWD (9:16) ---- */
@media (max-width: 640px) {
  .screen { padding: 14px; }
  .logo-icon { font-size: 48px; }
  .logo-title { font-size: 36px; }
  .tagline { font-size: 13px; margin-bottom: 20px; }
  .difficulty-options { flex-direction: column; align-items: center; }
  .btn-difficulty { min-width: 220px; flex-direction: row; gap: 10px; padding: 10px 18px; }
  .color-compare { gap: 8px; }
  .vs-badge { display: none; }
  .color-card { padding: 8px; }
  .color-swatch { aspect-ratio: 1.4; margin-bottom: 4px; }
  .color-label { font-size: 11px; }
  .color-hex { font-size: 12px; }
  .picker-container { padding: 8px; }
  .picker-main-wrap { width: 240px; height: 240px; }
  .result-card, .final-card { min-width: auto; width: 100%; padding: 24px; }
  .result-score-big { font-size: 52px; }
  .final-score-ring { width: 100px; height: 100px; }
  .game-body.hard-mode .btn-confirm { bottom: 28px; }
}

@media (max-width: 400px) {
  .logo-title { font-size: 30px; }
  .picker-main-wrap { width: 200px; height: 200px; }
  .btn-difficulty { min-width: 190px; }
}

@media (max-height: 700px) {
  #screen-game { padding-top: 6px; }
  .game-header { padding: 8px 14px; margin-bottom: 6px; }
  .game-body { gap: 6px; }
  .color-swatch { aspect-ratio: 1.2; }
  .picker-main-wrap { width: 220px; height: 220px; }
}
