/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0D0806;
  --bg-mid: #1A0F0A;
  --gold: #D4AF37;
  --gold-light: #F0D060;
  --gold-dim: #8B7020;
  --gold-pale: #EDD88A;
  --red: #8B1A1A;
  --red-light: #C23030;
  --cream: #E8D5B7;
  --cream-dim: #A09070;
  --ember: #FF6020;
  --smoke-col: rgba(210, 200, 190, 0.55);
  --font-serif: 'Noto Serif SC', Georgia, 'Times New Roman', serif;
  --radius: 12px;
  --transition: 0.25s ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: var(--font-serif);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ===== AMBIENT BACKGROUND ===== */
.ambient-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(139,26,26,0.22) 0%, transparent 70%),
    radial-gradient(ellipse 80% 60% at 50% 100%, rgba(80,40,10,0.28) 0%, transparent 60%),
    linear-gradient(180deg, #0D0806 0%, #140C06 40%, #0D0806 100%);
  z-index: 0;
  pointer-events: none;
}

.particles-bg {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.bg-particle {
  position: absolute;
  border-radius: 50%;
  background: var(--gold);
  animation: particleDrift linear infinite;
}

@keyframes particleDrift {
  0%   { transform: translateY(100vh) scale(0.5); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translateY(-20px) scale(1.2); opacity: 0; }
}

/* ===== LANGUAGE BAR ===== */
.lang-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px 6px;
  background: linear-gradient(to bottom, rgba(13,8,6,0.95) 0%, transparent 100%);
}

.lang-btn {
  background: none;
  border: 1px solid rgba(212,175,55,0.3);
  color: var(--cream-dim);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-serif);
  letter-spacing: 0.03em;
}

.lang-btn:hover,
.lang-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(212,175,55,0.1);
}

/* ===== MERIT HEADER ===== */
.merit-header {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: 52px 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.merit-total-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.merit-number {
  font-size: clamp(2.8rem, 8vw, 4.5rem);
  font-weight: 900;
  color: var(--gold-light);
  text-shadow: 0 0 30px rgba(240,208,96,0.5), 0 0 60px rgba(212,175,55,0.2);
  line-height: 1;
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.merit-number.bump {
  transform: scale(1.08);
}

.merit-unit {
  font-size: clamp(1rem, 3vw, 1.4rem);
  color: var(--gold-dim);
  font-weight: 400;
  letter-spacing: 0.12em;
}

.rank-badge {
  font-size: 0.85rem;
  color: var(--gold);
  border: 1px solid rgba(212,175,55,0.4);
  padding: 3px 14px;
  border-radius: 20px;
  letter-spacing: 0.15em;
  background: rgba(212,175,55,0.06);
  transition: var(--transition);
}

.today-row {
  font-size: 0.72rem;
  color: var(--cream-dim);
  letter-spacing: 0.05em;
}

.today-num {
  color: var(--gold-pale);
}

/* ===== MAIN LAYOUT ===== */
main {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 8px 20px 100px;
  min-height: calc(100vh - 130px);
}

@media (min-width: 720px) {
  main {
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 60px;
    padding-top: 20px;
  }
}

/* ===== FISH SECTION ===== */
.fish-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.tap-hint {
  font-size: 0.8rem;
  color: var(--cream-dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.7;
  animation: hintPulse 3s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.9; }
}

.fish-outer {
  position: relative;
  width: min(280px, 72vw);
  height: min(280px, 72vw);
  display: flex;
  align-items: center;
  justify-content: center;
}

.fish-halo {
  position: absolute;
  inset: -20px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212,175,55,0.12) 0%, transparent 70%);
  animation: haloPulse 4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes haloPulse {
  0%, 100% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.1); opacity: 1; }
}

.wooden-fish {
  width: 100%;
  height: 100%;
  cursor: pointer;
  user-select: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease;
  -webkit-user-select: none;
}

.wooden-fish:active {
  transform: scale(0.94);
}

.wooden-fish.clicked {
  animation: fishTap 0.35s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes fishTap {
  0%   { transform: scale(1) rotate(0deg); }
  20%  { transform: scale(0.91) rotate(-1.5deg); }
  50%  { transform: scale(1.05) rotate(1deg); }
  75%  { transform: scale(0.98) rotate(-0.5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.fish-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 18px rgba(212,175,55,0.15));
  transition: filter 0.2s ease;
}

.wooden-fish:hover .fish-svg {
  filter: drop-shadow(0 0 28px rgba(212,175,55,0.3));
}

/* Click FX layer */
.click-fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(212,175,55,0.75);
  transform: translate(-50%, -50%);
  animation: rippleOut 0.8s ease-out forwards;
}

@keyframes rippleOut {
  0%   { width: 40px; height: 40px; opacity: 1; }
  100% { width: 200px; height: 200px; opacity: 0; }
}

.merit-float {
  position: absolute;
  transform: translate(-50%, -50%);
  color: var(--gold-light);
  font-size: 1.1rem;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
  text-shadow: 0 0 10px rgba(240,208,96,0.8);
  animation: floatMerit 1.1s ease-out forwards;
}

@keyframes floatMerit {
  0%   { opacity: 1; transform: translate(-50%, -50%); }
  30%  { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx,0px)), calc(-50% - 90px)); }
}

/* ===== INCENSE SECTION ===== */
.incense-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 320px;
}

.incense-title {
  font-size: 1.1rem;
  color: var(--gold);
  letter-spacing: 0.25em;
  font-weight: 400;
  text-align: center;
  opacity: 0.85;
}

.incense-scene {
  position: relative;
  height: 220px;
  width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

/* Smoke area */
.smoke-area {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 160px;
  pointer-events: none;
}

.smoke-particle {
  position: absolute;
  border-radius: 50%;
  background: var(--smoke-col);
  filter: blur(5px);
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  animation: smokeRise var(--dur, 3s) ease-out forwards;
}

@keyframes smokeRise {
  0% {
    opacity: 0.7;
    transform: translateX(-50%) translateY(0) scale(0.6);
  }
  40% {
    opacity: 0.5;
    transform: translateX(calc(-50% + var(--dx1, 8px))) translateY(-55px) scale(1.4);
  }
  80% {
    opacity: 0.2;
    transform: translateX(calc(-50% + var(--dx2, -12px))) translateY(-110px) scale(2.2);
  }
  100% {
    opacity: 0;
    transform: translateX(calc(-50% + var(--dx2, -12px))) translateY(-155px) scale(3);
  }
}

/* Incense stick group */
.incense-group {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.incense-stick {
  width: 5px;
  height: 160px;
  background: linear-gradient(to bottom, #8B6914 0%, #5C3D1E 60%, #3D2010 100%);
  border-radius: 3px 3px 0 0;
  position: relative;
  overflow: hidden;
}

.stick-ash {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 0%;
  background: linear-gradient(to bottom, #888 0%, #777 70%, #666 100%);
  border-radius: 3px 3px 0 0;
  transition: height 1s linear;
}

.incense-ember {
  width: 9px;
  height: 9px;
  background: radial-gradient(circle, #FFA030, #FF6010);
  border-radius: 50%;
  position: relative;
  z-index: 2;
  box-shadow: 0 0 8px #FF7020, 0 0 18px rgba(255,112,32,0.6);
  animation: emberPulse 2s ease-in-out infinite;
  margin-bottom: -1px;
}

@keyframes emberPulse {
  0%, 100% { box-shadow: 0 0 7px #FF7020, 0 0 15px rgba(255,112,32,0.5); }
  50% { box-shadow: 0 0 13px #FF9030, 0 0 26px rgba(255,144,48,0.75); }
}

.incense-holder {
  width: 38px;
  height: 16px;
  background: linear-gradient(to bottom, #5C3A1A, #3A2010);
  border-radius: 4px 4px 8px 8px;
  position: relative;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

.holder-sand {
  position: absolute;
  top: 2px; left: 4px; right: 4px; bottom: 2px;
  background: linear-gradient(to bottom, #C8A86A, #A08040);
  border-radius: 3px 3px 6px 6px;
}

/* Candle group */
.candle-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  position: relative;
}

.candle-flame-wrap {
  position: relative;
  width: 20px;
  height: 36px;
  margin-bottom: -2px;
}

.candle-flame {
  position: absolute;
  bottom: 0;
  left: 50%; transform: translateX(-50%);
  width: 16px;
  height: 30px;
  background: radial-gradient(ellipse at 50% 80%, #FFDD00, #FF8800 50%, transparent 100%);
  border-radius: 50% 50% 30% 30% / 60% 60% 40% 40%;
  animation: flameWave 1.8s ease-in-out infinite alternate;
  filter: blur(1px);
}

.candle-flame-inner {
  position: absolute;
  bottom: 3px;
  left: 50%; transform: translateX(-50%);
  width: 7px;
  height: 16px;
  background: rgba(255,255,220,0.9);
  border-radius: 50% 50% 30% 30%;
  animation: flameWave 1.8s ease-in-out infinite alternate-reverse;
}

@keyframes flameWave {
  0%  { transform: translateX(-50%) scaleX(1) scaleY(1) rotate(-1deg); }
  100%{ transform: translateX(-50%) scaleX(0.88) scaleY(1.06) rotate(2deg); }
}

.candle-body {
  width: 28px;
  height: 120px;
  background: linear-gradient(to right, #F5F0E8 0%, #EDE5D0 40%, #D8D0BC 100%);
  border-radius: 3px 3px 0 0;
  position: relative;
  box-shadow: inset -4px 0 8px rgba(0,0,0,0.12);
  transition: height 1s linear;
}

.candle-drip {
  width: 34px;
  height: 10px;
  background: linear-gradient(to bottom, #E8E0CC, #D0C8B4);
  border-radius: 0 0 50% 50%;
  margin-top: -4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.candle-base {
  width: 44px;
  height: 18px;
  background: linear-gradient(to bottom, #C8B890, #A09060);
  border-radius: 4px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
}

/* ===== CONTROLS ===== */
.incense-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.duration-row {
  display: flex;
  gap: 8px;
}

.dur-btn {
  background: rgba(212,175,55,0.06);
  border: 1px solid rgba(212,175,55,0.25);
  color: var(--cream-dim);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: var(--font-serif);
  transition: var(--transition);
}

.dur-btn:hover,
.dur-btn.selected {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(212,175,55,0.12);
}

.light-btn {
  background: linear-gradient(135deg, #8B1A1A 0%, #C23030 50%, #8B1A1A 100%);
  border: 1px solid rgba(212,175,55,0.4);
  color: var(--gold-pale);
  padding: 12px 32px;
  border-radius: 30px;
  font-size: 1rem;
  font-family: var(--font-serif);
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 20px rgba(139,26,26,0.4), 0 0 0 1px rgba(212,175,55,0.15);
}

.light-btn:hover {
  box-shadow: 0 6px 28px rgba(194,48,48,0.55), 0 0 0 1px rgba(212,175,55,0.3);
  transform: translateY(-1px);
}

.light-btn:active {
  transform: translateY(0);
}

/* Timer row */
.timer-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.timer-display {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--gold-light);
  letter-spacing: 0.05em;
  text-shadow: 0 0 20px rgba(240,208,96,0.4);
  font-variant-numeric: tabular-nums;
}

.burning-hint {
  font-size: 0.75rem;
  color: var(--cream-dim);
  letter-spacing: 0.1em;
  opacity: 0.75;
  animation: hintPulse 4s ease-in-out infinite;
}

.extinguish-btn {
  background: none;
  border: 1px solid rgba(140,100,60,0.4);
  color: var(--cream-dim);
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-family: var(--font-serif);
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.1em;
}

.extinguish-btn:hover {
  border-color: var(--cream-dim);
  color: var(--cream);
}

/* ===== CERTIFICATE FAB ===== */
.cert-fab {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 50;
  background: linear-gradient(135deg, #2A1A05 0%, #4A2E08 100%);
  border: 1px solid rgba(212,175,55,0.5);
  color: var(--gold);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-family: var(--font-serif);
  cursor: pointer;
  letter-spacing: 0.08em;
  box-shadow: 0 4px 18px rgba(0,0,0,0.5);
  transition: var(--transition);
  animation: fabAppear 0.5s cubic-bezier(0.34,1.56,0.64,1) both;
}

@keyframes fabAppear {
  from { transform: scale(0) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.cert-fab:hover {
  box-shadow: 0 6px 24px rgba(212,175,55,0.25), 0 4px 18px rgba(0,0,0,0.5);
  transform: translateY(-2px);
}

/* ===== ACHIEVEMENT TOAST ===== */
.achievement-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, rgba(26,10,6,0.97), rgba(40,20,5,0.97));
  border: 1px solid var(--gold);
  border-radius: 16px;
  padding: 14px 20px;
  min-width: 260px;
  max-width: 340px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), 0 0 30px rgba(212,175,55,0.15);
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: none;
}

.achievement-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-glow {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: radial-gradient(ellipse at 50% 0%, rgba(212,175,55,0.1), transparent 60%);
  pointer-events: none;
}

.toast-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.toast-title {
  font-size: 1rem;
  color: var(--gold-light);
  font-weight: 700;
  letter-spacing: 0.05em;
}

.toast-sub {
  font-size: 0.78rem;
  color: var(--cream-dim);
  margin-top: 2px;
  letter-spacing: 0.03em;
}

/* ===== CERTIFICATE MODAL ===== */
.cert-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(5,2,1,0.88);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: overlayFade 0.3s ease;
}

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

.cert-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: modalPop 0.4s cubic-bezier(0.34,1.56,0.64,1) both;
  max-width: 100%;
}

@keyframes modalPop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

#certCanvas {
  width: 100%;
  max-width: 600px;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), 0 0 40px rgba(212,175,55,0.12);
}

.cert-actions {
  display: flex;
  gap: 10px;
}

.cert-btn {
  background: rgba(212,175,55,0.1);
  border: 1px solid rgba(212,175,55,0.35);
  color: var(--gold);
  padding: 9px 20px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-family: var(--font-serif);
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.05em;
}

.cert-btn:hover {
  background: rgba(212,175,55,0.2);
  border-color: var(--gold);
}

.close-cert-btn {
  padding: 9px 14px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 4px; }

/* ===== RESPONSIVE ===== */

/* --- Mobile (≤600px) --- */
@media (max-width: 600px) {
  /* Compact header — lose the excess top gap */
  .merit-header {
    padding: 44px 16px 4px;
    gap: 2px;
  }

  .merit-number { font-size: clamp(2.2rem, 9vw, 3rem); }

  .rank-badge { font-size: 0.78rem; padding: 2px 12px; }

  .today-row { font-size: 0.68rem; }

  /* Tighter main — less gap between fish & incense */
  main {
    gap: 8px;
    padding: 2px 16px 100px;
  }

  /* --- Fish --- */
  .fish-section { gap: 4px; }

  .tap-hint { font-size: 0.72rem; letter-spacing: 0.15em; }

  .fish-outer {
    width: 56vw;
    height: 56vw;
  }

  /* --- Incense --- */
  .incense-section {
    gap: 8px;
    max-width: 100%;
  }

  .incense-title { font-size: 0.88rem; letter-spacing: 0.18em; }

  /* Shorter scene so controls stay on screen */
  .incense-scene {
    height: 160px;
    width: 90px;
  }

  .incense-stick { height: 110px; }

  .smoke-area {
    height: 110px;
    bottom: 54px;
  }

  .incense-holder { width: 32px; height: 13px; }

  /* Duration buttons: smaller to fit 4 in one row without overflow */
  .incense-controls { gap: 8px; }

  .duration-row { gap: 5px; }

  .dur-btn {
    padding: 5px 8px;
    font-size: 0.74rem;
    border-radius: 6px;
  }

  .light-btn {
    padding: 11px 24px;
    font-size: 0.9rem;
  }

  .timer-display { font-size: 2.2rem; }

  .burning-hint { font-size: 0.7rem; }

  /* FAB: smaller, shift left so it never overlaps the last dur-btn */
  .cert-fab {
    right: 12px;
    bottom: 16px;
    padding: 8px 12px;
    font-size: 0.74rem;
  }
}

/* --- Very small (≤360px) --- */
@media (max-width: 360px) {
  .fish-outer { width: 52vw; height: 52vw; }
  .dur-btn { padding: 5px 6px; font-size: 0.7rem; }
  .merit-number { font-size: 2rem; }
}

/* --- Desktop (≥720px) --- */
@media (min-width: 720px) {
  .fish-section { justify-content: center; min-height: 380px; }
  .incense-section { min-height: 380px; justify-content: center; }
  .fish-outer { width: 300px; height: 300px; }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
