:root {
  --ink: #fff8ed;
  --muted: #c9bfd7;
  --deep: #21172f;
  --panel: #302341;
  --panel-light: #3b2b50;
  --gold: #f5c76b;
  --gold-dark: #b77c31;
  --pink: #f58eae;
  --green: #75d6a0;
  --red: #fb7887;
  --line: rgba(255, 255, 255, .11);
  --shadow: 0 18px 45px rgba(10, 6, 20, .26);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  background:
    radial-gradient(circle at 13% 10%, rgba(123, 79, 156, .27), transparent 28rem),
    radial-gradient(circle at 88% 27%, rgba(185, 102, 133, .15), transparent 25rem),
    linear-gradient(145deg, #1e162c 0%, #2a1d3b 48%, #21172f 100%);
}

button { font: inherit; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.hidden { display: none !important; }

.page-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.site-header {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 45px; height: 45px; display: grid; place-items: center;
  border: 1px solid rgba(245, 199, 107, .55); border-radius: 14px;
  background: linear-gradient(145deg, #684b70, #392747); color: var(--gold); font-size: 28px;
  box-shadow: 0 7px 20px rgba(0,0,0,.17);
}
.brand-title { display: block; font-family: "Rye", serif; letter-spacing: 1.7px; font-size: 17px; }
.brand-subtitle { display: block; color: var(--muted); font-size: 11px; letter-spacing: .7px; margin-top: 2px; }
.campaign-label { display: flex; align-items: center; gap: 9px; color: #d9c9e5; font-size: 10px; letter-spacing: 1.6px; font-weight: 900; }
.campaign-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px rgba(117,214,160,.8); }

main { min-height: calc(100vh - 142px); padding: 36px 0 28px; }
.eyebrow { margin: 0 0 8px; color: var(--gold); font-size: 10px; font-weight: 900; letter-spacing: 2px; }
.start-screen {
  min-height: 650px; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr auto;
  align-items: center; gap: 24px 40px; padding: 24px 28px 28px;
  border: 1px solid var(--line); border-radius: 26px;
  background: linear-gradient(135deg, rgba(64,46,81,.9), rgba(43,31,59,.91)); box-shadow: var(--shadow); overflow: hidden;
}
.start-copy { padding: 18px 0 10px 12px; position: relative; z-index: 1; }
.start-copy h1 { margin: 0; font-family: "Rye", serif; font-weight: 400; line-height: 1.15; font-size: clamp(38px, 5vw, 62px); letter-spacing: .3px; }
.start-copy h1 span { color: var(--gold); }
.intro-text { max-width: 475px; margin: 21px 0 17px; color: #ded5e7; line-height: 1.75; font-size: 15px; }
.hero-quote { max-width: 440px; padding: 12px 15px; border-left: 3px solid var(--pink); background: rgba(255,255,255,.045); color: #f3dce5; font-size: 13px; font-style: italic; }
.primary-button, .secondary-button {
  border: 0; border-radius: 12px; padding: 14px 20px; cursor: pointer; font-weight: 900;
  transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
}
.primary-button { margin-top: 26px; color: #35233b; background: linear-gradient(135deg, #ffdc8a, #eeb65c); box-shadow: 0 8px 22px rgba(238,182,92,.2); }
.primary-button span { margin-left: 17px; font-size: 18px; }
.primary-button:hover, .secondary-button:hover { transform: translateY(-2px); filter: brightness(1.06); }
.start-art { min-height: 365px; position: relative; display: grid; place-items: center; isolation: isolate; }
.castle-glow { position: absolute; width: 340px; height: 300px; border-radius: 50%; background: radial-gradient(circle, rgba(238,182,92,.22), transparent 68%); z-index: -1; }
.hero-castle { position: absolute; top: 37px; font-size: clamp(100px, 15vw, 170px); filter: drop-shadow(0 16px 18px rgba(0,0,0,.25)); }
.hero-knight { position: absolute; bottom: 23px; left: 19%; font-size: 90px; filter: drop-shadow(0 10px 8px rgba(0,0,0,.3)); transform: rotate(-7deg); }
.hero-princess { position: absolute; bottom: 36px; right: 17%; font-size: 66px; filter: drop-shadow(0 10px 8px rgba(0,0,0,.3)); }
.monster-teaser { position: absolute; right: 9%; top: 20px; font-size: 54px; transform: rotate(12deg); }
.floating-candy { position: absolute; width: 24px; height: 24px; border-radius: 50%; box-shadow: inset 3px 4px 5px rgba(255,255,255,.65), inset -4px -5px 8px rgba(0,0,0,.18), 0 8px 13px rgba(0,0,0,.22); }
.candy-a { top: 24%; left: 12%; background: #f36e8c; }
.candy-b { top: 48%; right: 9%; background: #68b7f0; width: 30px; height: 30px; }
.candy-c { bottom: 15%; left: 42%; background: #e9ba59; width: 19px; height: 19px; }
.start-rules { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding-top: 21px; border-top: 1px solid var(--line); }
.start-rules > div { display: flex; align-items: center; gap: 12px; padding: 7px 10px; }
.rule-icon { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 12px; background: rgba(255,255,255,.07); font-size: 19px; }
.start-rules strong, .start-rules small { display: block; }
.start-rules strong { font-size: 13px; }
.start-rules small { color: var(--muted); font-size: 11px; line-height: 1.4; margin-top: 2px; }

.progress-row { display: flex; align-items: end; justify-content: space-between; margin: 0 2px 20px; }
.game-heading { margin: 0; font-family: "Rye", serif; font-weight: 400; font-size: 28px; }
.stage-counter { text-align: right; color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: 1.4px; }
.stage-dots { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.stage-dots i { display: block; width: 24px; height: 5px; border-radius: 9px; background: #554460; }
.stage-dots i.active { background: var(--gold); box-shadow: 0 0 9px rgba(245,199,107,.35); }

.battle-arena { display: grid; grid-template-columns: 1fr 48px 1fr; align-items: center; gap: 14px; margin-bottom: 20px; }
.combatant { min-width: 0; display: flex; align-items: center; gap: 15px; padding: 16px 18px; min-height: 140px; border: 1px solid var(--line); border-radius: 18px; background: linear-gradient(135deg, rgba(61,44,78,.95), rgba(47,34,64,.95)); box-shadow: 0 9px 24px rgba(0,0,0,.12); }
.enemy-combatant { border-color: rgba(251,120,135,.23); }
.player-combatant { border-color: rgba(117,214,160,.2); }
.combatant-avatar { flex: 0 0 76px; width: 76px; height: 76px; display: grid; place-items: center; border-radius: 20px; font-size: 43px; background: rgba(255,255,255,.07); box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }
.enemy-avatar { background: linear-gradient(145deg, rgba(251,120,135,.2), rgba(129,70,103,.19)); }
.player-avatar { background: linear-gradient(145deg, rgba(117,214,160,.2), rgba(60,129,124,.19)); }
.combatant-info { min-width: 0; width: 100%; }
.combatant-title-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.combatant-type { color: #bfb2ca; font-size: 8px; letter-spacing: 1.2px; font-weight: 900; }
.difficulty-tag { padding: 4px 7px; border-radius: 6px; background: rgba(251,120,135,.14); color: #ff9eaa; font-size: 8px; font-weight: 900; letter-spacing: .8px; }
.player-tag { color: #9be7b8; background: rgba(117,214,160,.12); }
.combatant h2 { margin: 5px 0 0; font-size: 19px; line-height: 1.2; }
.combatant-flavor { margin: 3px 0 10px; color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hp-label-row { display: flex; justify-content: space-between; gap: 10px; color: #cfc4d8; font-size: 8px; font-weight: 900; letter-spacing: .8px; }
.hp-label-row strong { color: var(--ink); font-size: 9px; letter-spacing: .2px; }
.hp-track { height: 8px; margin-top: 6px; overflow: hidden; border-radius: 10px; background: rgba(0,0,0,.27); box-shadow: inset 0 1px 3px rgba(0,0,0,.22); }
.hp-fill { height: 100%; width: 100%; border-radius: inherit; transition: width .35s ease; }
.enemy-hp-fill { background: linear-gradient(90deg, #e85c76, #ff9a9a); }
.player-hp-fill { background: linear-gradient(90deg, #42b982, #91e6ad); }
.versus-mark { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid rgba(245,199,107,.34); border-radius: 50%; background: #342440; color: var(--gold); font-family: "Rye", serif; font-size: 12px; box-shadow: 0 5px 15px rgba(0,0,0,.2); }

.game-columns { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 20px; align-items: start; }
.board-card, .guide-card, .message-card, .survival-card { border: 1px solid var(--line); border-radius: 18px; background: linear-gradient(145deg, rgba(57,41,73,.96), rgba(43,31,58,.98)); box-shadow: 0 12px 30px rgba(0,0,0,.15); }
.board-card { padding: 18px; }
.board-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.board-header h2 { margin: 0; font-size: 20px; }
.turn-badge { display: flex; align-items: center; gap: 7px; padding: 8px 11px; border-radius: 9px; font-size: 9px; font-weight: 900; letter-spacing: 1px; }
.player-turn { color: #a8edbf; background: rgba(117,214,160,.12); }
.enemy-turn { color: #ffabb3; background: rgba(251,120,135,.14); }
.turn-indicator { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.grid {
  width: min(100%, 570px); aspect-ratio: 1 / 1; margin: 0 auto; display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: clamp(3px, .7vw, 7px); padding: clamp(6px, 1vw, 10px);
  border: 1px solid rgba(255,255,255,.13); border-radius: 15px;
  background: linear-gradient(145deg, rgba(25,17,36,.9), rgba(49,35,64,.95));
  box-shadow: inset 0 4px 17px rgba(0,0,0,.35), 0 7px 20px rgba(0,0,0,.16);
  touch-action: manipulation;
}
.candy-tile {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 0;
  padding: 0; border: 1px solid rgba(255,255,255,.14); border-radius: 9px; cursor: pointer;
  background: rgba(255,255,255,.055); box-shadow: inset 0 1px 2px rgba(255,255,255,.06), 0 2px 3px rgba(0,0,0,.15);
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.candy-tile:hover { transform: scale(1.045); background-color: rgba(255,255,255,.11); }
.candy-tile:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; z-index: 2; }
.candy-piece {
  width: 69%; height: 69%; max-width: 42px; max-height: 42px; border-radius: 36% 44% 39% 45%;
  transform: rotate(-8deg); position: relative; display: block;
  border: 2px solid rgba(255,255,255,.28);
  box-shadow: inset 3px 4px 5px rgba(255,255,255,.48), inset -5px -6px 8px rgba(0,0,0,.2), 0 3px 5px rgba(0,0,0,.23);
}
.candy-piece::before { content: ""; position: absolute; left: 18%; top: 13%; width: 34%; height: 18%; border-radius: 50%; background: rgba(255,255,255,.55); transform: rotate(-27deg); filter: blur(.4px); }
.candy-piece::after { content: ""; position: absolute; inset: 17%; border: 1px solid rgba(255,255,255,.13); border-radius: 35%; }
.candy-0 { background: linear-gradient(135deg, #ff8d9b, #df365e); }
.candy-1 { background: linear-gradient(135deg, #ffc178, #ed8037); }
.candy-2 { background: linear-gradient(135deg, #ffe58a, #e9b82f); }
.candy-3 { background: linear-gradient(135deg, #a3ed9d, #46b96b); }
.candy-4 { background: linear-gradient(135deg, #91d7ff, #438bd8); }
.candy-5 { background: linear-gradient(135deg, #d1a2ff, #8959cb); }
.candy-tile.selected { transform: scale(.91); border: 2px solid #ffe08b; background: rgba(245,199,107,.22); box-shadow: 0 0 0 3px rgba(245,199,107,.15), 0 0 17px rgba(245,199,107,.35); }
.candy-tile.empty { opacity: .2; }
.candy-tile.clearing { transform: scale(.25); opacity: 0; transition: transform .14s ease, opacity .14s ease; }
.board-footer { display: flex; justify-content: space-between; gap: 10px; margin: 12px 2px 0; color: #bdb1ca; font-size: 9px; font-weight: 800; letter-spacing: .8px; }
.board-footer > span:first-child { display: flex; align-items: center; gap: 7px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }
.side-column { display: flex; flex-direction: column; gap: 13px; }
.message-card { display: flex; gap: 12px; padding: 15px; min-height: 100px; }
.message-icon { flex: 0 0 38px; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: rgba(245,199,107,.12); font-size: 19px; }
.message-card .eyebrow { font-size: 8px; margin-bottom: 4px; }
.message-card h3 { margin: 0; font-size: 14px; }
.message-card p:last-child { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.guide-card { padding: 15px; }
.guide-title { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.guide-title span { font-size: 16px; }
.guide-title h3 { margin: 0; font-size: 14px; }
.combo-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid rgba(255,255,255,.065); }
.combo-row > span:last-child strong, .combo-row > span:last-child small { display: block; }
.combo-row strong { font-size: 11px; }
.combo-row small { margin-top: 2px; color: #bfb3ca; font-size: 9px; line-height: 1.3; }
.combo-preview { width: 59px; min-width: 59px; height: 26px; display: flex; align-items: center; justify-content: center; gap: 2px; }
.combo-preview i { display: block; width: 10px; height: 10px; border: 1px solid rgba(255,255,255,.45); border-radius: 35%; background: linear-gradient(135deg, #ffb6bd, #df4367); box-shadow: inset 1px 1px 2px rgba(255,255,255,.45); }
.combo-four i:nth-child(2), .combo-four i:nth-child(3), .combo-five i:nth-child(2), .combo-five i:nth-child(3), .combo-five i:nth-child(4) { background: linear-gradient(135deg, #ffe58a, #dfa92b); }
.combo-t { position: relative; }
.combo-t i:nth-child(2), .combo-t i:nth-child(3), .combo-t i:nth-child(4) { background: linear-gradient(135deg, #a6eaa1, #4bae69); }
.combo-t i:nth-child(5) { display: none; }
.combo-t::after { content: ""; position: absolute; width: 10px; height: 10px; left: 24px; top: 15px; border-radius: 35%; background: linear-gradient(135deg, #a6eaa1, #4bae69); border: 1px solid rgba(255,255,255,.45); }
.guide-note { margin: 11px 0 0; padding: 10px; border-radius: 9px; color: #d6cadd; background: rgba(255,255,255,.045); font-size: 9px; line-height: 1.5; }
.guide-note strong { color: var(--gold); }
.survival-card { display: flex; gap: 10px; padding: 13px; background: linear-gradient(135deg, rgba(116,61,86,.3), rgba(54,37,67,.96)); }
.survival-icon { flex: 0 0 28px; font-size: 20px; }
.survival-card strong { font-size: 11px; }
.survival-card p { margin: 3px 0 0; color: #cfc0d1; font-size: 10px; line-height: 1.45; }
.secondary-button { width: 100%; padding: 11px 14px; border: 1px solid var(--line); color: #e1d6e8; background: rgba(255,255,255,.055); font-size: 11px; }

.site-footer { padding: 8px 0 20px; text-align: center; color: #8f819d; font-size: 9px; font-weight: 900; letter-spacing: 2px; }
.site-footer span { color: var(--gold); padding: 0 5px; }
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(13,8,20,.78); backdrop-filter: blur(8px); }
.ending-card { width: min(440px, 100%); padding: 36px 30px 30px; text-align: center; border: 1px solid rgba(245,199,107,.28); border-radius: 23px; background: linear-gradient(145deg, #453252, #2d203d); box-shadow: 0 25px 80px rgba(0,0,0,.42); }
.ending-emoji { margin-bottom: 12px; font-size: 64px; filter: drop-shadow(0 8px 9px rgba(0,0,0,.25)); }
.ending-card h2 { margin: 0; font-family: "Rye", serif; font-size: 26px; font-weight: 400; color: var(--gold); }
.ending-card > p:not(.eyebrow) { color: #d8cddd; font-size: 13px; line-height: 1.6; }
.ending-card .primary-button { margin-top: 10px; }

@media (max-width: 900px) {
  .game-columns { grid-template-columns: minmax(0, 1fr) 270px; gap: 14px; }
  .combatant { padding: 13px; gap: 10px; }
  .combatant-avatar { flex-basis: 62px; width: 62px; height: 62px; font-size: 35px; }
  .combatant h2 { font-size: 16px; }
  .start-screen { gap: 15px; }
}
@media (max-width: 720px) {
  .page-shell { width: min(100% - 24px, 560px); }
  .site-header { min-height: 74px; }
  .campaign-label { font-size: 8px; letter-spacing: 1px; }
  main { padding-top: 20px; }
  .start-screen { display: flex; flex-direction: column; align-items: stretch; padding: 24px 18px 18px; min-height: 0; }
  .start-copy { padding: 8px 3px 0; }
  .start-copy h1 { font-size: 43px; }
  .intro-text { font-size: 13px; margin: 15px 0; }
  .start-art { min-height: 225px; width: 100%; }
  .hero-castle { top: 5px; font-size: 120px; }
  .hero-knight { bottom: 3px; left: 17%; font-size: 67px; }
  .hero-princess { bottom: 10px; right: 17%; font-size: 52px; }
  .monster-teaser { top: 3px; right: 12%; font-size: 40px; }
  .start-rules { grid-template-columns: 1fr; gap: 4px; padding-top: 13px; }
  .start-rules > div { padding: 5px; }
  .progress-row { align-items: center; }
  .game-heading { font-size: 22px; }
  .battle-arena { grid-template-columns: 1fr; gap: 8px; }
  .combatant { min-height: 112px; }
  .combatant-avatar { flex-basis: 60px; width: 60px; height: 60px; }
  .versus-mark { width: 30px; height: 30px; justify-self: center; font-size: 9px; margin: -2px 0; }
  .game-columns { grid-template-columns: 1fr; }
  .board-card { padding: 12px; }
  .grid { gap: 4px; padding: 6px; }
  .candy-tile { border-radius: 6px; }
  .board-footer { font-size: 8px; }
  .side-column { display: grid; grid-template-columns: 1fr 1fr; }
  .message-card, .guide-card { grid-column: 1 / -1; }
  .survival-card { align-items: center; }
  .secondary-button { min-height: 100%; }
}
@media (max-width: 390px) {
  .brand-title { font-size: 14px; }
  .brand-subtitle { font-size: 9px; }
  .campaign-label { max-width: 108px; text-align: right; line-height: 1.4; }
  .start-copy h1 { font-size: 36px; }
  .board-header h2 { font-size: 17px; }
  .turn-badge { padding: 7px 8px; font-size: 8px; }
  .side-column { grid-template-columns: 1fr; }
  .message-card, .guide-card { grid-column: auto; }
}

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

/* Ten-level campaign progress */
.stage-dots { gap: 4px; max-width: 190px; }
.stage-dots i { width: 14px; height: 5px; flex: 1 1 14px; }
.stage-dots i.completed { background: var(--green); box-shadow: 0 0 8px rgba(117,214,160,.28); }

/* Match-3 special candies */
.candy-tile.has-special { border-color: rgba(255,231,160,.72); box-shadow: inset 0 1px 3px rgba(255,255,255,.16), 0 0 9px rgba(245,199,107,.24); }
.candy-piece.special-striped-h::after {
  inset: 0; border: 0; border-radius: inherit;
  background: repeating-linear-gradient(0deg, transparent 0 5px, rgba(255,255,255,.72) 5px 8px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.candy-piece.special-striped-v::after {
  inset: 0; border: 0; border-radius: inherit;
  background: repeating-linear-gradient(90deg, transparent 0 5px, rgba(255,255,255,.72) 5px 8px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.candy-piece.special-wrapped {
  border: 3px dashed rgba(255,255,255,.9);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.2), 0 0 11px rgba(255,220,138,.55);
  transform: rotate(0deg) scale(1.03);
}
.candy-piece.special-wrapped::after { inset: 22%; border: 2px solid rgba(255,255,255,.8); border-radius: 28%; }
.candy-piece.special-color-bomb {
  border: 2px solid rgba(255,255,255,.8);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #fff 0 7%, transparent 8%),
    radial-gradient(circle at 68% 28%, #ffdc69 0 10%, transparent 11%),
    radial-gradient(circle at 30% 67%, #ff6f9a 0 12%, transparent 13%),
    radial-gradient(circle at 70% 68%, #6bd9d0 0 12%, transparent 13%),
    radial-gradient(circle at 48% 48%, #f5f2e8 0 16%, #55456e 18% 42%, #171221 70%);
  box-shadow: inset 0 0 9px rgba(255,255,255,.8), 0 0 13px rgba(245,199,107,.72);
  transform: rotate(0deg);
}
.candy-piece.special-color-bomb::before,
.candy-piece.special-color-bomb::after { display: none; }
.special-mark {
  position: absolute; z-index: 2; display: grid; place-items: center;
  width: 65%; height: 65%; color: #fff;
  font-family: Arial, sans-serif; font-size: clamp(12px, 2vw, 20px);
  line-height: 1; font-weight: 900; pointer-events: none;
  text-shadow: 0 1px 3px rgba(30,18,40,.8), 0 0 5px rgba(255,255,255,.5);
}
.combo-combo i { background: linear-gradient(135deg, #fff0a0, #e9a84c); box-shadow: 0 0 6px rgba(245,199,107,.55); }

@media (max-width: 720px) {
  .stage-dots { gap: 3px; max-width: 150px; }
  .stage-dots i { width: 10px; height: 5px; flex-basis: 10px; }
  .stage-counter { font-size: 8px; letter-spacing: .8px; }
}


/* =========================================================
   BATTLE ANIMATIONS
   ========================================================= */
.candy-tile {
  animation: candy-drop-in .24s cubic-bezier(.2,.8,.25,1) both;
  animation-delay: var(--tile-delay, 0ms);
  will-change: transform, opacity;
}
.candy-tile.swap-animate {
  z-index: 3;
  animation: candy-swap .22s ease-in-out both;
}
.candy-tile.clearing {
  z-index: 4;
  pointer-events: none;
  animation: candy-crush-out .18s ease-in forwards;
}
.candy-tile.has-special .candy-piece {
  animation: special-idle 2.4s ease-in-out infinite;
}
.candy-tile.special-activating .candy-piece,
.candy-piece.special-activating {
  animation: special-activate .42s ease-out both;
}

@keyframes candy-drop-in {
  from { opacity: 0; transform: translateY(-12px) scale(.68); }
  65% { opacity: 1; transform: translateY(2px) scale(1.06); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes candy-swap {
  0% { transform: scale(.92); filter: brightness(1); }
  45% { transform: scale(1.12); filter: brightness(1.5); }
  100% { transform: scale(1); filter: brightness(1); }
}
@keyframes candy-crush-out {
  0% { opacity: 1; transform: scale(1) rotate(0); filter: brightness(1); }
  45% { opacity: .95; transform: scale(1.18) rotate(9deg); filter: brightness(1.8); }
  100% { opacity: 0; transform: scale(.12) rotate(-18deg); filter: brightness(2); }
}
@keyframes special-idle {
  0%, 100% { filter: brightness(1) drop-shadow(0 0 0 rgba(255,220,138,0)); }
  50% { filter: brightness(1.13) drop-shadow(0 0 5px rgba(255,220,138,.55)); }
}
@keyframes special-activate {
  0% { transform: scale(1); filter: brightness(1); }
  45% { transform: scale(1.45) rotate(12deg); filter: brightness(2.2); }
  100% { transform: scale(.65); opacity: .15; filter: brightness(2.5); }
}

/* Character reactions during attacks. */
.combat-hit { animation: combat-hit .48s ease both; }
.hero-attack { animation: hero-attack .42s ease both; }
.enemy-attack { animation: enemy-attack .42s ease both; }
.message-pop { animation: message-pop .28s ease both; }
.hp-fill { transition: width .42s cubic-bezier(.2,.8,.2,1); }

@keyframes combat-hit {
  0%, 100% { transform: translateX(0); filter: brightness(1); }
  18% { transform: translateX(-7px) rotate(-1deg); filter: brightness(1.65); }
  38% { transform: translateX(6px) rotate(1deg); }
  58% { transform: translateX(-4px); }
  78% { transform: translateX(3px); filter: brightness(1.2); }
}
@keyframes hero-attack {
  0%, 100% { transform: translateX(0) scale(1); }
  40% { transform: translateX(9px) scale(1.035); }
  65% { transform: translateX(4px) scale(1.015); }
}
@keyframes enemy-attack {
  0%, 100% { transform: translateX(0); }
  40% { transform: translateX(-9px) scale(1.035); }
  70% { transform: translateX(-3px); }
}
@keyframes message-pop {
  from { transform: translateY(5px); opacity: .72; }
  to { transform: translateY(0); opacity: 1; }
}

/* =========================================================
   LEVEL-TRANSITION DIALOGUE
   ========================================================= */
.transition-overlay {
  z-index: 30;
  overflow-y: auto;
  place-items: safe center;
  background: rgba(13,8,20,.84);
  animation: overlay-fade-in .24s ease both;
}
.transition-card {
  position: relative;
  width: min(560px, 100%);
  margin: 8px auto;
  padding: 25px 28px 22px;
  overflow: hidden;
  text-align: center;
  border: 1px solid rgba(245,199,107,.45);
  border-radius: 25px;
  background:
    radial-gradient(circle at 50% 14%, rgba(245,199,107,.16), transparent 38%),
    linear-gradient(145deg, #493455, #2b203b 72%);
  box-shadow: 0 28px 90px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.08);
  animation: transition-card-in .42s cubic-bezier(.18,.85,.25,1.12) both;
}
.transition-card::before,
.transition-card::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border: 1px solid rgba(245,199,107,.12);
  border-radius: 50%;
  pointer-events: none;
}
.transition-card::before { top: -110px; left: -95px; }
.transition-card::after { right: -105px; bottom: -125px; }
.transition-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #e7d9eb;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1.5px;
}
.transition-ribbon strong {
  padding: 6px 9px;
  border: 1px solid rgba(245,199,107,.35);
  border-radius: 7px;
  color: var(--gold);
  background: rgba(245,199,107,.09);
  letter-spacing: .8px;
}
.transition-scene {
  position: relative;
  display: grid;
  place-items: center;
  width: 120px;
  height: 120px;
  margin: 17px auto 8px;
  border: 1px solid rgba(245,199,107,.24);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245,199,107,.2), rgba(245,199,107,.025) 68%);
  box-shadow: 0 0 35px rgba(245,199,107,.1), inset 0 0 24px rgba(245,199,107,.08);
}
.transition-avatar {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  border-radius: 28px;
  background: rgba(255,255,255,.07);
  font-size: 65px;
  filter: drop-shadow(0 10px 9px rgba(0,0,0,.28));
  animation: transition-monster 2.1s ease-in-out infinite;
}
.scene-spark {
  position: absolute;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(245,199,107,.75);
  animation: sparkle-float 2s ease-in-out infinite;
}
.spark-one { top: 8px; left: 8px; font-size: 18px; }
.spark-two { top: 20px; right: 3px; font-size: 15px; animation-delay: .45s; }
.spark-three { bottom: 4px; left: 20px; font-size: 13px; animation-delay: .9s; }
.transition-location { margin: 8px 0 5px; font-size: 9px; }
.transition-title {
  margin: 0;
  color: var(--gold);
  font-family: "Rye", serif;
  font-size: clamp(25px, 5vw, 34px);
  font-weight: 400;
  text-shadow: 0 3px 15px rgba(0,0,0,.2);
}
.transition-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 17px;
  color: #d8cddd;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .7px;
}
.transition-meta > span:not(.difficulty-tag) {
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 7px;
  background: rgba(255,255,255,.045);
}
.dialogue-panel {
  position: relative;
  padding: 15px 17px 16px;
  text-align: left;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 15px;
  background: rgba(18,13,27,.42);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.035);
}
.dialogue-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 27px;
}
.dialogue-portrait {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255,255,255,.09);
  font-size: 18px;
}
.dialogue-speaker {
  color: #ffb2c3;
  font-size: 11px;
  font-weight: 900;
}
.dialogue-speaker.is-hero { color: #9be7b8; }
.dialogue-label {
  margin-left: auto;
  color: #a99ab6;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 1.3px;
}
.dialogue-text {
  min-height: 56px;
  margin: 10px 0 0;
  color: #f5edf6;
  font-size: 13px;
  line-height: 1.65;
  animation: dialogue-reveal .28s ease both;
}
.transition-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 17px;
}
.dialogue-progress {
  color: #bdb0c8;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1px;
}
.transition-footer .primary-button {
  margin: 0;
  padding: 11px 16px;
  font-size: 11px;
}
.transition-footer .primary-button span { margin-left: 9px; font-size: 15px; }
.transition-hint {
  margin: 11px 0 0;
  color: #9688a3;
  font-size: 9px;
}
@keyframes overlay-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes transition-card-in {
  from { opacity: 0; transform: translateY(22px) scale(.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes transition-monster {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-8px) rotate(3deg); }
}
@keyframes sparkle-float {
  0%, 100% { opacity: .45; transform: translateY(0) scale(.85) rotate(0); }
  50% { opacity: 1; transform: translateY(-6px) scale(1.2) rotate(18deg); }
}
@keyframes dialogue-reveal {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 520px) {
  .transition-card { padding: 20px 17px 17px; }
  .transition-scene { width: 100px; height: 100px; margin-top: 14px; }
  .transition-avatar { width: 76px; height: 76px; font-size: 53px; }
  .dialogue-text { min-height: 68px; font-size: 12px; }
  .transition-meta { gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  .candy-tile, .candy-piece, .transition-overlay, .transition-card,
  .transition-avatar, .scene-spark, .dialogue-text, .combat-hit,
  .hero-attack, .enemy-attack, .message-pop {
    animation: none !important;
  }
}

@keyframes enemy-arrive {
  0% { opacity: .55; transform: translateY(-12px) scale(.96); }
  65% { opacity: 1; transform: translateY(3px) scale(1.025); }
  100% { transform: translateY(0) scale(1); }
}
.enemy-arrive { animation: enemy-arrive .62s cubic-bezier(.2,.8,.25,1) both; }

/* Keep the level dialogue fully visible on shorter laptop screens. */
@media (max-height: 700px) {
  .transition-card {
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    padding: 14px 22px 13px;
  }
  .transition-scene { width: 78px; height: 78px; margin: 8px auto 4px; }
  .transition-avatar { width: 62px; height: 62px; border-radius: 20px; font-size: 44px; }
  .transition-title { font-size: 26px; }
  .transition-meta { margin: 7px 0 10px; }
  .dialogue-panel { padding: 10px 14px 11px; }
  .dialogue-text { min-height: 45px; margin-top: 6px; }
  .transition-footer { margin-top: 10px; }
  .transition-hint { margin-top: 6px; }
}

.transition-card { scrollbar-width: none; }
.transition-card::-webkit-scrollbar { display: none; }


/* =========================================================
   ACCESSIBLE CANDY SHAPES + NON-FLICKERING BOARD
   ========================================================= */
.candy-motion {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  transform: translate(0, 0);
  will-change: transform;
  pointer-events: none;
}
.candy-piece {
  position: relative;
  display: block;
  width: 72%;
  height: 72%;
  max-width: 44px;
  max-height: 44px;
  border: 2px solid rgba(255,255,255,.35);
  box-shadow: inset 3px 4px 5px rgba(255,255,255,.48),
              inset -5px -6px 8px rgba(0,0,0,.2),
              0 3px 5px rgba(0,0,0,.23);
  transform: none;
}
.candy-piece::before {
  content: "";
  position: absolute;
  left: 18%;
  top: 13%;
  width: 34%;
  height: 18%;
  border-radius: 50%;
  background: rgba(255,255,255,.62);
  transform: rotate(-27deg);
  filter: blur(.4px);
  z-index: 1;
}
.candy-piece::after {
  content: "";
  position: absolute;
  inset: 17%;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 30%;
}

/* Bentuk berbeda agar warna bukan satu-satunya petunjuk visual. */
.candy-piece.candy-0 {
  clip-path: circle(48% at 50% 50%);
  border-radius: 50%;
}
.candy-piece.candy-1 {
  clip-path: inset(4% round 23%);
  border-radius: 23%;
}
.candy-piece.candy-2 {
  clip-path: polygon(50% 2%, 98% 94%, 2% 94%);
  border-radius: 0;
}
.candy-piece.candy-3 {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  border-radius: 0;
}
.candy-piece.candy-4 {
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0% 50%);
  border-radius: 0;
}
.candy-piece.candy-5 {
  clip-path: polygon(50% 0%, 62% 34%, 98% 36%, 70% 59%, 80% 96%, 50% 75%, 20% 96%, 30% 59%, 2% 36%, 38% 34%);
  border-radius: 0;
}

/* Bentuk khusus tetap terbaca walaupun warnanya berbeda. */
.candy-piece.special-striped-h,
.candy-piece.special-striped-v {
  clip-path: inset(5% round 24%);
}
.candy-piece.special-wrapped {
  clip-path: inset(5% round 24%);
  border: 3px dashed rgba(255,255,255,.92);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.2), 0 0 11px rgba(255,220,138,.55);
}
.candy-piece.special-color-bomb {
  clip-path: circle(49% at 50% 50%);
  border-radius: 50%;
}
.special-mark {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 70%;
  height: 70%;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  color: #fff;
  font-family: Arial, sans-serif;
  font-size: clamp(12px, 2vw, 20px);
  line-height: 1;
  font-weight: 900;
  text-shadow: 0 1px 3px rgba(30,18,40,.9), 0 0 5px rgba(255,255,255,.55);
  pointer-events: none;
}
.special-mark[hidden] { display: none; }

/* Hanya candy baru yang memakai animasi masuk. Tombol grid tidak diulang animasinya. */
.candy-motion.candy-enter {
  animation: candy-enter .28s cubic-bezier(.2,.8,.25,1) both;
}
.candy-motion.candy-pop-out {
  animation: candy-pop-out .16s ease-in forwards;
}
.candy-motion.special-activating .candy-piece {
  animation: special-activate .42s ease-out both;
}
.candy-tile.has-special .candy-piece {
  animation: special-idle 2.4s ease-in-out infinite;
}
.candy-tile.clearing { animation: none !important; }

@keyframes candy-enter {
  from { opacity: 0; transform: translateY(-24px) scale(.62); }
  70% { opacity: 1; transform: translateY(3px) scale(1.06); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes candy-pop-out {
  0% { opacity: 1; transform: scale(1) rotate(0); filter: brightness(1); }
  45% { opacity: 1; transform: scale(1.18) rotate(8deg); filter: brightness(1.7); }
  100% { opacity: 0; transform: scale(.1) rotate(-16deg); filter: brightness(2); }
}
@media (prefers-reduced-motion: reduce) {
  .candy-motion, .candy-motion.candy-enter, .candy-motion.candy-pop-out,
  .candy-piece, .candy-tile.has-special .candy-piece {
    animation: none !important;
    transition: none !important;
  }
}


/* =========================================================
   SCORE, MAIN MENU, AND ENEMY DEFEAT FEEDBACK
   ========================================================= */
.menu-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-width: 470px;
  margin-top: 16px;
}
.menu-stat-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid rgba(245,199,107,.2);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(245,199,107,.10), rgba(255,255,255,.035));
}
.menu-stat-label { color: #f5d58b; font-size: 9px; font-weight: 900; letter-spacing: 1.1px; }
.menu-stat-card strong { color: #fff8ed; font-size: 24px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.menu-stat-card small { color: #bfb3ca; font-size: 9px; line-height: 1.35; }

.game-toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 14px; }
.game-toolbar-actions { display: flex; align-items: center; gap: 9px; }
.score-chip {
  display: flex;
  flex-direction: column;
  min-width: 92px;
  padding: 7px 12px;
  border: 1px solid rgba(245,199,107,.34);
  border-radius: 10px;
  background: rgba(245,199,107,.09);
}
.score-chip span { color: #f5d58b; font-size: 8px; font-weight: 900; letter-spacing: 1.2px; }
.score-chip strong { color: #fff8ed; font-size: 18px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.menu-button {
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px;
  color: #e7d9eb;
  background: rgba(255,255,255,.07);
  cursor: pointer;
  font-size: 10px;
  font-weight: 900;
  transition: transform .16s ease, background .16s ease;
}
.menu-button:hover { transform: translateY(-2px); background: rgba(255,255,255,.13); }

/* Special candies now have distinct silhouettes, not just a small icon. */
.candy-piece.special-striped-h {
  width: 91%;
  height: 54%;
  max-width: 52px;
  border-radius: 999px;
  clip-path: inset(0 round 999px);
  transform: rotate(-7deg);
  background-image: repeating-linear-gradient(0deg, transparent 0 5px, rgba(255,255,255,.82) 5px 8px);
  border: 2px solid rgba(255,255,255,.8);
}
.candy-piece.special-striped-v {
  width: 54%;
  height: 91%;
  max-height: 52px;
  border-radius: 999px;
  clip-path: inset(0 round 999px);
  transform: rotate(7deg);
  background-image: repeating-linear-gradient(90deg, transparent 0 5px, rgba(255,255,255,.82) 5px 8px);
  border: 2px solid rgba(255,255,255,.8);
}
.candy-piece.special-striped-h::before,
.candy-piece.special-striped-v::before { display: none; }
.candy-piece.special-striped-h::after,
.candy-piece.special-striped-v::after {
  inset: 0;
  border: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,255,255,.22), transparent 48%, rgba(0,0,0,.12));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.candy-piece.special-wrapped {
  width: 76%;
  height: 76%;
  clip-path: polygon(14% 2%, 86% 2%, 100% 16%, 100% 84%, 86% 98%, 14% 98%, 0 84%, 0 16%);
  border: 2px solid rgba(255,255,255,.95);
  border-radius: 8px;
  transform: rotate(0deg);
  background-image:
    linear-gradient(90deg, transparent 38%, rgba(255,255,255,.83) 39% 46%, rgba(255,255,255,.83) 54% 61%, transparent 62%),
    linear-gradient(0deg, transparent 38%, rgba(255,255,255,.83) 39% 46%, rgba(255,255,255,.83) 54% 61%, transparent 62%);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.14), 0 0 12px rgba(255,220,138,.55);
}
.candy-piece.special-wrapped::before {
  display: block;
  left: 35%;
  top: 34%;
  width: 30%;
  height: 30%;
  border: 2px solid rgba(255,255,255,.95);
  border-radius: 50%;
  background: rgba(255,255,255,.24);
  transform: none;
}
.candy-piece.special-wrapped::after {
  inset: 5%;
  border: 1px dashed rgba(255,255,255,.95);
  border-radius: 5px;
  background: transparent;
}
.candy-piece.special-color-bomb {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  clip-path: circle(49% at 50% 50%);
  border: 3px solid rgba(255,255,255,.92);
  transform: rotate(0deg);
  background:
    radial-gradient(circle at 27% 25%, #fff 0 5%, transparent 6%),
    radial-gradient(circle at 72% 24%, #ffdc69 0 8%, transparent 9%),
    radial-gradient(circle at 25% 70%, #ff6f9a 0 9%, transparent 10%),
    radial-gradient(circle at 73% 72%, #6bd9d0 0 9%, transparent 10%),
    radial-gradient(circle at 50% 50%, #fff3cb 0 12%, #59436f 14% 43%, #171221 72%);
  box-shadow: inset 0 0 12px rgba(255,255,255,.8), 0 0 15px rgba(245,199,107,.82);
}
.candy-piece.special-color-bomb::before,
.candy-piece.special-color-bomb::after { display: none; }
.candy-tile.has-special .special-mark { font-size: clamp(10px, 1.7vw, 17px); }

/* Brief non-blocking reward notification after an enemy is defeated. */
.enemy-defeat-toast {
  position: fixed;
  z-index: 60;
  top: 22px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(390px, calc(100% - 28px));
  padding: 13px 17px;
  border: 1px solid rgba(245,199,107,.62);
  border-radius: 15px;
  color: #fff8ed;
  background: linear-gradient(135deg, rgba(76,55,87,.98), rgba(42,31,57,.98));
  box-shadow: 0 15px 42px rgba(0,0,0,.38), 0 0 24px rgba(245,199,107,.15);
  pointer-events: none;
  transform: translate(-50%, -22px) scale(.94);
  opacity: 0;
}
.enemy-defeat-toast.show { animation: defeat-toast-in .34s cubic-bezier(.2,.85,.25,1.2) forwards; }
.enemy-defeat-toast.hide { animation: defeat-toast-out .28s ease forwards; }
.defeat-toast-icon { display: grid; place-items: center; width: 42px; height: 42px; flex: 0 0 42px; border-radius: 12px; background: rgba(245,199,107,.15); font-size: 24px; }
.defeat-toast-copy { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.defeat-toast-copy strong { color: #ffe39b; font-size: 11px; letter-spacing: 1px; }
.defeat-toast-copy small { color: #d8cddd; font-size: 10px; }
.defeat-toast-spark { margin-left: auto; color: #ffe39b; font-size: 22px; animation: toast-sparkle .7s ease-in-out infinite alternate; }
@keyframes defeat-toast-in {
  0% { opacity: 0; transform: translate(-50%, -22px) scale(.92); }
  70% { opacity: 1; transform: translate(-50%, 4px) scale(1.025); }
  100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
@keyframes defeat-toast-out {
  to { opacity: 0; transform: translate(-50%, -12px) scale(.96); }
}
@keyframes toast-sparkle { from { opacity: .45; transform: scale(.8) rotate(-15deg); } to { opacity: 1; transform: scale(1.15) rotate(15deg); } }

@media (max-width: 720px) {
  .start-screen { grid-template-columns: 1fr; }
  .menu-stats { max-width: none; }
  .game-toolbar { align-items: flex-end; flex-direction: column; gap: 7px; }
  .game-toolbar-actions { width: 100%; justify-content: flex-end; }
  .score-chip { min-width: 82px; padding: 6px 9px; }
  .score-chip strong { font-size: 16px; }
  .menu-button { padding: 8px 10px; }
}
@media (max-width: 390px) {
  .menu-stats { gap: 7px; }
  .menu-stat-card { padding: 9px; }
  .menu-stat-card strong { font-size: 20px; }
  .menu-stat-label { font-size: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .enemy-defeat-toast.show, .enemy-defeat-toast.hide, .defeat-toast-spark { animation: none !important; }
}

.score-pop { animation: score-pop .28s ease-out; }
@keyframes score-pop {
  0% { transform: scale(1); color: #fff8ed; }
  45% { transform: scale(1.22); color: #ffe39b; }
  100% { transform: scale(1); color: #fff8ed; }
}

.ending-menu-button { display: block; width: 100%; margin-top: 9px; padding: 11px 16px; }
.ending-card .secondary-button { color: #e5d8e9; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.13); }

/* =========================================================
   LEVEL SELECT MAP + CHECKPOINTS
   ========================================================= */
.level-select-screen {
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 26px;
  background: linear-gradient(135deg, rgba(64,46,81,.94), rgba(43,31,59,.97));
  box-shadow: var(--shadow);
}
.level-select-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 28px;
  margin-bottom: 20px;
}
.level-select-intro {
  max-width: 590px;
  color: #ded5e7;
  font-size: 13px;
  line-height: 1.6;
  margin: 9px 0 0;
}
.level-progress-summary {
  width: min(270px, 36%);
  flex: 0 0 auto;
  padding: 13px 15px;
  border: 1px solid rgba(245,199,107,.2);
  border-radius: 13px;
  background: rgba(255,255,255,.045);
}
.level-progress-summary strong,
.level-progress-summary small { display: block; }
.level-progress-summary strong {
  color: var(--gold);
  font-size: 10px;
  letter-spacing: 1px;
}
.level-progress-summary small {
  margin-top: 8px;
  color: var(--muted);
  font-size: 10px;
}
.level-progress-track {
  height: 7px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(0,0,0,.28);
}
.level-progress-track span {
  display: block;
  width: 10%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e8ae58, #ffe29a);
  transition: width .35s ease;
}
.level-select-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(270px, .65fr);
  gap: 18px;
  align-items: stretch;
}
.level-map-card,
.level-details-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(57,41,73,.96), rgba(43,31,58,.98));
  box-shadow: 0 12px 30px rgba(0,0,0,.12);
}
.level-map-card { padding: 18px; }
.level-map-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 17px;
}
.level-map-heading h2 { margin: 0; font-size: 19px; }
.map-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 9px;
  white-space: nowrap;
}
.map-legend i {
  width: 8px;
  height: 8px;
  display: inline-block;
  border-radius: 50%;
}
.legend-open { background: var(--gold); }
.legend-locked { background: #665b70; margin-left: 7px; }
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.level-node {
  position: relative;
  min-width: 0;
  min-height: 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px 5px;
  border: 1px solid rgba(245,199,107,.3);
  border-radius: 14px;
  color: var(--ink);
  background: linear-gradient(145deg, rgba(116,79,111,.8), rgba(66,49,82,.94));
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, filter .16s ease, opacity .16s ease;
}
.level-node:hover:not(:disabled) { transform: translateY(-3px); filter: brightness(1.1); }
.level-node:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.level-node.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(245,199,107,.16), 0 8px 20px rgba(0,0,0,.18);
  background: linear-gradient(145deg, rgba(142,96,111,.95), rgba(79,53,84,.98));
}
.level-node.completed { border-color: rgba(117,214,160,.4); }
.level-node.locked {
  color: #9e94a8;
  border-color: rgba(255,255,255,.055);
  background: linear-gradient(145deg, rgba(64,56,72,.7), rgba(47,41,56,.85));
  filter: grayscale(1);
  opacity: .58;
  cursor: pointer;
}
.level-node-number {
  color: var(--gold);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1px;
}
.level-node.locked .level-node-number { color: #a49aa9; }
.level-node-avatar { font-size: 30px; line-height: 1.15; filter: drop-shadow(0 4px 4px rgba(0,0,0,.22)); }
.level-node-name {
  width: 100%;
  overflow: hidden;
  color: inherit;
  font-size: 9px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.level-node-status {
  color: #d1c5d9;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .6px;
}
.level-node.completed .level-node-status { color: #9be7b8; }
.level-node.locked .level-node-status { color: #a49aa9; }
.level-details-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 19px;
}
.selected-level-avatar {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin: 2px 0 12px;
  border: 1px solid rgba(245,199,107,.24);
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(245,199,107,.15), rgba(245,142,174,.12));
  font-size: 42px;
  box-shadow: 0 8px 20px rgba(0,0,0,.16);
}
.selected-level-number {
  color: var(--gold);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1.5px;
}
.level-details-card h2 {
  margin: 4px 0 8px;
  font-family: "Rye", serif;
  font-weight: 400;
  font-size: 22px;
}
.selected-level-tags { display: flex; align-items: center; gap: 8px; }
.selected-level-hp {
  padding: 4px 7px;
  border-radius: 6px;
  color: #f4d797;
  background: rgba(245,199,107,.1);
  font-size: 9px;
  font-weight: 900;
}
.selected-level-location {
  margin: 13px 0 5px;
  color: #f0c5d2;
  font-size: 11px;
  font-weight: 900;
}
.selected-level-description {
  margin: 0;
  color: #d3c8dc;
  font-size: 11px;
  line-height: 1.65;
}
.level-detail-divider {
  width: 100%;
  margin: 14px 0 10px;
  border-top: 1px solid var(--line);
}
.level-detail-meta {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 5px 0;
  color: var(--muted);
  font-size: 10px;
}
.level-detail-meta strong {
  color: var(--ink);
  text-align: right;
  font-size: 9px;
  letter-spacing: .5px;
}
#selectedLevelStatus { color: #9be7b8; }
.level-launch-button { width: 100%; margin-top: auto; }
.level-launch-button:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.level-select-hint {
  margin: 10px 0 0;
  color: #bdb0c9;
  font-size: 9px;
  line-height: 1.55;
}
.level-select-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  margin-top: 18px;
}
.level-select-footer .secondary-button { padding: 10px 14px; color: var(--ink); background: rgba(255,255,255,.08); border: 1px solid var(--line); }
.level-select-footer > span { color: var(--muted); font-size: 10px; text-align: right; }

/* =========================================================
   FIRST-TIME POWER TUTORIAL
   ========================================================= */
.power-tutorial-overlay { z-index: 35; }
.power-tutorial-card {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid rgba(245,199,107,.36);
  border-radius: 22px;
  background: linear-gradient(145deg, #463252, #2a1d3b);
  box-shadow: 0 22px 65px rgba(0,0,0,.4);
  text-align: center;
  animation: tutorial-card-in .3s cubic-bezier(.2,.85,.25,1.15) both;
}
.power-tutorial-icon {
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  margin: 10px auto 14px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 24px;
  color: #fff8ed;
  background: radial-gradient(circle at 35% 25%, rgba(255,255,255,.25), rgba(245,199,107,.12));
  font-size: 48px;
  text-shadow: 0 4px 12px rgba(0,0,0,.28);
  box-shadow: 0 10px 25px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.16);
}
.power-tutorial-card h2 {
  margin: 0 0 10px;
  color: var(--gold);
  font-family: "Rye", serif;
  font-size: 25px;
  font-weight: 400;
}
.power-tutorial-description {
  margin: 0 auto;
  max-width: 340px;
  color: #f1e7f4;
  font-size: 13px;
  line-height: 1.7;
}
.power-tutorial-hint {
  margin-top: 15px;
  padding: 12px 14px;
  border: 1px solid rgba(117,214,160,.18);
  border-radius: 12px;
  color: #bde8ca;
  background: rgba(117,214,160,.07);
  font-size: 11px;
  line-height: 1.6;
}
.power-tutorial-card .primary-button { width: 100%; margin-top: 20px; }
@keyframes tutorial-card-in {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 850px) {
  .level-select-layout { grid-template-columns: 1fr; }
  .level-details-card { display: grid; grid-template-columns: 74px 1fr; column-gap: 14px; align-items: center; }
  .level-details-card > .eyebrow { grid-column: 1 / -1; }
  .selected-level-avatar { grid-row: span 4; margin: 0; }
  .level-details-card h2,
  .selected-level-number,
  .selected-level-tags,
  .selected-level-location,
  .selected-level-description,
  .level-detail-divider,
  .level-detail-meta,
  .level-launch-button,
  .level-select-hint { grid-column: 1 / -1; }
  .level-launch-button { margin-top: 14px; }
}
@media (max-width: 600px) {
  .level-select-screen { padding: 15px; }
  .level-select-header { display: block; }
  .level-progress-summary { width: 100%; margin-top: 15px; }
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .level-node { min-height: 103px; }
  .level-map-heading { align-items: flex-start; flex-direction: column; }
  .level-select-footer { align-items: flex-start; flex-direction: column; }
  .level-select-footer > span { text-align: left; }
  .power-tutorial-card { padding: 22px 18px; }
}


/* =========================================================
   8-BIT AUDIO CONTROLS
   ========================================================= */
.header-tools { display:flex; align-items:center; gap:18px; }
.audio-controls { display:flex; align-items:center; gap:7px; }
.audio-toggle {
  border:1px solid rgba(245,199,107,.25); border-radius:9px; padding:7px 9px;
  color:#f8e9c8; background:rgba(255,255,255,.055); font-size:9px; font-weight:900;
  cursor:pointer; transition:background .15s ease, border-color .15s ease;
}
.audio-toggle[aria-pressed="true"] { border-color:rgba(117,214,160,.42); background:rgba(117,214,160,.09); }
.audio-toggle.audio-off { color:#a99eaf; border-color:rgba(255,255,255,.08); }
.audio-volume { display:flex; align-items:center; gap:6px; color:#bdb1c9; font-size:8px; font-weight:900; letter-spacing:.8px; }
.audio-volume input { width:70px; accent-color:var(--gold); cursor:pointer; }
.start-menu-actions { display:flex; align-items:center; flex-wrap:wrap; gap:10px; margin-top:18px; }
.start-menu-actions .primary-button { margin-top:0; }
.achievement-menu-button { margin-top:0; color:#f3e2bd; border:1px solid rgba(245,199,107,.26); background:rgba(255,255,255,.055); }
.level-footer-actions { display:flex; gap:9px; }
.level-footer-actions .secondary-button { width:auto; }

/* Enemy telegraph panel and status effects */
.enemy-ability-panel {
  display:flex; align-items:center; gap:12px; margin:0 0 16px; padding:11px 14px;
  border:1px solid rgba(245,199,107,.18); border-radius:14px;
  background:linear-gradient(110deg,rgba(74,54,85,.88),rgba(48,35,65,.94));
  box-shadow:0 8px 22px rgba(0,0,0,.12); transition:border-color .2s ease, background .2s ease;
}
.enemy-ability-icon { width:40px; height:40px; flex:0 0 40px; display:grid; place-items:center; border-radius:12px; background:rgba(245,199,107,.12); font-size:22px; }
.enemy-ability-copy { min-width:0; flex:1; }
.enemy-ability-label { display:block; margin-bottom:2px; color:#d3b978; font-size:8px; font-weight:900; letter-spacing:1.2px; }
.enemy-ability-copy strong { display:block; color:#fff4d9; font-size:12px; }
.enemy-ability-copy p { margin:2px 0 0; color:#c7b9d1; font-size:10px; line-height:1.4; }
.enemy-ability-state { flex:0 0 auto; padding:5px 8px; border:1px solid rgba(245,199,107,.2); border-radius:7px; color:#ebd18d; font-size:8px; font-weight:900; letter-spacing:.7px; }
.enemy-ability-panel.warning { border-color:rgba(251,120,135,.55); background:linear-gradient(110deg,rgba(114,47,69,.92),rgba(61,34,66,.96)); animation:ability-warning-pulse 1s ease-in-out infinite alternate; }
.enemy-ability-panel.warning .enemy-ability-label,.enemy-ability-panel.warning .enemy-ability-state { color:#ffabb4; }
.enemy-ability-panel.active { border-color:rgba(245,199,107,.65); background:linear-gradient(110deg,rgba(104,66,45,.94),rgba(64,42,72,.96)); }
.enemy-ability-panel.active .enemy-ability-state { color:#fff0b8; background:rgba(245,199,107,.12); }
.candy-tile.candy-locked { border-color:rgba(173,179,198,.6)!important; filter:saturate(.55) brightness(.8); cursor:not-allowed; }
.candy-tile.candy-locked::after { content:"🔒"; position:absolute; z-index:5; right:1px; bottom:1px; font-size:clamp(8px,1vw,12px); line-height:1; filter:drop-shadow(0 1px 2px #1b1225); }
.candy-tile.candy-cursed { border-color:rgba(178,119,255,.88)!important; box-shadow:inset 0 0 0 1px rgba(181,112,255,.35),0 0 9px rgba(174,92,255,.3); }
.candy-tile.candy-cursed::after { content:"☠"; position:absolute; z-index:5; right:2px; top:1px; color:#e0b7ff; font-size:clamp(8px,1vw,12px); line-height:1; text-shadow:0 1px 3px #20112b; }
@keyframes ability-warning-pulse { from { box-shadow:0 0 0 rgba(251,120,135,0); } to { box-shadow:0 0 20px rgba(251,120,135,.17); } }
.enemy-ability-cast { animation:enemy-ability-cast .65s ease-in-out both; }
@keyframes enemy-ability-cast { 0%{transform:translateY(0) scale(1)} 35%{transform:translateY(-7px) scale(1.08);filter:brightness(1.4)} 70%{transform:translateY(2px) scale(.96)} 100%{transform:translateY(0) scale(1);filter:none} }

/* Achievement collection */
.achievement-overlay { z-index:50; }
.achievement-modal {
  width:min(760px,100%); max-height:min(88vh,850px); overflow:hidden; display:flex; flex-direction:column;
  padding:24px; border:1px solid rgba(245,199,107,.32); border-radius:22px;
  background:linear-gradient(145deg,#453252,#281d38); box-shadow:0 28px 90px rgba(0,0,0,.5);
  animation:tutorial-card-in .25s ease both;
}
.achievement-modal-heading { flex:0 0 auto; text-align:center; }
.achievement-modal-heading h2 { margin:0; color:var(--gold); font-family:"Rye",serif; font-size:25px; font-weight:400; }
.achievement-modal-heading p:not(.eyebrow) { margin:7px 0 0; color:#cfc1d7; font-size:11px; }
.achievement-progress-track { height:7px; margin:12px 0 16px; overflow:hidden; border-radius:99px; background:rgba(0,0,0,.3); }
.achievement-progress-track span { display:block; width:0; height:100%; border-radius:inherit; background:linear-gradient(90deg,#e8ae58,#ffe29a); transition:width .25s ease; }
.achievement-list { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:9px; overflow:auto; padding:2px 4px 10px 0; }
.achievement-item { min-width:0; display:grid; grid-template-columns:42px minmax(0,1fr) auto; align-items:center; gap:9px; padding:10px; border:1px solid rgba(255,255,255,.09); border-radius:12px; background:rgba(255,255,255,.045); }
.achievement-item.locked { opacity:.58; filter:grayscale(.8); }
.achievement-item.unlocked { border-color:rgba(245,199,107,.28); background:rgba(245,199,107,.055); }
.achievement-item.claimed { border-color:rgba(117,214,160,.25); background:rgba(117,214,160,.055); }
.achievement-item-icon { width:40px; height:40px; display:grid; place-items:center; border-radius:11px; background:rgba(245,199,107,.11); font-size:20px; }
.achievement-item-copy { min-width:0; }
.achievement-item-copy strong { display:block; color:#fff3d9; font-size:11px; }
.achievement-item-copy p { margin:3px 0; color:#c7b9d1; font-size:9px; line-height:1.35; }
.achievement-item-copy small { color:#e8c77f; font-size:8px; font-weight:900; }
.achievement-claim-button { align-self:center; padding:7px 8px; border:1px solid rgba(245,199,107,.28); border-radius:8px; color:#342238; background:linear-gradient(135deg,#ffdc8a,#eeb65c); font-size:8px; font-weight:900; cursor:pointer; }
.achievement-claim-button:disabled { color:#ada2b4; border-color:rgba(255,255,255,.08); background:rgba(255,255,255,.06); cursor:not-allowed; }
.achievement-claim-button.is-claimed { color:#9be7b8; border-color:rgba(117,214,160,.25); background:rgba(117,214,160,.08); }
.achievement-modal > .secondary-button { flex:0 0 auto; margin-top:13px; }
.achievement-toast {
  position:fixed; z-index:60; top:22px; right:22px; display:flex; align-items:center; gap:11px;
  width:min(340px,calc(100% - 32px)); padding:13px 16px; border:1px solid rgba(245,199,107,.48);
  border-radius:13px; background:linear-gradient(120deg,#4b3457,#30213f); box-shadow:0 14px 35px rgba(0,0,0,.32);
}
.achievement-toast.show { animation:toast-in .28s cubic-bezier(.2,.85,.25,1.15) both; }
.achievement-toast.hide { animation:toast-out .25s ease both; }
.achievement-toast-icon { font-size:26px; }
.achievement-toast strong,.achievement-toast small { display:block; }
.achievement-toast strong { color:var(--gold); font-size:10px; letter-spacing:.6px; }
.achievement-toast small { margin-top:3px; color:#e0d3e8; font-size:10px; }

@media (max-width:900px) {
  .header-tools { gap:9px; }
  .audio-controls { gap:4px; }
  .audio-toggle { padding:6px 7px; font-size:8px; }
  .audio-volume input { width:52px; }
}
@media (max-width:720px) {
  .site-header { flex-wrap:wrap; gap:7px; padding:12px 0; }
  .header-tools { width:100%; justify-content:space-between; }
  .audio-controls { flex-wrap:wrap; }
  .enemy-ability-panel { align-items:flex-start; padding:10px; }
  .enemy-ability-icon { width:34px; height:34px; flex-basis:34px; font-size:19px; }
  .enemy-ability-state { font-size:7px; padding:4px 5px; }
  .achievement-modal { padding:18px 13px; max-height:90vh; }
  .achievement-list { grid-template-columns:1fr; }
  .level-footer-actions { flex-wrap:wrap; }
}

/* State emphasis for enemy ability telegraph / execution */
.enemy-ability-panel.warning .enemy-ability-name { color:#ffd5a1; }
.enemy-ability-panel.active .enemy-ability-name { color:#fff0b8; }
.enemy-ability-panel.idle .enemy-ability-state { opacity:.78; }

/* Enemy ability preview on the level selection map */
.level-ability-preview { margin-top:13px; padding:11px 12px; border:1px solid rgba(245,199,107,.2); border-radius:11px; background:rgba(245,199,107,.055); }
.level-ability-preview-label { display:block; color:#d3b978; font-size:8px; font-weight:900; letter-spacing:1.1px; }
.level-ability-preview strong { display:block; margin-top:4px; color:#fff0c9; font-size:12px; }
.level-ability-preview p { margin:5px 0 0; color:#c7b9d1; font-size:10px; line-height:1.5; }
