/* Blood & Destiny — fantasi kelam: tinta, darah kering, kertas tulang; emas hanya untuk takdir. */

@font-face { font-family: "EB Garamond"; font-style: normal; font-weight: 400 800; font-display: swap;
  src: url("fonts/EBGaramond-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "EB Garamond"; font-style: italic; font-weight: 400 800; font-display: swap;
  src: url("fonts/EBGaramond-Italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IM Fell English SC"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("fonts/IMFellEnglishSC-Regular-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Pirata One"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("fonts/PirataOne-Regular-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  /* peran */
  --canvas: #120c0c;      /* oklch(.13 .012 25) */
  --surface: #1f1716;
  --surface-2: #2b201e;
  --blood: #8a1f1c;       /* aksi primer */
  --blood-hi: #b8322c;
  --blood-lo: #4a0f0e;
  --fate: #d6b468;        /* emas = takdir (dadu, seleksi) saja */
  --fate-hi: #f1d68e;
  /* nama lama, nilai baru */
  --bg0: #0e0909;
  --bg1: #1a1111;
  --plum: #2a1414;
  --panel-a: rgba(36, 25, 23, .94);
  --panel-b: rgba(20, 14, 13, .96);
  --line: #5c3d2e;
  --gold: var(--fate);
  --gold-hi: var(--fate-hi);
  --ink: #ece3d3;
  --muted: #c2b29b;       /* ≥ 4.5:1 di atas panel */
  --danger: #e0715f;
  --ok: #7fcf6a;
  --radius: 12px;
  --font: "EB Garamond", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-display: "IM Fell English SC", "Palatino Linotype", Georgia, serif;
  --font-logo: "Pirata One", "IM Fell English SC", Georgia, serif;
  --mono: Consolas, "Courier New", monospace;
  --topbar: 52px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  overflow-x: hidden;
  background:
    radial-gradient(900px 480px at 50% -10%, rgba(138, 31, 28, .26), transparent 65%),
    radial-gradient(700px 420px at 100% 100%, rgba(74, 15, 14, .35), transparent 70%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  background-attachment: fixed;
  font-size-adjust: .45; /* EB Garamond ber-x-height kecil: samakan ukuran tampak dengan font lama agar tata letak tarung/lobby tidak menyusut */
}
::selection { background: rgba(184, 50, 44, .55); color: #fff6ee; }
html { scrollbar-color: #5c3d2e #120c0c; }
input { caret-color: var(--blood-hi); }

h1, h2, h3 { font-family: var(--font-display); font-size-adjust: none; font-weight: 400; letter-spacing: .02em; margin: 0; }
p { margin: 0; }
button, input { font: inherit; color: inherit; }

/* ---------- Panel bertekstur ---------- */

.panel {
  position: relative;
  background:
    linear-gradient(180deg, var(--panel-a), var(--panel-b)),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .018) 0 2px, transparent 2px 7px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    inset 0 0 0 1px rgba(214, 178, 94, .12),
    inset 0 0 40px rgba(0, 0, 0, .35),
    0 12px 32px rgba(0, 0, 0, .5);
}
/* sudut hiasan emas (garis L) */
.panel::before, .panel::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
  border-color: var(--gold);
  border-style: solid;
  opacity: .75;
}
.panel::before { top: 5px; left: 5px; border-width: 2px 0 0 2px; border-top-left-radius: 4px; }
.panel::after { bottom: 5px; right: 5px; border-width: 0 2px 2px 0; border-bottom-right-radius: 4px; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 16px;
  border: 1px solid var(--gold);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(60, 46, 26, .95), rgba(28, 22, 14, .95));
  color: var(--gold-hi);
  cursor: pointer;
  font-variant: small-caps;
  letter-spacing: .05em;
  transition: filter .15s, transform .15s, box-shadow .15s, background .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.2); box-shadow: 0 0 14px rgba(214, 178, 94, .25); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--blood-hi), var(--blood));
  color: #fbeee0;
  font-weight: 700;
  border-color: #c9473f;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 220, 200, .18);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); box-shadow: 0 4px 18px rgba(184, 50, 44, .45), inset 0 1px 0 rgba(255, 220, 200, .25); }
.btn-ghost { background: transparent; border-color: rgba(214, 178, 94, .45); }
.btn:disabled, button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, .hero-card:focus-visible {
  outline: 2px solid var(--gold-hi);
  outline-offset: 2px;
}
body.is-busy, body.is-busy button, body.is-busy .hero-card { cursor: progress; }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  height: var(--topbar);
  background: linear-gradient(180deg, rgba(18, 11, 11, .96), rgba(18, 11, 11, .84));
  border-bottom: 1px solid rgba(214, 180, 104, .3);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .6), 0 6px 18px rgba(0, 0, 0, .35);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-logo);
  font-variant: normal;
  font-weight: 400;
  letter-spacing: .04em;
  font-size: 1.25rem;
  color: var(--ink);
  white-space: nowrap;
  flex: 0 0 auto;
}
.brand-mark { width: 30px; height: 30px; display: block; }
.brand-mark svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 0 6px rgba(184, 50, 44, .45)); }
.roombar {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.room-label { color: var(--muted); letter-spacing: .06em; }
.room-code {
  font-family: var(--mono);
  font-size: 1.35rem;
  letter-spacing: .18em;
  color: var(--gold-hi);
  text-shadow: 0 0 12px rgba(214, 178, 94, .45);
}
.roombar .btn { min-height: 34px; padding: 4px 12px; }
.btn-icon {
  margin-left: auto;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(214, 178, 94, .45);
  border-radius: 8px;
  background: transparent;
  color: var(--gold-hi);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-icon:hover { background: rgba(214, 178, 94, .1); border-color: var(--gold); }
.btn-icon[aria-expanded="true"] { background: rgba(214, 178, 94, .18); border-color: var(--gold); }
.btn-icon.is-muted { color: var(--muted); }
.btn-icon svg { display: block; }
.roombar:not([hidden]) + .btn-icon { margin-left: 0; }
.lang-switch {
  margin-left: auto;
  display: flex;
  border: 1px solid rgba(214, 178, 94, .45);
  border-radius: 8px;
  overflow: hidden;
  flex: 0 0 auto;
}
/* Tombol suara disembunyikan bila modul audio gagal: lang-switch kembali didorong ke kanan. */
.roombar:not([hidden]) + .lang-switch, .btn-icon:not([hidden]) + .lang-switch { margin-left: 0; }

/* ---------- Panel suara (popover kanan atas, di atas layar tarung) ---------- */

.sound-panel {
  position: fixed;
  top: calc(var(--topbar) + 6px);
  right: 12px;
  z-index: 40;
  width: min(280px, calc(100vw - 24px));
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sound-panel h3 { color: var(--gold-hi); font-size: 1.05rem; }
.snd-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: .9rem;
}
.snd-row input[type="range"] { width: 100%; min-height: 28px; accent-color: var(--gold); cursor: pointer; }
.snd-row input[type="range"]:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.snd-mute { align-self: stretch; }
.snd-mute[aria-pressed="true"] { border-color: var(--danger); color: #ffd2c8; }

/* ---------- Panel kendali pahlawan (popover kanan atas) ---------- */

.party-btn { position: relative; }
.party-alert {
  display: none;
  position: absolute;
  top: -3px;
  right: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold-hi);
  box-shadow: 0 0 0 2px var(--danger), 0 0 8px var(--danger);
  animation: party-pulse 1.8s ease-in-out infinite;
}
.party-btn.has-alert .party-alert { display: block; }
@keyframes party-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.party-panel {
  position: fixed;
  top: calc(var(--topbar) + 6px);
  right: 12px;
  z-index: 40;
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100dvh - var(--topbar) - 16px);
  overflow: auto;
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pp-title { color: var(--gold-hi); font-size: 1.05rem; }
.pp-close {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(214, 178, 94, .45);
  border-radius: 8px;
  background: transparent;
  color: var(--gold-hi);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.pp-close:hover { background: rgba(214, 178, 94, .1); border-color: var(--gold); }
.pp-note { color: var(--muted); font-size: .86rem; }
.pp-note.is-spectator { color: var(--gold-hi); font-weight: 700; }
.pp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pp-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 8px;
  padding: 6px 8px;
  border-left: 3px solid var(--pc, var(--line));
  background: rgba(0, 0, 0, .22);
  border-radius: 6px;
}
.pp-pic { width: 48px; height: 48px; overflow: hidden; border-radius: 6px; }
.pp-pic > * { width: 100%; height: 100%; display: block; }
.pp-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.pp-name { color: var(--ink); }
.pp-class { margin-left: 6px; color: var(--muted); font-size: .8rem; font-variant: small-caps; }
.pp-owner { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .84rem; }
.pp-owner i { width: 8px; height: 8px; border-radius: 50%; background: var(--pc, var(--muted)); flex: 0 0 auto; }
.pp-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.pp-badge { padding: 0 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; border: 1px solid currentColor; }
.pp-badge.is-off { color: var(--muted); }
.pp-badge.is-temp { color: #8ec9ee; }
.pp-badge.is-pend { color: var(--gold-hi); }
.pp-give { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 2px; }
.pp-select, .hero-give {
  min-height: 32px;
  min-width: 0;
  padding: 2px 6px;
  border: 1px solid rgba(214, 178, 94, .45);
  border-radius: 6px;
  background: rgba(12, 10, 20, .75);
  color: var(--ink);
  font: inherit;
  font-size: .86rem;
}
.pp-select { flex: 1 1 110px; }
.pp-select:focus-visible, .hero-give:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.pp-go, .pp-cancel { min-height: 32px; padding: 2px 10px; font-size: .84rem; }
.hero-give { grid-column: 1 / -1; width: 100%; cursor: pointer; }
.lang-switch button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  cursor: pointer;
  font-size: .85rem;
  letter-spacing: .06em;
}
.lang-switch button[aria-pressed="true"] { background: linear-gradient(#f1d68e, #b8892f); color: #1a1208; font-weight: 700; }

/* ---------- Banner koneksi & toast ---------- */

.conn-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 6px 16px;
  background: #5a1f1a;
  color: #ffe9e2;
  border-bottom: 1px solid var(--danger);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
  text-align: center;
  flex-wrap: wrap;
}
.conn-banner .btn { min-height: 30px; padding: 2px 12px; color: #ffe9e2; border-color: rgba(255, 233, 226, .6); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100vw - 32px);
  width: max-content;
  padding: 10px 18px;
  background: linear-gradient(180deg, rgba(46, 37, 25, .98), rgba(26, 21, 15, .98));
  border: 1px solid var(--gold);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
  color: var(--ink);
  overflow-wrap: anywhere;
  text-align: center;
  animation: toast-in .25s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

.clip-helper { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

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

.screen { animation: screen-in .35s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }

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

.screen-lobby {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 16px 0;
  max-width: 1400px;
  margin: 0 auto;
}
.seats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.seat {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  min-width: 0;
  padding: 5px 12px;
  border-left: 4px solid var(--pc);
  border-radius: 10px;
}
.seat.panel::before, .seat.panel::after { display: none; }
.seat.is-me { box-shadow: inset 0 0 0 1px rgba(214, 178, 94, .12), inset 0 0 40px rgba(0, 0, 0, .35), 0 0 0 1px var(--pc), 0 0 18px color-mix(in srgb, var(--pc) 35%, transparent); }
.seat-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.seat-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.seat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b6658;
  flex: 0 0 auto;
}
.seat-dot.is-online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.seat-name {
  font-weight: 700;
  color: var(--pc);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.seat-crown { color: var(--gold-hi); text-shadow: 0 0 8px rgba(241, 214, 142, .6); flex: 0 0 auto; }
.seat-you { color: var(--muted); font-size: .8rem; font-style: italic; flex: 0 0 auto; }
.seat-quota { color: var(--muted); font-size: .8rem; }
.seat-empty {
  justify-content: center;
  border: 1px dashed rgba(214, 178, 94, .55);
  background: rgba(30, 16, 14, .35);
  color: var(--muted);
  cursor: pointer;
  font-variant: small-caps;
  letter-spacing: .06em;
  transition: color .15s, border-color .15s, background .15s;
}
.seat-empty:hover:not(:disabled) { color: var(--gold-hi); border-color: var(--gold); background: rgba(214, 178, 94, .08); }

.lobby-head { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.lobby-head h2 { color: var(--gold-hi); font-size: 1.3rem; flex: 0 0 auto; }
.lobby-head .hint { color: var(--muted); font-size: .85rem; font-style: italic; flex: 1; min-width: 0; }
.party-count {
  margin-left: auto;
  flex: 0 0 auto;
  padding: 2px 12px;
  border: 1px solid rgba(214, 178, 94, .5);
  border-radius: 999px;
  color: var(--gold-hi);
  font-variant: small-caps;
  letter-spacing: .06em;
  background: rgba(214, 178, 94, .08);
}

.hero-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.loading { grid-column: 1 / -1; text-align: center; color: var(--muted); font-style: italic; padding: 40px 0; }

/* ---------- Kartu pahlawan ---------- */

.hero-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  grid-template-areas:
    "por head gen"
    "role role role"
    "story story story"
    "stats stats stats"
    "vit vit vit"
    "own own own";
  align-content: start;
  gap: 4px 10px;
  padding: 10px;
  min-width: 0;
  cursor: pointer;
  border-top: 3px solid var(--hero);
  transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
}
.hero-card::before { top: 7px; }
.hero-card.is-free:hover { transform: translateY(-3px); box-shadow: inset 0 0 0 1px rgba(214, 178, 94, .2), inset 0 0 40px rgba(0, 0, 0, .3), 0 16px 34px rgba(0, 0, 0, .55), 0 0 18px color-mix(in srgb, var(--hero) 35%, transparent); }
.hero-card.is-mine {
  outline: 2px solid var(--owner);
  outline-offset: -1px;
  box-shadow: inset 0 0 0 1px rgba(214, 178, 94, .12), inset 0 0 40px rgba(0, 0, 0, .35), 0 0 22px color-mix(in srgb, var(--owner) 55%, transparent);
  animation: mine-pulse 2.4s ease-in-out infinite;
}
@keyframes mine-pulse {
  50% { box-shadow: inset 0 0 0 1px rgba(214, 178, 94, .12), inset 0 0 40px rgba(0, 0, 0, .35), 0 0 34px color-mix(in srgb, var(--owner) 80%, transparent); }
}
/* Kartu milik orang lain: dibedakan lewat warna pudar + potret redup, teks tetap terbaca. */
.hero-card.is-taken { filter: saturate(.5) brightness(.94); cursor: default; }
.hero-card.is-taken .hero-portrait { opacity: .72; }
/* Cincin fokus keyboard harus menang atas outline warna pemilik di .is-mine. */
.hero-card.hero-card:focus-visible { outline: 3px solid var(--gold-hi); outline-offset: 2px; }

.hero-portrait { grid-area: por; width: 72px; align-self: start; }
.hero-card.is-free .hero-portrait, .hero-card.is-mine .hero-portrait { transition: transform .25s ease; }
.hero-card.is-free:hover .hero-portrait { transform: scale(1.05) rotate(-2deg); }
.portrait { width: 100%; height: auto; display: block; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .55)); }
.hero-head { grid-area: head; min-width: 0; align-self: center; }
.hero-name {
  font-size: 1.15rem;
  color: var(--gold-hi);
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.hero-class { color: var(--ink); font-size: .9rem; font-variant: small-caps; letter-spacing: .04em; }
.hero-weapon { color: var(--muted); font-size: .78rem; font-style: italic; }
.hero-gender { grid-area: gen; display: flex; flex-direction: column; gap: 4px; align-self: start; }
.g-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(214, 178, 94, .5);
  background: rgba(12, 10, 20, .6);
  color: var(--muted);
  cursor: pointer;
  font-size: .95rem;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
  transition: background .15s, color .15s;
}
.g-btn:hover:not(:disabled) { color: var(--gold-hi); border-color: var(--gold); }
.g-btn[aria-pressed="true"] { background: linear-gradient(#f1d68e, #b8892f); color: #1a1208; border-color: #f6e3a8; font-weight: 700; }
.hero-card.is-taken .g-btn:disabled { opacity: .8; }

.hero-role, .hero-story {
  font-size: .82rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.hero-role { grid-area: role; color: #cfc3a6; }
.hero-story { grid-area: story; }
.hero-story strong { color: var(--gold); font-weight: 700; }
.hero-stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin: 2px 0 0;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 0;
  border: 1px solid rgba(214, 178, 94, .25);
  border-radius: 6px;
  background: rgba(0, 0, 0, .25);
  min-width: 0;
}
.stat dt { font-size: .66rem; color: var(--muted); letter-spacing: .06em; cursor: help; }
.stat dd { margin: 0; font-weight: 700; color: var(--gold-hi); font-size: .95rem; line-height: 1.1; }
.hero-vitals { grid-area: vit; display: flex; justify-content: space-between; gap: 6px; font-size: .75rem; color: var(--muted); }
.vital { display: inline-flex; gap: 4px; align-items: baseline; min-width: 0; white-space: nowrap; }
.vital b { color: var(--ink); }
.vital-hp b { color: #f08a7a; }
.hero-owner {
  grid-area: own;
  justify-self: start;
  max-width: 100%;
  padding: 1px 10px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--owner, transparent);
  color: #15100a;
}
.hero-card.is-free .hero-owner { background: transparent; color: var(--muted); font-weight: 400; font-style: italic; border: 1px solid rgba(169, 156, 128, .35); }

/* ---------- Footer lobby ---------- */

.lobby-foot {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  margin-top: auto;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  flex-wrap: wrap;
}
.diff { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.diff-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.diff-label { color: var(--gold); font-variant: small-caps; letter-spacing: .06em; }
.seg { display: inline-flex; border: 1px solid rgba(214, 178, 94, .5); border-radius: 8px; overflow: hidden; }
.seg-btn {
  border: 0;
  border-right: 1px solid rgba(214, 178, 94, .3);
  background: rgba(12, 10, 20, .5);
  color: var(--muted);
  padding: 5px 14px;
  cursor: pointer;
  font-variant: small-caps;
  letter-spacing: .05em;
  transition: background .15s, color .15s;
}
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover:not(:disabled) { color: var(--gold-hi); }
.seg-btn[aria-pressed="true"] { background: linear-gradient(#f1d68e, #b8892f); color: #1a1208; font-weight: 700; opacity: 1; }
.seg-btn:disabled { opacity: .8; }
.seg-btn:disabled[aria-pressed="true"] { opacity: .9; }
.diff-desc { color: var(--muted); font-size: .8rem; font-style: italic; }
.start-wrap { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.start-wrap small { color: var(--muted); font-style: italic; }
.btn-start { min-height: 44px; font-size: 1.1rem; padding: 6px 22px; }
.wait { color: var(--gold-hi); font-style: italic; margin-left: auto; animation: wait-glow 2.4s ease-in-out infinite; }
@keyframes wait-glow { 50% { opacity: .6; } }

/* ---------- Layar Arena Latihan ---------- */

.screen-play {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.arena-head h2 {
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  color: var(--gold-hi);
  text-shadow: 0 2px 6px rgba(0, 0, 0, .6);
}
.arena-head p { color: var(--muted); font-style: italic; margin-top: 4px; }
.arena-head .play-diff { color: var(--gold); font-style: normal; font-variant: small-caps; letter-spacing: .06em; }

.arena-last {
  width: 100%;
  padding: 12px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  text-align: left;
  border-left: 4px solid var(--gold);
}
.arena-last.is-win { border-left-color: var(--ok); }
.arena-last.is-lose { border-left-color: var(--danger); }
.arena-last.is-aborted { border-left-color: #8a7f68; }
.arena-last-title { color: var(--gold); font-size: .95rem; }
.arena-last-line { color: var(--ink); font-weight: 700; flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
.arena-last.is-win .arena-last-line { color: #b8eaa8; }
.arena-last.is-lose .arena-last-line { color: #f4b2a6; }
.arena-last-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.arena-chip {
  padding: 2px 10px;
  border: 1px solid rgba(214, 178, 94, .4);
  border-radius: 999px;
  background: rgba(0, 0, 0, .25);
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
}

.arena-grid { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.arena-wait { grid-column: 1 / -1; margin: 0; text-align: center; }
.arena-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  min-width: 0;
  text-align: left;
}
.arena-card-head { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.arena-card-name { color: var(--gold-hi); font-size: 1.2rem; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.arena-badge {
  flex: 0 0 auto;
  padding: 1px 10px;
  border-radius: 999px;
  background: rgba(214, 178, 94, .15);
  border: 1px solid rgba(214, 178, 94, .5);
  color: var(--gold-hi);
  font-size: .78rem;
  font-variant: small-caps;
  letter-spacing: .05em;
}
.arena-card-desc { color: var(--muted); font-size: .88rem; flex: 1; }
.arena-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.arena-tag {
  padding: 1px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(214, 178, 94, .25);
  color: var(--ink);
  font-size: .78rem;
}
.arena-obj-boss { border-color: rgba(224, 113, 95, .6); color: #f4b2a6; }
.arena-obj-survive { border-color: rgba(95, 179, 217, .6); color: #b6def0; }
.arena-obj-exit { border-color: rgba(127, 207, 106, .6); color: #c4ecb6; }
.arena-go { align-self: flex-end; min-height: 40px; }

/* Layar tarung memenuhi area di bawah topbar (tata letak di battle.css). */
body[data-screen="battle"] main { padding: 0; }
body[data-screen="battle"] .toast { bottom: 112px; }
.party-grid { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.party-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 12px 14px;
  min-width: 0;
  border-top: 3px solid var(--hero);
  animation: rise .6s ease-out both;
}
.party-card:nth-child(2) { animation-delay: .12s; }
.party-card:nth-child(3) { animation-delay: .24s; }
.party-card:nth-child(4) { animation-delay: .36s; }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.97); } }
.party-portrait { width: 120px; margin-bottom: 4px; }
.party-card h3 { color: var(--gold-hi); font-size: 1.3rem; overflow-wrap: anywhere; }
.party-owner { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; min-width: 0; max-width: 100%; }
.party-owner span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.owner-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--owner); box-shadow: 0 0 8px var(--owner); flex: 0 0 auto; }

/* ---------- Tablet ---------- */

@media (max-width: 1100px) {
  .hero-card { grid-template-columns: 56px minmax(0, 1fr) auto; padding: 9px; }
  .hero-portrait { width: 56px; }
  .hero-story { display: none; }
  .hero-name { font-size: 1.02rem; }
  .hero-class { font-size: .82rem; }
  .hero-role { font-size: .78rem; }
  .roombar { gap: 6px; }
  .room-label { display: none; }
  .lobby-head .hint { font-size: .8rem; }
}

/* ---------- HP miring / layar pendek ---------- */

@media (max-height: 500px) {
  :root { --topbar: 40px; --foot: 40px; }
  .topbar { padding: 4px 10px; gap: 8px; }
  .brand-text { display: none; }
  .brand-mark { width: 26px; height: 26px; }
  .room-code { font-size: 1.1rem; }
  .roombar .btn { min-height: 30px; padding: 2px 10px; font-size: .85rem; }
  .lang-switch button { padding: 4px 8px; }

  .btn { min-height: 36px; }

  .screen-lobby { gap: 6px; padding: 6px 10px 0; }
  .seats { gap: 6px; }
  .seat { min-height: 32px; padding: 4px 8px; gap: 6px; }
  .seat-main { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0 6px; }
  .seat-name { font-size: .85rem; flex: 0 1 auto; }
  .seat-quota, .seat-you { font-size: .7rem; }
  .seat-quota { white-space: nowrap; }
  .seat-empty { font-size: .85rem; }
  .lobby-head h2 { font-size: 1rem; }
  .lobby-head .hint { display: none; }
  .party-count { font-size: .8rem; padding: 0 10px; }
  .hero-grid { gap: 6px; }
  .hero-card {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    grid-template-areas:
      "por head head"
      "stats stats stats"
      "vit vit vit"
      "own own gen";
    gap: 3px 6px;
    padding: 6px;
    border-top-width: 2px;
  }
  .hero-card::before, .hero-card::after { width: 9px; height: 9px; }
  .hero-portrait { width: 40px; }
  .hero-role, .hero-story, .hero-weapon { display: none; }
  .hero-name { font-size: .9rem; }
  .hero-class { font-size: .72rem; }
  .hero-stats, .hero-vitals { font-size: .7rem; }
  .stat dt { font-size: .6rem; }
  .stat dd { font-size: .8rem; }
  .hero-vitals { font-size: .66rem; }
  .vital-k { font-size: .62rem; }
  .hero-gender { flex-direction: row; align-self: center; justify-self: end; }
  .g-btn { width: 24px; height: 24px; font-size: .8rem; }
  .hero-owner { align-self: center; font-size: .66rem; padding: 1px 6px; }
  /* Footer jadi satu baris tipis menempel di bawah layar; area gulir diberi ruang setinggi footer
     supaya baris kartu terakhir tidak tertutup. */
  .screen-lobby { padding-bottom: calc(var(--foot) + 8px); }
  .lobby-foot {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--foot);
    min-height: 0;
    padding: 0 12px;
    gap: 10px;
    flex-wrap: nowrap;
    border-radius: 0;
    border-width: 1px 0 0;
  }
  .lobby-foot.panel::before, .lobby-foot.panel::after { display: none; }
  body[data-screen="lobby"] .toast { bottom: calc(var(--foot) + 8px); }
  .diff-top { flex-wrap: nowrap; gap: 8px; }
  .diff-label { font-size: .85rem; white-space: nowrap; }
  .diff-desc { display: none; }
  .seg-btn { padding: 2px 10px; font-size: .82rem; }
  .btn-start { min-height: 30px; font-size: .9rem; padding: 2px 14px; }
  .start-wrap { gap: 8px; min-width: 0; }
  .start-wrap small { font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .wait { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

  .screen-play { padding: 10px 12px 16px; gap: 10px; }
  .arena-head h2 { font-size: 1.5rem; }
  .arena-head p { font-size: .85rem; margin-top: 2px; }
  /* Party jadi baris ringkas (potret kecil di kiri) supaya pilihan skenario cepat terlihat. */
  .party-grid { gap: 6px; }
  .party-card {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-areas: "por name" "por own";
    align-items: center;
    gap: 0 8px;
    padding: 6px 8px;
    text-align: left;
    border-top-width: 2px;
  }
  .party-card::before, .party-card::after { display: none; }
  .party-portrait { grid-area: por; width: 40px; margin: 0; }
  .party-card h3 { grid-area: name; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .party-card .hero-class { display: none; }
  .party-owner { grid-area: own; font-size: .72rem; gap: 4px; }
  .owner-dot { width: 8px; height: 8px; }
  .arena-head p:not(.play-diff) { display: none; }
  .arena-grid { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .arena-card { padding: 10px 12px; gap: 6px; }
  .arena-card-name { font-size: 1.05rem; }
  .arena-last { padding: 8px 12px; }
  .btn-icon { width: 32px; height: 30px; }
  .sound-panel { top: calc(var(--topbar) + 4px); padding: 10px 14px 12px; gap: 6px; }
  .party-panel { top: calc(var(--topbar) + 4px); padding: 10px 12px 12px; gap: 6px; }
  .party-btn { padding: 2px 8px; }
  .hero-give { min-height: 26px; font-size: .74rem; }
  body[data-screen="battle"] .toast { bottom: 64px; }
}

/* ---------- Lebar sempit ---------- */

@media (max-width: 640px) {
  .seats, .hero-grid, .party-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .arena-grid { grid-template-columns: minmax(0, 1fr); }
  .roombar .btn { padding: 2px 8px; }
  .roombar { gap: 4px; }
  .room-label { display: none; }
  .party-btn { padding: 2px 6px; }
  .lobby-head { flex-wrap: wrap; }
}

/* ---------- Overlay putar HP (hanya layar tarung) ---------- */

.rotate-hint { display: none; }
@media (orientation: portrait) and (max-width: 600px) {
  body[data-screen="battle"] .rotate-hint {
    display: flex; position: fixed; inset: 0; z-index: 80; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; padding: 24px; text-align: center; background: rgba(10, 8, 14, .94); color: var(--ink);
  }
}
.rotate-icon { width: 44px; height: 72px; border: 3px solid var(--gold); border-radius: 8px; animation: rotate-hint 2.4s ease-in-out infinite; }
.rotate-title { font-weight: bold; color: var(--gold-hi); font-size: 1.1rem; margin: 0; }
.rotate-body { margin: 0; max-width: 280px; }
@keyframes rotate-hint { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }

/* ---------- Gerak dikurangi ---------- */

@media (prefers-reduced-motion: reduce) {
  .party-alert { animation: none; }
  .rotate-icon { transform: rotate(-90deg); }
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
