:root {
  --ink: #0b0a12;
  --ink-raised: #17131f;
  --ink-raised-2: #1e1829;
  --hairline: #322a3f;
  --paper: #f3ece0;
  --paper-dim: #a89bb0;
  --flame-gold: #e7b24a;
  --flame-ember: #f2874a;
  --flame-violet: #8a6fe0;
  --flame-jade: #4fae8f;
  --ash-crimson: #b23b4f;
  --ash-grey: #6b6270;
  --transcendent: #fff3dc;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  overflow-x: hidden;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(ellipse 900px 600px at 50% -10%, #241a33 0%, transparent 60%),
    var(--ink);
}

#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 50;
}

#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  opacity: 0;
  mix-blend-mode: screen;
}

#shake-wrap {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 16px 80px;
}

@keyframes shake-good {
  0% { transform: translate(0,0); }
  25% { transform: translate(3px,-3px); }
  50% { transform: translate(-3px,2px); }
  75% { transform: translate(2px,2px); }
  100% { transform: translate(0,0); }
}
@keyframes shake-bad {
  0% { transform: translate(0,0); }
  10% { transform: translate(-9px,3px) rotate(-0.6deg); }
  20% { transform: translate(8px,-4px) rotate(0.6deg); }
  30% { transform: translate(-7px,4px); }
  40% { transform: translate(7px,-3px); }
  50% { transform: translate(-5px,2px); }
  60% { transform: translate(5px,-2px); }
  70% { transform: translate(-3px,1px); }
  80% { transform: translate(3px,-1px); }
  100% { transform: translate(0,0); }
}
.shake-good { animation: shake-good 0.4s ease-in-out; }
.shake-bad { animation: shake-bad 0.5s ease-in-out; }

.app-header {
  text-align: center;
  margin-bottom: 32px;
}
.app-header h1 {
  font-family: "Cinzel", "Georgia", serif;
  font-weight: 600;
  font-size: clamp(2.2rem, 8vw, 3rem);
  letter-spacing: 0.55rem;
  margin: 0;
  color: var(--paper);
  text-shadow: 0 0 30px #e7b24a33;
}
.subtitle {
  font-family: "IBM Plex Mono", monospace;
  color: var(--paper-dim);
  margin-top: 10px;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
}

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.orb-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 12px 0 8px;
}

.orb {
  --tier-color: var(--flame-violet);
  --tier-glow: #8a6fe066;
  position: relative;
  width: min(240px, 62vw);
  height: min(240px, 62vw);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: settle-in 0.9s cubic-bezier(.2,.9,.3,1) both;
}

@keyframes settle-in {
  0% { opacity: 0; transform: scale(0.85); }
  100% { opacity: 1; transform: scale(1); }
}

.dial-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dial-track {
  fill: none;
  stroke: var(--hairline);
  stroke-width: 2.5;
}

.dial-progress {
  fill: none;
  stroke: var(--tier-color);
  stroke-width: 2.5;
  stroke-linecap: round;
  transform-origin: 50px 50px;
  transform: rotate(-90deg);
  filter: drop-shadow(0 0 6px var(--tier-glow));
  transition: stroke 0.5s ease, stroke-dashoffset 0.6s cubic-bezier(.3,.8,.4,1), filter 0.5s ease;
}

.orb.boundless .dial-progress {
  animation: boundless-pulse 2.2s ease-in-out infinite;
}
@keyframes boundless-pulse {
  0%, 100% { filter: drop-shadow(0 0 6px var(--tier-glow)); }
  50% { filter: drop-shadow(0 0 16px var(--tier-glow)); }
}

.dial-ticks line {
  stroke: var(--paper-dim);
  stroke-width: 1;
  opacity: 0.35;
}

.dial-core {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.aura-value {
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.5rem, 7.5vw, 2.5rem);
  font-weight: 600;
  color: var(--tier-color, var(--flame-violet));
  text-shadow: 0 0 20px var(--tier-glow, #8a6fe066);
  transition: color 0.5s ease, text-shadow 0.5s ease;
}

.aura-value.bump-up { animation: bump-up 0.5s cubic-bezier(.34,1.56,.64,1); }
.aura-value.bump-down { animation: bump-down 0.5s cubic-bezier(.34,1.56,.64,1); }

@keyframes bump-up {
  0% { transform: scale(1); }
  30% { transform: scale(1.5); }
  60% { transform: scale(0.94); }
  100% { transform: scale(1); }
}
@keyframes bump-down {
  0% { transform: scale(1); }
  25% { transform: scale(0.78) rotate(-2deg); }
  55% { transform: scale(1.08) rotate(1deg); }
  100% { transform: scale(1) rotate(0); }
}

.aura-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.65rem;
  letter-spacing: 0.3rem;
  color: var(--paper-dim);
}

.tier-label {
  font-family: "Cinzel", serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 5px 18px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: #ffffff06;
  color: var(--flame-violet);
  transition: all 0.5s ease;
}

.reset-btn {
  margin-top: 4px;
}

.panel {
  background: linear-gradient(180deg, var(--ink-raised), var(--ink-raised-2));
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 20px 22px;
}

.panel h2 {
  font-family: "Cinzel", serif;
  font-weight: 600;
  margin: 0 0 16px;
  font-size: 1rem;
  letter-spacing: 0.06em;
  color: var(--paper);
}

.set-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.set-row:last-child { margin-bottom: 0; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
  background: var(--flame-violet);
  transition: transform 0.15s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.96); }
.btn:focus-visible { outline: 2px solid var(--flame-gold); outline-offset: 2px; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--paper-dim);
}
.btn-add {
  width: 100%;
  margin-top: 12px;
  background: transparent;
  border: 1px dashed var(--hairline);
  color: var(--paper-dim);
  font-size: 0.85rem;
}

.actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 640px) {
  .actions-grid { grid-template-columns: 1fr; }
}

.kindle-panel { border-color: #e7b24a33; }
.smother-panel { border-color: #b23b4f33; }

.action-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}

.action-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  padding: 11px 14px;
  transition: transform 0.12s ease, background 0.15s ease;
}
.action-item:focus-visible { outline: 2px solid var(--flame-gold); outline-offset: 2px; }
.action-item:active { transform: scale(0.97); }

/* A brief cooldown after every act keeps any one flame from being tapped
   into the stratosphere by spam-clicking. */
body.on-cooldown .action-item {
  opacity: 0.45;
  pointer-events: none;
  filter: saturate(0.6);
}

/* Kindling: soft, rounded, warm — a lit candle */
.kindle-panel .action-item {
  background: #e7b24a0f;
  border-radius: 999px;
  border: 1px solid #e7b24a2e;
}
.kindle-panel .action-item:hover {
  background: #e7b24a22;
  box-shadow: 0 0 18px #e7b24a22;
}

/* Smothering: angular, one corner cut — a struck-out sigil */
.smother-panel .action-item {
  background: #b23b4f12;
  border: 1px solid #b23b4f33;
  clip-path: polygon(0 0, 100% 0, 100% 66%, 90% 100%, 0 100%);
}
.smother-panel .action-item:hover {
  background: #b23b4f22;
  box-shadow: 0 0 18px #b23b4f22;
}

.action-item .label { font-size: 0.9rem; color: var(--paper); }
.action-item .value {
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
}
.kindle-panel .action-item .value { color: var(--flame-gold); }
.smother-panel .action-item .value { color: var(--ash-crimson); }

.history-panel { max-height: 280px; }
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: 200px;
  overflow-y: auto;
}
.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--paper-dim);
  padding: 8px 2px;
  border-bottom: 1px solid #ffffff08;
  border-left: 2px solid transparent;
  padding-left: 10px;
}
.history-list li.pos-row { border-left-color: var(--flame-gold); }
.history-list li.neg-row { border-left-color: var(--ash-crimson); }
.history-list li .delta {
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.history-list li .delta.pos { color: var(--flame-gold); }
.history-list li .delta.neg { color: var(--ash-crimson); }
.history-list .empty { text-align: center; padding: 14px; border: none; }

/* Impact banner - the "huge impact frame" text slam */
.impact-banner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  z-index: 70;
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: clamp(1.7rem, 9vw, 5.5rem);
  letter-spacing: 0.02em;
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  text-shadow: 0 0 30px currentColor, 0 0 70px currentColor;
}

.impact-banner.play-good {
  animation: impact-good 0.85s cubic-bezier(.2,1.4,.4,1) forwards;
  color: var(--flame-gold);
}
.impact-banner.play-bad {
  animation: impact-bad 0.85s cubic-bezier(.2,1.4,.4,1) forwards;
  color: var(--ash-crimson);
}

@keyframes impact-good {
  0%   { transform: translate(-50%,-50%) scale(0.2) rotate(-6deg); opacity: 0; }
  15%  { transform: translate(-50%,-50%) scale(1.25) rotate(1deg); opacity: 1; }
  30%  { transform: translate(-50%,-50%) scale(1) rotate(0); opacity: 1; }
  75%  { transform: translate(-50%,-50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(1.35) rotate(0); opacity: 0; }
}
@keyframes impact-bad {
  0%   { transform: translate(-50%,-50%) scale(1.5) rotate(3deg); opacity: 0; filter: blur(4px); }
  10%  { transform: translate(-52%,-48%) scale(1.05) rotate(-2deg); opacity: 1; filter: blur(0); }
  18%  { transform: translate(-48%,-51%) scale(1.08) rotate(1deg); }
  26%  { transform: translate(-50%,-50%) scale(1) rotate(0); }
  75%  { transform: translate(-50%,-50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(0.7) rotate(0); opacity: 0; filter: blur(6px); }
}

.flash-good { animation: flash-good 0.5s ease-out; }
.flash-bad { animation: flash-bad 0.5s ease-out; }
@keyframes flash-good {
  0% { opacity: 0.8; background: radial-gradient(circle, #e7b24acc, #f2874a33 55%, transparent 78%); }
  100% { opacity: 0; }
}
@keyframes flash-bad {
  0% { opacity: 0.85; background: radial-gradient(circle, #b23b4fcc, #1a0a0e88 60%, transparent 80%); }
  100% { opacity: 0; }
}

.leaderboard-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.leaderboard-head h2 { margin: 0; }

.lb-rename-btn {
  background: none;
  border: none;
  color: var(--paper-dim);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0;
}
.lb-rename-btn:hover { color: var(--flame-gold); }
.lb-rename-btn:focus-visible { outline: 2px solid var(--flame-gold); outline-offset: 2px; }

.leaderboard-join { margin-bottom: 4px; }
.lb-join-copy {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--paper-dim);
}

#leaderboard-name-input {
  flex: 1;
  background: #00000030;
  border: 1px solid var(--hairline);
  color: var(--paper);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 1rem;
  min-width: 0;
}
#leaderboard-name-input:focus-visible {
  outline: 2px solid var(--flame-gold);
  outline-offset: 1px;
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: #ffffff05;
}
.leaderboard-row.you-row {
  border-color: var(--flame-gold);
  box-shadow: 0 0 14px #e7b24a22;
}

.lb-rank {
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
  color: var(--paper-dim);
  width: 2.5em;
  flex-shrink: 0;
}
.leaderboard-row.rank-1 .lb-rank { color: var(--flame-gold); }
.leaderboard-row.rank-2 .lb-rank { color: #cbd5da; }
.leaderboard-row.rank-3 .lb-rank { color: #c98a55; }

.lb-name {
  flex: 1;
  font-size: 0.9rem;
  color: var(--paper);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.lb-you-tag {
  color: var(--paper-dim);
  font-size: 0.78rem;
}

.lb-aura {
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--flame-gold);
  white-space: nowrap;
}

.leaderboard-status {
  color: var(--paper-dim);
  font-size: 0.85rem;
  text-align: center;
  margin: 8px 0 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
