:root {
  /* tile art is ~200x252 → aspect 1 : 1.25 */
  --cell-w: min(11vw, 7.4vh, 72px);
  --cell-h: calc(var(--cell-w) * 1.25);
  --cols: 8;
  --rows: 8;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: radial-gradient(ellipse at 50% -20%, #1d3a2f 0%, #0e1f1a 55%, #081210 100%);
  color: #e8f3ec;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

header {
  text-align: center;
  padding: 10px 0 6px;
}

h1 {
  font-size: clamp(20px, 4vmin, 30px);
  letter-spacing: 4px;
  color: #cfeede;
  text-shadow: 0 0 14px rgba(140, 230, 180, .45);
  margin-bottom: 8px;
}

.score-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: stretch;
  flex-wrap: wrap;
}

.score-box {
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  padding: 4px 14px;
  min-width: 92px;
  display: flex;
  flex-direction: column;
}

.score-box .label {
  font-size: 11px;
  color: #9fc4b0;
}

.score-box span:last-child {
  font-size: clamp(15px, 3vmin, 20px);
  font-weight: bold;
}

#restart {
  background: #2e6b4f;
  border: 1px solid #4d9a76;
  color: #eafff3;
  border-radius: 10px;
  padding: 4px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

#restart:active { transform: scale(.95); }

#home-btn {
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .15);
  color: #eafff3;
  border-radius: 10px;
  padding: 4px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

#home-btn:active { transform: scale(.95); }

#sound-btn {
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 16px;
  cursor: pointer;
}

.hidden { display: none !important; }

.sp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.sp-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.sp-row input[type=range] { width: 110px; accent-color: #5fc492; }

.track-row { justify-content: center; gap: 8px; }
.track-row button {
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .2);
  color: #e8f3ec;
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
}
.track-row span { flex: 1; text-align: center; font-size: 12px; color: #bfe6d2; }

header { position: relative; }

/* ── 파워 행 (피버 + 필살기) ── */
#power-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}

/* ── 필살기 버튼 ── */
#ult-btn {
  --ult: 0;
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  padding: 0;
  background: conic-gradient(from -90deg,
    #ffd93d calc(var(--ult) * 1%),
    rgba(255, 255, 255, .1) calc(var(--ult) * 1%));
  display: flex;
  align-items: center;
  justify-content: center;
}

#ult-btn::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: #11231c;
}

#ult-btn img {
  position: relative;
  z-index: 1;
  width: 68%;
  filter: grayscale(.9) opacity(.45);
  transition: filter .3s;
  pointer-events: none;
}

#ult-label {
  position: absolute;
  z-index: 1;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: 1px;
  color: #9fc4b0;
  white-space: nowrap;
}

#ult-btn.ready {
  background: conic-gradient(#ff6b6b, #ffb347, #ffd93d, #8ed06c, #6bc5ff, #b388ff, #ff6b6b);
  animation: ult-ready-glow 1s ease-in-out infinite, ult-spin 3s linear infinite;
}

#ult-btn.ready img {
  filter: none;
  animation: overlay-pulse .8s ease-in-out infinite;
}

#ult-btn.ready #ult-label { color: #ffe98a; font-weight: bold; }

@keyframes ult-ready-glow {
  0%, 100% { box-shadow: 0 0 10px 2px rgba(255, 217, 61, .7); }
  50% { box-shadow: 0 0 22px 7px rgba(255, 140, 200, .9); }
}

@keyframes ult-spin {
  to { filter: hue-rotate(360deg); }
}

/* ── 필살기 연출 ── */
#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
}

#flash.go { animation: flash-bang .4s ease-out; }

@keyframes flash-bang {
  0% { opacity: .95; }
  100% { opacity: 0; }
}

body.ult-charging #board-wrap {
  animation: ult-rumble .6s ease-in;
  filter: brightness(1.25) saturate(1.5);
}

@keyframes ult-rumble {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-1px, 1px); }
  25% { transform: translate(2px, -1px); }
  40% { transform: translate(-2px, 2px); }
  55% { transform: translate(2px, 1px); }
  70% { transform: translate(-3px, -2px); }
  85% { transform: translate(3px, 2px); }
}

.fx-beam {
  position: absolute;
  top: 0;
  height: 100%;
  width: var(--cell-w);
  z-index: 6;
  pointer-events: none;
  background: linear-gradient(180deg,
    #ffffff, #ffd93d 25%, #ff6b6b 45%, #b388ff 65%, transparent 95%);
  animation: beam-drop .55s ease-out forwards;
}

@keyframes beam-drop {
  0% { transform: translateY(-100%); opacity: 1; }
  55% { transform: translateY(0); opacity: .95; }
  100% { transform: translateY(0); opacity: 0; }
}

.fx-ring {
  position: absolute;
  border: 4px solid #fff;
  border-radius: 50%;
  z-index: 7;
  pointer-events: none;
  box-shadow: 0 0 16px rgba(255, 230, 150, .9), inset 0 0 12px rgba(255, 180, 220, .8);
}

/* ── 피버 게이지 ── */
#fever-wrap {
  position: relative;
  width: min(58vw, 420px);
  height: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .14);
  overflow: hidden;
}

#fever-bar {
  height: 100%;
  width: 0%;
  border-radius: 8px;
  background: linear-gradient(90deg, #ffb347, #ff6b6b, #ffd93d);
  background-size: 200% 100%;
  transition: width .25s ease;
  animation: fever-flow 1.6s linear infinite;
}

@keyframes fever-flow {
  0% { background-position: 0% 0; }
  100% { background-position: 200% 0; }
}

#fever-label {
  position: absolute;
  inset: 0;
  text-align: center;
  font-size: 10px;
  font-weight: bold;
  line-height: 14px;
  letter-spacing: 3px;
  color: rgba(255, 255, 255, .85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
  pointer-events: none;
}

body.fever #fever-bar { animation-duration: .4s; }

body.fever #board-wrap {
  border-color: transparent;
  animation: fever-glow 1s linear infinite;
}

@keyframes fever-glow {
  0%   { box-shadow: 0 0 24px 4px rgba(255, 120, 120, .55); }
  25%  { box-shadow: 0 0 24px 4px rgba(255, 220, 100, .55); }
  50%  { box-shadow: 0 0 24px 4px rgba(120, 255, 160, .55); }
  75%  { box-shadow: 0 0 24px 4px rgba(120, 180, 255, .55); }
  100% { box-shadow: 0 0 24px 4px rgba(255, 120, 120, .55); }
}

#board-wrap {
  position: relative;
  margin-top: 8px;
  padding: calc(var(--cell-w) * 0.10);
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}

#board {
  position: relative;
  width: calc(var(--cell-w) * var(--cols));
  height: calc(var(--cell-h) * var(--rows));
  overflow: hidden;
  border-radius: 8px;
}

.tile {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cell-w);
  height: var(--cell-h);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .18s ease;
  will-change: transform;
  cursor: pointer;
}

.tile img.spirit {
  width: 94%;
  height: 94%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.tile img.overlay {
  position: absolute;
  width: 58%;
  left: 21%;
  top: 23%;
  opacity: .96;
  pointer-events: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, .85));
  animation: overlay-pulse 1.1s ease-in-out infinite;
}

@keyframes overlay-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.tile.selected img.spirit {
  filter: drop-shadow(0 0 7px #ffe98a) brightness(1.15);
  animation: wobble .4s ease-in-out infinite;
}

@keyframes wobble {
  0%, 100% { transform: scale(1.04) rotate(-3deg); }
  50% { transform: scale(1.04) rotate(3deg); }
}

.tile.clearing {
  transition: transform .22s ease-in, opacity .22s ease-in;
  transform: scale(0) !important;
  opacity: 0;
}

.tile.spawned img.spirit,
.tile.spawned img.overlay {
  animation: spawn-pop .35s ease;
}

@keyframes spawn-pop {
  0% { transform: scale(.2); }
  65% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* special-effect flashes */
.fx {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  animation: fx-fade .45s ease-out forwards;
}

.fx-row {
  height: var(--cell-h);
  left: 0;
  width: 100%;
  background: linear-gradient(180deg, transparent, rgba(160, 220, 255, .85), transparent);
}

.fx-col {
  width: var(--cell-w);
  top: 0;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(190, 255, 170, .85), transparent);
}

.fx-burst {
  width: calc(var(--cell-w) * 3);
  height: calc(var(--cell-h) * 3);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 210, 120, .9) 0%, rgba(255, 160, 60, .4) 55%, transparent 75%);
}

.fx-rainbow {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: conic-gradient(from 0deg, rgba(255,120,120,.35), rgba(255,220,120,.35), rgba(140,255,140,.35), rgba(120,180,255,.35), rgba(220,140,255,.35), rgba(255,120,120,.35));
}

@keyframes fx-fade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

#combo-banner {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: clamp(22px, 5vmin, 38px);
  font-weight: bold;
  color: #ffe98a;
  text-shadow: 0 0 12px rgba(255, 200, 80, .8), 0 2px 4px rgba(0, 0, 0, .6);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

#combo-banner.show {
  animation: combo-pop .8s ease-out forwards;
}

@keyframes combo-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -65%) scale(1); }
}

#toast {
  position: fixed;
  bottom: 5vh;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 40, 32, .92);
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 20px;
  padding: 8px 22px;
  font-size: 14px;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  z-index: 20;
}

#toast.show { opacity: 1; }

/* ── 파티클 & 떠오르는 점수 ── */
.particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 8;
  box-shadow: 0 0 6px currentColor;
}

.float-score {
  position: absolute;
  font-weight: bold;
  font-size: clamp(14px, 3vmin, 22px);
  color: #fff7c9;
  text-shadow: 0 0 8px rgba(255, 215, 100, .9), 0 2px 3px rgba(0, 0, 0, .7);
  pointer-events: none;
  z-index: 9;
  transform: translate(-50%, -50%);
}

.float-score.fever {
  color: #ffb0d0;
  font-size: clamp(17px, 3.6vmin, 27px);
  text-shadow: 0 0 10px rgba(255, 110, 170, .95), 0 2px 3px rgba(0, 0, 0, .7);
}

/* ── 화면 흔들림 ── */
.shake-1 { animation: shake1 .3s ease; }
.shake-2 { animation: shake2 .35s ease; }
.shake-3 { animation: shake3 .45s ease; }

@keyframes shake1 {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(2px, -2px); }
  50% { transform: translate(-2px, 2px); }
  75% { transform: translate(1px, 1px); }
}

@keyframes shake2 {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(5px, -4px) rotate(.3deg); }
  40% { transform: translate(-5px, 4px) rotate(-.3deg); }
  60% { transform: translate(4px, 2px); }
  80% { transform: translate(-3px, -2px); }
}

@keyframes shake3 {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(9px, -7px) rotate(.6deg); }
  30% { transform: translate(-9px, 7px) rotate(-.6deg); }
  45% { transform: translate(7px, 4px) rotate(.4deg); }
  60% { transform: translate(-6px, -5px) rotate(-.4deg); }
  80% { transform: translate(3px, 2px); }
}

/* ── 착지 바운스 ── */
.tile.land img.spirit { animation: land-squash .24s ease; }

@keyframes land-squash {
  0%   { transform: scaleY(.76) scaleX(1.16) translateY(7%); }
  60%  { transform: scaleY(1.1) scaleX(.94); }
  100% { transform: none; }
}

/* ── 콤보 레벨별 연출 ── */
#combo-banner[data-level="3"] { color: #ffc46b; font-size: clamp(26px, 5.6vmin, 44px); }
#combo-banner[data-level="4"] { color: #ff9d6b; font-size: clamp(30px, 6.2vmin, 50px); }
#combo-banner[data-level="5"] {
  color: #ff6b8d;
  font-size: clamp(34px, 7vmin, 58px);
  text-shadow: 0 0 18px rgba(255, 100, 140, .95), 0 2px 5px rgba(0, 0, 0, .6);
}

#score.bump { animation: score-bump .25s ease; display: inline-block; }

@keyframes score-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); color: #ffe98a; }
  100% { transform: scale(1); }
}

/* ── 타이머 ── */
#timer-box.warn #timer {
  color: #ff6b6b;
  animation: timer-pulse .5s ease-in-out infinite;
}

@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

/* ── 오버레이 / 화면 전환 ── */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 14, 11, .82);
  backdrop-filter: blur(4px);
}

#overlay.hidden { display: none; }

.screen {
  background: linear-gradient(180deg, rgba(28, 56, 45, .96), rgba(12, 26, 21, .98));
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 18px;
  box-shadow: 0 14px 50px rgba(0, 0, 0, .6);
  padding: 28px 26px;
  width: min(92vw, 380px);
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.screen.hidden { display: none; }

.screen h1 {
  margin-bottom: 0;
}

.screen .subtitle {
  font-size: 13px;
  color: #9fc4b0;
  letter-spacing: 2px;
  margin-top: -8px;
}

.screen h2 {
  font-size: clamp(18px, 4vmin, 24px);
  color: #cfeede;
  letter-spacing: 2px;
}

.screen h3 {
  font-size: 13px;
  color: #bfe6d2;
  letter-spacing: 1px;
  text-align: left;
}

.title-best {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 10px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  padding: 8px 14px;
}

.title-best .label {
  font-size: 12px;
  color: #9fc4b0;
}

.title-best span:last-child {
  font-size: 20px;
  font-weight: bold;
  color: #ffe98a;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-btn {
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .18);
  color: #eafff3;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 16px;
  font-family: inherit;
  font-weight: bold;
  letter-spacing: 2px;
  cursor: pointer;
  transition: transform .1s;
}

.menu-btn:active { transform: scale(.96); }

.menu-btn.primary {
  background: linear-gradient(135deg, #2e6b4f, #4d9a76);
  border: 1px solid #6bd6a8;
  box-shadow: 0 0 18px rgba(110, 220, 170, .35);
}

.setting-section {
  text-align: left;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.radio-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .1);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.radio-row:has(input:checked) {
  background: rgba(110, 220, 170, .12);
  border-color: #6bd6a8;
}

.radio-main {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: bold;
}

.radio-main input { accent-color: #5fc492; }

.radio-row .desc {
  font-size: 11px;
  color: #9fc4b0;
  margin-left: 24px;
}

.sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  padding: 4px 2px;
}

.sub-row select {
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .2);
  color: #e8f3ec;
  border-radius: 8px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 13px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  padding: 8px 14px;
}

.result-row .label {
  font-size: 12px;
  color: #9fc4b0;
}

.result-row span:last-child {
  font-size: 20px;
  font-weight: bold;
  color: #ffe98a;
}

/* ── 마스코트 비아 ── */
#via {
  position: fixed;
  top: 16px;
  right: 8px;
  height: clamp(64px, 13vh, 120px);
  z-index: 60;
  pointer-events: none;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .5));
}

#via.jump {
  animation: via-jump .45s ease-in-out infinite;
}

@keyframes via-jump {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  30% { transform: translateY(-13px) rotate(-6deg) scale(1.08); }
  60% { transform: translateY(-4px) rotate(5deg) scale(1.04); }
}
