/* Terang Percaya Diri — bahasa desain "kayu minimalis" (v0.4.1).
   Palet: kayu gelap → terang, perkamen, satu aksen emas. Merah/hijau/biru redup hanya untuk fungsi
   (damage, HP, perisai). Panel datar dengan bingkai kayu dua garis, tanpa gradasi mencolok. */

@property --charge {
  syntax: '<number>';
  inherits: true;
  initial-value: 0;
}

:root {
  --w9: #1f130b;
  --w8: #2e1c10;
  --w7: #44291a;
  --w6: #5e3a22;
  --w5: #7d5131;
  --w4: #a0703f;
  --parch: #efe0bf;
  --parch-2: #d6c093;
  --ink: #2b1d12;
  --gold: #e3b04b;
  --red: #c4483b;
  --green: #7fa04a;
  --blue: #6d8fa8;
  --grain: repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.06) 0 2px, transparent 2px 11px);
  --font-display: 'Lilita One', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  background: var(--w9);
  color: var(--parch);
  font: 600 15px/1.4 var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; letter-spacing: 0.02em; margin: 0; }

#app { position: relative; z-index: 2; }

.screen {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

/* Panel kayu: isi datar, bingkai gelap + garis terang di dalam. */
.wood, .slot, .opt, .dock, .sheet, .icon-btn, .round-badge {
  background: var(--grain), var(--w7);
  border: 3px solid var(--w9);
  box-shadow: inset 0 0 0 2px var(--w5);
}

/* ---------- Latar: lorong gerbang kayu (zoom tak berujung) ---------- */

#bg {
  position: fixed; inset: 0; z-index: 0; overflow: hidden;
  background: radial-gradient(ellipse at 50% 50%, #120a05 0%, var(--w8) 60%, var(--w9) 100%);
}
.tunnel-zoom { position: absolute; inset: 0; transform-origin: 50% 50%; }

.gate {
  position: absolute; left: 50%; top: 50%;
  width: 118vw; height: 112vh;
  transform: translate(-50%, -50%) scale(var(--s));
  border: 3.4vmin solid var(--w6);
  border-bottom: 0;
  box-shadow: inset 0 0 0 0.9vmin var(--w8);
}
.gate::after {
  content: ''; position: absolute; left: -3.4vmin; right: -3.4vmin; bottom: 0;
  height: 1.6vmin; background: var(--w7);
}
.gate .beam {
  position: absolute; top: -8vmin; left: -9vmin; right: -9vmin;
  height: 4vmin; border-radius: 1vmin;
  background: var(--w5);
  box-shadow: 0 1.2vmin 0 var(--w8);
}
.gate .lamp {
  position: absolute; top: 2vmin;
  width: 2.6vmin; height: 3.6vmin; border-radius: 1vmin;
  background: var(--gold);
  box-shadow: 0 0 4vmin 1.5vmin rgba(227, 176, 75, 0.35);
}
.gate .lamp.l { left: 2vmin; }
.gate .lamp.r { right: 2vmin; }
.fog {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 34% 30% at 50% 50%, rgba(14, 8, 4, 0.97) 0%, rgba(14, 8, 4, 0.6) 55%, transparent 100%),
    radial-gradient(ellipse at 50% 50%, transparent 50%, rgba(14, 8, 4, 0.75) 100%);
}

/* ---------- Suasana kartu event ---------- */

#ambient { position: fixed; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
#ambient i { position: absolute; left: calc(var(--x) * 1%); top: calc(var(--y) * 1%); display: block; }
#ambient.tint-gold { box-shadow: inset 0 0 18vmin rgba(227, 176, 75, 0.22); }
#ambient.tint-steel { box-shadow: inset 0 0 18vmin rgba(109, 143, 168, 0.28); }
#ambient.tint-blood { animation: tintPulse 2.4s ease-in-out infinite; --tint: rgba(196, 72, 59, 0.35); }
#ambient.tint-sage { box-shadow: inset 0 0 18vmin rgba(127, 160, 74, 0.22); }
#ambient.tint-rain { box-shadow: inset 0 0 22vmin rgba(40, 52, 64, 0.55); }
#ambient.tint-ember { animation: tintPulse 3s ease-in-out infinite; --tint: rgba(217, 130, 43, 0.3); }
#ambient.tint-spirit { box-shadow: inset 0 0 18vmin rgba(239, 224, 191, 0.2); }
#ambient.tint-frenzy { animation: tintPulse 0.9s ease-in-out infinite; --tint: rgba(196, 72, 59, 0.38); }
@keyframes tintPulse { 0%, 100% { box-shadow: inset 0 0 10vmin var(--tint); } 50% { box-shadow: inset 0 0 24vmin var(--tint); } }

.p-leaf {
  width: calc(14px * var(--s)); height: calc(8px * var(--s));
  background: var(--w4); border-radius: 0 100% 0 100%; opacity: 0.75;
  animation: leafFall calc(11s * var(--t)) linear infinite; animation-delay: calc(var(--d) * -11s);
}
@keyframes leafFall {
  from { transform: translate(0, -60vh) rotate(0); }
  50% { transform: translate(6vw, 0) rotate(200deg); }
  to { transform: translate(-4vw, 60vh) rotate(420deg); }
}
.p-mote {
  width: calc(6px * var(--s)); height: calc(6px * var(--s)); border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 8px var(--gold); opacity: 0;
  animation: moteRise calc(8s * var(--t)) ease-in-out infinite; animation-delay: calc(var(--d) * -8s);
}
#ambient.tint-sage .p-mote { background: #b9cf8a; box-shadow: 0 0 8px #b9cf8a; }
#ambient.tint-spirit .p-mote { background: var(--parch); box-shadow: 0 0 10px var(--parch); }
@keyframes moteRise { 0% { transform: translateY(40vh); opacity: 0; } 30%, 70% { opacity: 0.8; } 100% { transform: translateY(-50vh); opacity: 0; } }
.p-wind {
  width: calc(90px * var(--s)); height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, rgba(239, 224, 191, 0.4), transparent);
  animation: windBlow calc(1.8s * var(--t)) linear infinite; animation-delay: calc(var(--d) * -1.8s);
}
@keyframes windBlow { from { transform: translateX(-60vw); } to { transform: translateX(80vw); } }
.p-rain {
  width: 2px; height: calc(22px * var(--s));
  background: linear-gradient(transparent, rgba(214, 192, 147, 0.5));
  animation: rainFall calc(0.75s * var(--t)) linear infinite; animation-delay: calc(var(--d) * -0.75s);
}
@keyframes rainFall { from { transform: translate(0, -60vh) rotate(12deg); } to { transform: translate(-12vw, 60vh) rotate(12deg); } }
.p-ember {
  width: calc(5px * var(--s)); height: calc(5px * var(--s)); border-radius: 50%;
  background: #e0782f; box-shadow: 0 0 8px #e0782f;
  animation: emberRise calc(4.5s * var(--t)) ease-out infinite; animation-delay: calc(var(--d) * -4.5s);
}
@keyframes emberRise {
  0% { transform: translate(0, 45vh); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(5vw, -40vh); opacity: 0; }
}

/* ---------- Tombol ---------- */

.btn {
  border: 3px solid var(--w9);
  border-radius: 10px;
  padding: 11px 18px;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.03em;
  color: var(--parch);
  background: var(--w6);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25), inset 0 0 0 2px rgba(255, 255, 255, 0.08);
  transition: transform 0.08s, filter 0.15s;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25); }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn.big { font-size: 22px; padding: 14px 22px; }
.btn-play, .btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold { background: var(--parch); }
.btn-fire { background: var(--red); color: var(--parch); }
.btn-heal { background: var(--green); color: var(--ink); }
.btn-shield { background: var(--blue); color: var(--ink); }
.btn-danger { background: #8e2f25; }
.btn-ghost { background: var(--w7); }
.pulse-btn { animation: btnPulse 1.8s ease-in-out infinite; }
@keyframes btnPulse { 50% { filter: brightness(1.15); } }

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 10px;
  font-size: 22px; line-height: 1;
  display: grid; place-items: center;
  color: var(--parch);
}

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn-row .btn.big { flex: 2; }

.tag {
  display: inline-block;
  font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 1px 6px; border-radius: 4px;
  background: var(--w8); color: var(--parch-2);
  border: 1px solid var(--w9);
}
.tag.red { background: var(--red); color: var(--parch); }
.tag.gold { background: var(--gold); color: var(--ink); }
.tag.blue { background: var(--blue); color: var(--ink); }
.tag.green { background: var(--green); color: var(--ink); }

/* ---------- Layar judul ---------- */

.title-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; }
.title-orbit { position: relative; width: 300px; height: 150px; margin-bottom: 6px; }
.orbit-av {
  --a: calc(-70deg + var(--i) * 20deg);
  position: absolute; left: 50%; top: 100%;
  width: 52px; height: 52px; margin: -26px 0 0 -26px;
  transform: rotate(var(--a)) translateY(-118px) rotate(calc(var(--a) * -1));
  animation: bob 3s ease-in-out infinite; animation-delay: calc(var(--i) * -0.4s);
}
.orbit-av, .slot-avatar, .pick-av, .mini-av, .duel-av, .winner-av {
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, var(--parch) 55%, var(--parch-2));
  border: 3px solid var(--c, var(--w5));
  box-shadow: 0 0 0 3px var(--w9);
  padding: 4px;
}
.orbit-av svg, .slot-avatar svg, .pick-av svg, .avatar svg, .mini-av svg, .duel-av svg, .winner-av svg { width: 100%; height: 100%; display: block; }
@keyframes bob { 0%, 100% { margin-top: -26px; } 50% { margin-top: -34px; } }

.logo { display: flex; flex-direction: column; line-height: 0.95; text-shadow: 0 4px 0 var(--w9), 0 0 2px var(--w9); }
.logo span:first-child { font-size: 58px; color: var(--gold); }
.logo span:last-child { font-size: 40px; color: var(--parch); }
.tagline { color: var(--parch-2); margin: 4px 0 16px; font-weight: 800; }
.title-menu { display: grid; gap: 10px; width: min(320px, 100%); }
.version { color: var(--parch-2); opacity: 0.7; font-size: 12px; margin-top: 18px; }

/* ---------- Lobby ---------- */

.screen-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.screen-head h2 { font-size: 26px; text-shadow: 0 3px 0 var(--w9); }

.slots { display: grid; gap: 10px; }
.slot { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; }
.slot-avatar { position: relative; flex: none; width: 62px; height: 62px; }
.slot-avatar .edit {
  position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%);
  font-size: 10px; font-weight: 900; text-transform: uppercase;
  background: var(--w9); color: var(--parch); border-radius: 4px; padding: 1px 6px;
}
.slot-body { flex: 1; display: grid; gap: 6px; min-width: 0; }
.slot input {
  width: 100%;
  background: var(--w9);
  border: 2px solid var(--w6);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--parch);
  font: 800 16px var(--font-body);
}
.slot input::placeholder { color: var(--parch-2); opacity: 0.6; }
.slot input:focus { outline: none; border-color: var(--gold); }
.type-pill {
  justify-self: start;
  border: 2px solid var(--w9); border-radius: 6px;
  padding: 3px 10px;
  font-weight: 900; font-size: 13px;
  display: inline-flex; gap: 6px; align-items: center;
}
.type-pill.human { background: var(--parch); color: var(--ink); }
.type-pill.bot { background: var(--w8); color: var(--parch-2); }
.type-pill span { opacity: 0.6; }
.slot-no { position: absolute; top: 8px; right: 12px; font-family: var(--font-display); color: var(--c); }

.count-row { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 16px 0; font-size: 18px; }
.count-row b { font-family: var(--font-display); font-size: 26px; color: var(--gold); }

.options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 16px; }
.opt { border-radius: 10px; padding: 9px 8px; display: grid; gap: 2px; justify-items: center; font-size: 12px; color: var(--parch-2); }
.opt b { font-family: var(--font-display); font-weight: 400; font-size: 17px; color: var(--parch-2); }
.opt b.on { color: var(--gold); }
.lobby > .btn-play { width: 100%; }

/* ---------- Mode online ---------- */

.btn-wood { background: var(--w5); }
.online-home, .online-lobby { display: flex; flex-direction: column; gap: 12px; }
.online-home .screen-head, .online-lobby .screen-head { margin-bottom: 0; }
.online-card { border-radius: 12px; padding: 14px; display: grid; gap: 10px; }
.online-card h3 { font-size: 20px; color: var(--gold); }
.online-card .sheet-text { margin: 0; }
.online-notice { background: var(--red); color: var(--parch); padding: 8px 12px; border-radius: 8px; font-weight: 800; }
.hint { color: var(--parch-2); opacity: 0.75; font-size: 12px; }
.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1; min-width: 0;
  font-family: var(--font-display); font-size: 26px; letter-spacing: 0.3em; text-align: center; text-transform: uppercase;
  background: var(--w9); color: var(--gold); border: 2px solid var(--w5); border-radius: 10px; padding: 6px 10px;
}
.join-row input:focus { outline: none; border-color: var(--gold); }
.code-card { border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; justify-items: center; text-align: center; }
.code-card .btn-row { width: 100%; }
.room-code { font-family: var(--font-display); font-weight: 400; font-size: 44px; letter-spacing: 0.25em; color: var(--gold); text-shadow: 0 3px 0 var(--w9); }
.me-slot { border: 2px solid var(--c); }
.online-seat .slot-avatar { width: 52px; height: 52px; }
.online-seat.open .slot-avatar, .online-seat.bot .slot-avatar { opacity: 0.75; }
.seat-empty { display: grid; place-items: center; width: 100%; height: 100%; font-family: var(--font-display); font-size: 24px; color: var(--w5); }
.seat-name { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-name small { font-size: 10px; text-transform: uppercase; color: var(--gold); margin-left: 4px; }
.online-seat.open .seat-name { color: var(--parch-2); font-weight: 600; }
.online-lobby .options { grid-template-columns: repeat(3, 1fr); }
#online-controls .btn-play { width: 100%; }
#online-controls .sheet-note { text-align: center; margin: 0 0 12px; }
.type-pill .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 6px; vertical-align: middle; }
.type-pill .dot.on { background: var(--green); }
.waiting-note { text-align: center; font-weight: 800; }
.waiting-note span { animation: dotBlink 1.2s infinite; }
.waiting-note span:nth-child(2) { animation-delay: 0.2s; }
.waiting-note span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBlink { 50% { opacity: 0.2; } }
.connecting { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 6px solid var(--w7); border-top-color: var(--gold); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.net-strip {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  text-align: center; font-weight: 900; font-size: 13px; padding: 5px 8px; border-radius: 6px;
  background: var(--w8); color: var(--parch); border: 2px solid var(--gold);
}
.net-strip[hidden] { display: none; }
.net-strip.warn { border-color: var(--red); animation: sdBlink 1.2s ease-in-out infinite; }
.net-strip .btn { font-size: 14px; padding: 4px 12px; }
.turn-timer { position: relative; height: 18px; margin-top: 8px; border-radius: 9px; background: var(--w9); overflow: hidden; }
.turn-timer i { position: absolute; inset: 0; transform-origin: left; transform: scaleX(var(--left, 1)); background: var(--gold); transition: transform 0.25s linear; }
.turn-timer.low i { background: var(--red); }
.turn-timer span { position: relative; display: block; text-align: center; font-size: 11px; font-weight: 900; line-height: 18px; color: var(--ink); }
.fighter.offline .avatar { filter: grayscale(0.8) brightness(0.8); }

/* ---------- Arena ---------- */

.screen.game { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; }

.hud { display: flex; align-items: center; justify-content: space-between; }
.strips { display: grid; gap: 6px; }
.strips:empty { display: none; }

/* Layar lebar: kotak aksi tetap di tengah bawah, lebarnya dibatasi. */
@media (min-width: 900px) {
  .screen.game { max-width: 980px; height: 100dvh; }
  .arena { min-height: 0; }
}
.round-badge { font-family: var(--font-display); font-size: 18px; padding: 5px 18px; border-radius: 10px; }
.round-badge b { color: var(--gold); font-weight: 400; font-size: 22px; margin-left: 4px; }

.event-strip {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  border: 3px solid var(--w9);
  border-radius: 6px;
  padding: 6px 12px;
  background: var(--parch);
  color: var(--ink);
  text-align: left;
  box-shadow: inset 0 0 0 2px var(--parch-2), 0 3px 0 var(--w9);
}
.event-strip[hidden], .sd-strip[hidden] { display: none; }
.ev-name { font-family: var(--font-display); font-size: 18px; flex: 1; }
.ev-cap { font-size: 12px; font-weight: 900; color: var(--w5); }
.ev-info { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: var(--parch); display: grid; place-items: center; font-weight: 900; font-size: 13px; }

.sd-strip { text-align: center; font-weight: 900; font-size: 13px; padding: 5px; border-radius: 6px; background: var(--w8); color: var(--parch-2); border: 2px solid var(--w9); }
.sd-strip.active { background: var(--red); color: var(--parch); animation: sdBlink 1.2s ease-in-out infinite; }
@keyframes sdBlink { 50% { filter: brightness(1.25); } }

.arena { position: relative; flex: 1; min-height: 380px; }
.arena.n5, .arena.n6 { min-height: 450px; }
/* Kotak dalam: titik poligon = pusat cincin avatar. Margin atas memberi ruang penanda giliran + setengah cincin,
   margin bawah untuk setengah cincin + nama, HP, Charge, dan status. */
.poly { position: absolute; inset: 76px 58px 122px; }
.floor { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.floor polygon {
  fill: rgba(31, 19, 11, 0.55);
  stroke: var(--w4);
  stroke-width: 3;
  stroke-dasharray: 2 10;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.emblem {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 88px; height: 88px; border-radius: 50%;
  display: grid; place-items: center; align-content: center; gap: 2px;
  background: var(--w8);
  border: 3px solid var(--w9);
  box-shadow: inset 0 0 0 2px var(--w5);
  color: var(--parch-2);
  text-align: center;
}
.emblem .icon { width: 36px; height: 36px; color: var(--gold); }
.emblem span { font-size: 10px; font-weight: 900; text-transform: uppercase; line-height: 1.1; max-width: 80px; }
.emblem b { font-family: var(--font-display); font-weight: 400; font-size: 32px; color: var(--gold); line-height: 1; }

.fighter {
  --ringc: var(--gold);
  --fw: clamp(96px, 27vw, 128px);
  position: absolute;
  /* Properti translate terpisah agar animasi transform tidak menggeser posisi; pusat cincin (78% lebar) di titik. */
  translate: -50% calc(var(--fw) * -0.39 - 3px);
  width: var(--fw);
  display: flex; flex-direction: column; align-items: center;
  gap: 3px;
  transition: opacity 0.4s, filter 0.4s;
}
.arena.n5 .fighter { --fw: clamp(86px, 24vw, 118px); }
.arena.n6 .fighter { --fw: clamp(80px, 22vw, 110px); }
.arena.n6 .emblem { width: 70px; height: 70px; }
.arena.n6 .emblem .icon { width: 28px; height: 28px; }
.arena.n6 .emblem span { font-size: 9px; max-width: 60px; }
.fighter.warn { --ringc: #d9822b; }
.fighter.over { --ringc: var(--red); }
.fighter.limitless { --ringc: var(--parch); }

.turn-flag {
  position: absolute; top: -26px; left: 50%; margin-left: -34px; width: 68px; text-align: center;
  font-family: var(--font-display); font-size: 12px; letter-spacing: 0.05em;
  padding: 1px 10px; border-radius: 4px;
  background: var(--gold); color: var(--ink);
  border: 2px solid var(--w9);
  opacity: 0; transform: translateY(4px);
  transition: opacity 0.25s, transform 0.25s;
}
.fighter.current .turn-flag { opacity: 1; transform: none; }

.ring {
  position: relative;
  width: 78%;
  aspect-ratio: 1;
  border-radius: 50%;
  padding: 5px;
  background: conic-gradient(var(--ringc) calc(var(--charge) * 1turn), var(--w8) 0);
  border: 3px solid var(--w9);
  transition: --charge 0.7s ease-out, box-shadow 0.3s;
}
.fighter.current .ring { box-shadow: 0 0 0 3px var(--c), 0 0 22px rgba(227, 176, 75, 0.55); }
.avatar {
  width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, var(--parch) 55%, var(--parch-2));
  border: 3px solid var(--c);
  padding: 6%;
  overflow: hidden;
}
.fighter.over .ring { animation: overBuzz 0.25s linear infinite; }
@keyframes overBuzz { 50% { transform: translateX(1px); } }

.f-name {
  font-family: var(--font-display);
  font-size: 14px;
  max-width: 100%;
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--w8);
  border: 2px solid var(--w9);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.f-name small { font-family: var(--font-body); font-size: 9px; font-weight: 900; margin-left: 4px; color: var(--parch-2); }

.hp {
  position: relative;
  width: 92%;
  height: 13px;
  border-radius: 3px;
  background: var(--w9);
  overflow: hidden;
  border: 2px solid var(--w9);
}
.hp i { position: absolute; inset: 0 auto 0 0; width: var(--hp); background: var(--green); transition: width 0.6s ease-out; }
.fighter.hp-low .hp i { background: var(--red); }
.hp b { position: relative; display: block; text-align: center; font-size: 10px; font-weight: 900; line-height: 9px; color: var(--parch); text-shadow: 0 1px 1px var(--w9); }

.charge-line { font-size: 12px; color: var(--parch-2); display: flex; align-items: baseline; gap: 2px; text-shadow: 0 1px 2px var(--w9); }
.charge-line b { font-family: var(--font-display); font-weight: 400; font-size: 17px; color: var(--ringc); }
.bolt { color: var(--ringc); }
.status { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; min-height: 15px; }

.shield {
  position: absolute; inset: -9px;
  border-radius: 50%;
  border: 3px solid var(--blue);
  background: radial-gradient(circle, transparent 58%, rgba(109, 143, 168, 0.45));
  opacity: 0; transform: scale(0.6);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.fighter.shielded .shield { opacity: 1; transform: scale(1); }

.ko-stamp {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(-14deg) scale(2);
  font-family: var(--font-display); font-size: 26px;
  color: var(--red); border: 4px solid var(--red); border-radius: 6px;
  padding: 0 8px; background: rgba(31, 19, 11, 0.75);
  opacity: 0; transition: opacity 0.2s, transform 0.3s cubic-bezier(.2, 1.6, .4, 1);
}
.fighter.ko { opacity: 0.65; }
.fighter.ko .avatar { filter: grayscale(1) brightness(0.7); }
.fighter.ko .ko-stamp { opacity: 1; transform: translate(-50%, -50%) rotate(-14deg) scale(1); }

.aim {
  position: absolute; right: -14px; top: -6px;
  font-family: var(--font-display); font-size: 13px;
  padding: 0 6px; border-radius: 4px;
  background: var(--parch); color: var(--ink);
  border: 2px solid var(--w9);
  opacity: 0; transition: opacity 0.2s;
}
.fighter.targetable { cursor: pointer; }
.fighter.targetable .aim { opacity: 1; }
.fighter.targeted .ring::after {
  content: ''; position: absolute; inset: -11px; border-radius: 50%;
  border: 3px dashed var(--red);
  animation: spin 4s linear infinite;
}
.fighter.targeted .aim { background: var(--red); color: var(--parch); }
@keyframes spin { to { transform: rotate(1turn); } }

/* Tema arena per kartu */
.arena.rooted .ring::before {
  content: ''; position: absolute; inset: -6px; border-radius: 50%;
  border: 2px dashed var(--blue); opacity: 0.8;
}
.arena.windy .fighter { animation: sway 2.6s ease-in-out infinite; }
.arena.windy .fighter:nth-of-type(even) { animation-delay: -1.3s; }
@keyframes sway { 50% { margin-left: 4px; } }
.arena.quake .floor { animation: quake 3.2s ease-in-out infinite; }
@keyframes quake { 0%, 86%, 100% { transform: none; } 88% { transform: translate(-3px, 1px); } 91% { transform: translate(3px, -1px); } 94% { transform: translate(-2px, 0); } }
.arena.frenzied .ring { animation: frenzy 0.9s ease-in-out infinite; }
@keyframes frenzy { 50% { box-shadow: 0 0 16px rgba(196, 72, 59, 0.7); } }

/* Efek sementara (fx.pulse) */
.fx-pop { animation: pop var(--fx-ms) ease-out; }
@keyframes pop { 40% { transform: scale(1.08); } }
.fx-rest { animation: rest var(--fx-ms) ease-in-out; }
@keyframes rest { 50% { transform: translateY(5px) scale(0.94); filter: brightness(0.8); } }
.fx-charge .ring { animation: chargeGlow var(--fx-ms) ease-out; }
@keyframes chargeGlow { 30% { box-shadow: 0 0 22px var(--ringc); } }
.fx-gold .ring { animation: goldGlow var(--fx-ms) ease-out; }
@keyframes goldGlow { 30%, 70% { box-shadow: 0 0 28px var(--gold), 0 0 0 4px var(--gold); } }
.fx-zap { animation: zap var(--fx-ms) linear; }
@keyframes zap {
  0%, 100% { transform: none; filter: none; }
  10%, 30%, 50%, 70% { transform: translateX(-4px) rotate(-2deg); filter: brightness(1.7); }
  20%, 40%, 60%, 80% { transform: translateX(4px) rotate(2deg); filter: brightness(0.7); }
}
.fx-hurt { animation: hurt var(--fx-ms) ease-out; }
.fx-hurt-big { animation: hurt var(--fx-ms) ease-out, hurtBig var(--fx-ms) ease-out; }
@keyframes hurt {
  0%, 100% { transform: none; }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
}
@keyframes hurtBig { 10% { filter: brightness(1.8) sepia(1) hue-rotate(-30deg); } }
.fx-dodge { animation: dodge var(--fx-ms) ease-out; }
@keyframes dodge { 30% { transform: translateX(18px) rotate(6deg); opacity: 0.6; } }
.fx-heal .ring { animation: heal var(--fx-ms) ease-out; }
@keyframes heal { 30%, 70% { box-shadow: 0 0 26px var(--green), 0 0 0 4px var(--green); } }
.fx-revive { animation: revive var(--fx-ms) ease-out; }
@keyframes revive {
  0% { transform: translateY(14px) scale(0.8); filter: brightness(2.5); }
  60% { transform: translateY(-5px) scale(1.05); filter: brightness(1.4); }
  100% { transform: none; filter: none; }
}
.fx-ko { animation: koFall var(--fx-ms) ease-in; }
@keyframes koFall { 30% { transform: rotate(-8deg) scale(1.05); } }

/* ---------- Dock ---------- */

.dock {
  position: sticky; bottom: 0; z-index: 3;
  margin: 0 -16px -16px;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  border-bottom: 0;
  display: grid; gap: 10px;
}
/* Tinggi minimum di ponsel agar arena (dan nampan dadu di tengahnya) tidak bergeser saat isi dock berganti. */
.dock { min-height: 222px; align-content: start; }
@media (min-width: 900px) {
  .dock { width: min(560px, 100%); margin: 0 auto -16px; border-radius: 16px 16px 0 0; }
}
.dock-head { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.dock-head b { font-family: var(--font-display); font-weight: 400; font-size: 18px; }
.mini-av { display: inline-block; flex: none; width: 30px; height: 30px; padding: 2px; border-width: 2px; box-shadow: 0 0 0 2px var(--w9); vertical-align: middle; }
.emblem { transition: opacity 0.3s, transform 0.3s; }
.poly.has-dice .emblem { opacity: 0.12; transform: translate(-50%, -50%) scale(0.85); }

/* Nampan dadu di tengah arena (titik pusat poligon). */
.tray {
  position: absolute; z-index: 4;
  translate: -50% -50%;
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 6px;
  width: 104px;
  pointer-events: none;
}
.tray:not(:empty)::before {
  content: ''; position: absolute; inset: -14px; z-index: -1; border-radius: 50%;
  background: radial-gradient(circle, rgba(31, 19, 11, 0.9) 55%, rgba(31, 19, 11, 0));
}
.tray .die { width: 42px; height: 42px; border-radius: 9px; padding: 4px; }
.arena.n6 .tray, .arena.n5 .tray { width: 96px; }
.arena.n6 .tray .die { width: 38px; height: 38px; }
.dock-body { display: grid; gap: 10px; }
.dock-body:empty { display: none; }
.dock-msg { margin: 0; text-align: center; color: var(--parch-2); }
.dock-msg b { color: var(--parch); }
.dock-note { margin: -4px 0 0; text-align: center; font-size: 12px; color: var(--gold); }
.thinking span { animation: dots 1.2s infinite; }
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dots { 50% { opacity: 0.2; } }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.chip { font-size: 12px; font-weight: 900; padding: 3px 10px; border-radius: 4px; background: var(--w8); border: 2px solid var(--w9); color: var(--parch-2); }
.chip.gold { color: var(--gold); }
.chip.danger { color: #e58a7f; }

/* Dadu (tulang/perkamen) */
.die {
  position: relative;
  width: 48px; height: 48px;
  border-radius: 10px;
  background: var(--parch);
  border: 3px solid var(--w9);
  box-shadow: inset 0 -4px 0 var(--parch-2);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 5px;
}
.die i { border-radius: 50%; margin: 2px; }
.die i.on { background: var(--ink); }
.die b { grid-column: 1 / -1; grid-row: 1 / -1; display: grid; place-items: center; font-family: var(--font-display); font-weight: 400; color: var(--w4); font-size: 22px; }
.die.rolling { animation: tumble 0.28s linear infinite; }
@keyframes tumble { 0% { transform: rotate(0); } 50% { transform: rotate(180deg) translateY(-8px) scale(0.9); } 100% { transform: rotate(360deg); } }
.die.landed { animation: land 0.35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes land { 0% { transform: scale(1.3); } 100% { transform: scale(1); } }
.die.dup, .die.win { background: var(--gold); box-shadow: inset 0 -4px 0 #b9862f, 0 0 16px rgba(227, 176, 75, 0.7); }
.die.mini { width: 30px; height: 30px; border-radius: 7px; padding: 3px; border-width: 2px; box-shadow: inset 0 -3px 0 var(--parch-2); }
.die.mini i { margin: 1px; }
.die.mini.win { box-shadow: inset 0 -3px 0 #b9862f, 0 0 14px rgba(227, 176, 75, 0.8); }

/* Power meter */
.power { display: flex; align-items: center; gap: 10px; }
.power-label { font-size: 12px; font-weight: 900; text-transform: uppercase; color: var(--parch-2); }
.power output { font-family: var(--font-display); font-size: 28px; min-width: 2ch; text-align: right; color: var(--gold); }
.power input[type="range"] {
  flex: 1;
  -webkit-appearance: none; appearance: none;
  height: 14px; border-radius: 4px;
  background: linear-gradient(var(--gold), var(--gold)) 0 / var(--fill) 100% no-repeat, var(--w9);
  border: 2px solid var(--w9);
}
.power input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--parch); border: 3px solid var(--w9);
}
.power input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 6px; background: var(--parch); border: 3px solid var(--w9); }

/* ---------- Overlay ---------- */

#overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(20, 12, 6, 0.7);
  animation: fadeIn 0.2s ease-out;
}
#overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }

.sheet {
  width: min(420px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 20px;
  border-radius: 14px;
  display: grid; gap: 12px;
  text-align: center;
  animation: sheetIn 0.3s cubic-bezier(.2, 1.3, .4, 1);
}
@keyframes sheetIn { from { transform: translateY(24px) scale(0.96); opacity: 0; } }
.sheet h2 { font-size: 26px; text-shadow: 0 3px 0 var(--w9); }
.kicker { margin: 0; font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold); }
.sheet-text { margin: 0; color: var(--parch-2); }
.sheet-text b { color: var(--parch); }
.sheet-note { margin: 0; font-size: 12px; color: var(--parch-2); }

.sheet.reveal { background: none; border: 0; box-shadow: none; cursor: pointer; }
.event-card {
  position: relative;
  border-radius: 10px;
  padding: 20px 18px 18px;
  background: var(--parch);
  color: var(--ink);
  border: 4px solid var(--w9);
  box-shadow: inset 0 0 0 3px var(--gold), 0 6px 0 var(--w9);
  display: grid; gap: 8px; justify-items: center;
}
.event-card h2 { font-size: 30px; color: var(--ink); text-shadow: none; }
.event-card p { margin: 0; color: var(--w6); font-weight: 800; }
.ec-top { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.1em; color: var(--w4); }
.ec-cap { font-family: var(--font-display); font-size: 15px; padding: 3px 12px; border-radius: 4px; background: var(--ink); color: var(--parch); }
.ec-icon {
  width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--w7); color: var(--gold);
  border: 3px solid var(--w9);
  box-shadow: inset 0 0 0 2px var(--w5);
}
.ec-icon .icon { width: 44px; height: 44px; }
.event-card.flip { animation: cardFlip 0.7s cubic-bezier(.2, 1.2, .4, 1); }
.event-card.flip .ec-icon { animation: iconIn 0.9s 0.3s both cubic-bezier(.2, 1.6, .4, 1); }
@keyframes cardFlip { 0% { transform: perspective(800px) rotateY(90deg) scale(0.6); } 100% { transform: perspective(800px) rotateY(0) scale(1); } }
@keyframes iconIn { from { transform: scale(0) rotate(-90deg); } }
/* Ikon kartu sedikit bergerak sesuai tema */
.theme-wind .icon, .theme-boring12 .icon, .theme-boring16 .icon, .theme-boring20 .icon { animation: sway 1.6s ease-in-out infinite; }
.theme-rain .icon, .theme-calm .icon, .theme-return .icon { animation: bob2 2s ease-in-out infinite; }
.theme-lethal .icon, .theme-frenzy .icon { animation: flicker 0.5s steps(2) infinite; }
.theme-norun .icon, .theme-noevade16 .icon, .theme-noevade20 .icon { animation: shake 1.2s ease-in-out infinite; }
.theme-focusday .icon { animation: breathe 1.6s ease-in-out infinite; }
@keyframes bob2 { 50% { transform: translateY(-4px); } }
@keyframes flicker { 50% { opacity: 0.6; transform: scale(1.06); } }
@keyframes shake { 0%, 80%, 100% { transform: none; } 85% { transform: translateX(-3px); } 90% { transform: translateX(3px); } 95% { transform: translateX(-2px); } }
@keyframes breathe { 50% { transform: scale(1.12); } }
.event-card.small { padding: 12px; width: 190px; margin: 0 auto; }
.event-card.small h2 { font-size: 22px; }
.card-reveal { display: grid; gap: 12px; }

.duel { display: flex; align-items: center; justify-content: center; gap: 10px; }
.duel-av { display: inline-block; width: 70px; height: 70px; }
.duel-arrow { display: grid; font-size: 12px; font-weight: 900; color: var(--parch-2); text-transform: uppercase; }
.duel-arrow b { font-family: var(--font-display); font-weight: 400; font-size: 34px; color: #e58a7f; }

.winner { display: grid; justify-items: center; gap: 8px; }
.crown { font-size: 46px; color: var(--gold); line-height: 1; text-shadow: 0 3px 0 var(--w9); animation: bob2 2s ease-in-out infinite; }
.winner-av { width: 128px; height: 128px; padding: 8px; border-width: 5px; box-shadow: 0 0 0 4px var(--w9), 0 0 36px rgba(227, 176, 75, 0.45); }
.winner h2 { font-size: 32px; color: var(--gold); }
.fallen { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 12px; font-size: 13px; color: var(--parch-2); counter-reset: f; }
.fallen li { display: flex; align-items: center; gap: 4px; }
.fallen li::before { counter-increment: f; content: counter(f) '.'; font-weight: 900; }

.menu-list { display: grid; gap: 8px; }
.debug { display: grid; gap: 4px; font-size: 12px; color: var(--parch-2); text-align: left; }
.debug select { font: inherit; padding: 8px; border-radius: 8px; background: var(--w9); color: var(--parch); border: 2px solid var(--w5); }

.log { list-style: none; margin: 0; padding: 0; text-align: left; font-size: 13px; max-height: 55dvh; overflow-y: auto; }
.log li { padding: 6px 2px; border-bottom: 1px dashed var(--w5); color: var(--parch-2); }
.log li.round, .log li.event, .log li.momentum, .log li.penalty { color: var(--gold); font-weight: 800; }
.log li.overcharge, .log li.sudden, .log li.gameover, .log li.damage { color: #e58a7f; }
.log li.revive, .log li.meditate { color: #b9cf8a; }

.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pick { border: 2px solid transparent; border-radius: 10px; background: var(--w8); padding: 8px 4px; display: grid; justify-items: center; gap: 2px; }
.pick.chosen { border-color: var(--gold); }
.pick-av { width: 58px; height: 58px; }
.pick b { font-size: 11px; line-height: 1.1; }
.pick small { font-size: 9px; color: var(--parch-2); line-height: 1.1; }

.dots { display: flex; justify-content: center; gap: 6px; }
.dots i { width: 8px; height: 8px; border-radius: 2px; background: var(--w5); transition: width 0.25s, background 0.25s; }
.dots i.on { background: var(--gold); width: 22px; }
.tut-stage { overflow: hidden; }
.tut-body { display: grid; gap: 10px; }
.tut-art { min-height: 110px; display: grid; place-items: center; }
.art-dice { display: flex; gap: 12px; }
.art-dice .die { width: 64px; height: 64px; }
.art-over { font-family: var(--font-display); font-size: 56px; color: #e58a7f; animation: shake 1.2s linear infinite; }
.art-over small { font-size: 24px; color: var(--parch-2); }
.art-duel { display: flex; align-items: center; gap: 12px; }
.art-orb { width: 20px; height: 20px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 18px var(--gold); animation: orbFly 1.4s ease-in-out infinite; }
@keyframes orbFly { 0% { transform: translateX(-30px); } 100% { transform: translateX(30px); opacity: 0.2; } }
.art-ring { display: flex; gap: 8px; }
.art-ring .duel-av { width: 54px; height: 54px; animation: bob2 2.4s ease-in-out infinite; }
.art-ring .duel-av:nth-child(2) { animation-delay: -0.6s; }
.art-ring .duel-av:nth-child(3) { animation-delay: -1.2s; }
.art-ring .duel-av:nth-child(4) { animation-delay: -1.8s; }

/* ---------- Lapisan efek ---------- */

#fx { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.float-text {
  position: fixed;
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--parch);
  text-shadow: 0 3px 0 var(--w9), 0 0 3px var(--w9);
  white-space: nowrap;
}
.float-text.dmg { color: #e8705f; font-size: 30px; }
.float-text.dmg.big { font-size: 44px; color: #f05a45; }
.float-text.gain, .float-text.gold { color: var(--gold); }
.float-text.small { font-size: 18px; }
.float-text.heal { color: #b9cf8a; }
.float-text.dim { color: var(--parch-2); font-size: 22px; }
.float-text.dim.small { font-size: 16px; }
.float-text.shield-text { color: #a9c3d6; font-size: 22px; }
.float-text.warn-text { color: var(--gold); font-size: 18px; }

.mini-roll { position: fixed; transform: translate(-50%, -50%); display: flex; align-items: center; gap: 4px; z-index: 31; }
.mini-roll em { font-style: normal; font-family: var(--font-display); font-size: 14px; padding: 0 5px; border-radius: 4px; background: var(--w9); color: #e58a7f; }

.orb { position: fixed; width: 28px; height: 28px; border-radius: 50%; background: radial-gradient(circle, var(--parch) 0 22%, var(--c) 50%, transparent 72%); box-shadow: 0 0 22px var(--c); }
.burst { position: fixed; width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(circle, transparent 30%, var(--c) 45%, transparent 65%); }
.screen-flash { position: fixed; inset: 0; left: 0 !important; top: 0 !important; background: radial-gradient(ellipse at center, rgba(196, 72, 59, 0.35), rgba(196, 72, 59, 0.85)); }
.trail { position: fixed; width: 18px; height: 18px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 16px 4px rgba(227, 176, 75, 0.6); }
.banner {
  position: fixed;
  font-family: var(--font-display);
  font-size: clamp(40px, 13vw, 72px);
  color: var(--parch);
  white-space: nowrap;
  text-shadow: 0 5px 0 var(--w9), 0 0 3px var(--w9);
}
.banner.gold-banner, .banner.round-banner { color: var(--gold); }
.banner.red-banner { color: #e8705f; }
.banner.turn-banner { font-size: clamp(30px, 9vw, 52px); }
.confetti { position: fixed; width: 9px; height: 14px; border-radius: 2px; }

/* ---------- Tutorial interaktif ---------- */

#coach {
  position: fixed; z-index: 35;
  left: 50%; top: 66px;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 24px));
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--parch);
  color: var(--ink);
  border: 4px solid var(--w9);
  box-shadow: inset 0 0 0 2px var(--gold), 0 8px 24px rgba(0, 0, 0, 0.5);
  display: grid; gap: 6px;
}
#coach[hidden] { display: none; }
/* Ketukan di luar tombol bubble diteruskan ke arena di bawahnya (mis. petarung yang tertutup). */
#coach { pointer-events: none; }
#coach button { pointer-events: auto; }
#coach.bottom { top: auto; bottom: 248px; }
#coach h3 { font-size: 20px; }
#coach p { margin: 0; font-weight: 800; color: var(--w6); line-height: 1.35; }
#coach .kicker { color: var(--w4); }
#coach .btn { padding: 8px 14px; font-size: 17px; }
.coach-head { display: flex; justify-content: space-between; align-items: center; }
.coach-quit { border: 0; background: none; color: var(--w4); font-weight: 900; font-size: 12px; text-decoration: underline; }
.coach-hint { font-size: 12px; color: var(--w4) !important; }
.coach-hl { outline: 3px solid var(--gold); outline-offset: 4px; animation: coachPulse 1.1s ease-in-out infinite; border-radius: 10px; }
.fighter.coach-hl, .ring.coach-hl { border-radius: 50%; }
@keyframes coachPulse { 50% { outline-color: rgba(227, 176, 75, 0.25); outline-offset: 8px; } }

#toasts { position: fixed; left: 16px; right: 16px; bottom: 20px; z-index: 40; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--parch); color: var(--ink); padding: 10px 16px; border-radius: 8px; border: 3px solid var(--w9); font-weight: 800; animation: sheetIn 0.25s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .orbit-av, .pulse-btn, .crown, .art-ring .duel-av, .sd-strip.active, .arena .fighter, .arena .floor, .arena .ring { animation: none !important; }
}
