:root {
  --ink: #2b1d14;
  --cream: #f3e3c3;
  --gold: #e0b252;
  --terracotta: #a4452a;
}

html, body {
  margin: 0;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  font-family: system-ui, sans-serif;
}

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}

#ui {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

#move-label {
  position: absolute;
  left: 50%;
  top: max(10px, env(safe-area-inset-top));
  transform: translateX(-50%);
  color: var(--gold);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  text-shadow: 0 2px 0 #000, 0 0 8px rgba(0, 0, 0, 0.6);
  transition: opacity 0.25s;
  opacity: 0;
  white-space: nowrap;
}

#hint {
  position: fixed;
  z-index: 1;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 6px;
  background: rgba(43, 29, 20, 0.75);
  color: var(--cream);
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
  pointer-events: none;
  max-width: min(70vw, 640px);
  transition: opacity 1s;
}

.menu-button {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  width: 42px;
  height: 42px;
  border: 2px solid #6b3f23;
  border-radius: 8px;
  background: rgba(43, 29, 20, 0.8);
  color: var(--cream);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}

.menu-button.has-update::after {
  content: '';
  position: absolute;
  top: -4px;
  right: -4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e8571e;
  box-shadow: 0 0 0 2px var(--ink);
}

.menu-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 12, 8, 0.6);
  pointer-events: auto;
}

.menu-overlay[hidden] {
  display: none;
}

/* Batik frame: a kawung-like dot border drawn with gradients. */
.batik-frame {
  border: 10px solid transparent;
  border-image: repeating-radial-gradient(circle at 50% 50%, var(--gold) 0 2px, #6b3f23 2px 4px, var(--terracotta) 4px 6px) 10;
  box-shadow: 0 0 0 2px var(--ink), 0 12px 40px rgba(0, 0, 0, 0.5);
}

.menu-panel {
  width: min(360px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 18px;
  background: #3a2619;
  color: var(--cream);
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
}

.menu-panel h2 {
  margin: 0 0 4px;
  text-align: center;
  letter-spacing: 6px;
  color: var(--gold);
  font-size: 24px;
}

.menu-btn {
  padding: 10px 14px;
  border: 2px solid #6b3f23;
  border-radius: 6px;
  background: #4d321f;
  color: var(--cream);
  font-size: 16px;
  cursor: pointer;
}

.menu-btn:hover:not(:disabled) {
  border-color: var(--gold);
}

.menu-btn.primary {
  background: var(--terracotta);
  border-color: #c96a44;
  font-weight: 600;
}

.menu-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.menu-btn.update {
  background: #2f7a2c;
  border-color: #4aa03c;
}

.menu-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.menu-row > span {
  margin-right: 4px;
}

.menu-btn.chip {
  padding: 6px 10px;
  font-size: 14px;
}

.menu-btn.chip.active {
  border-color: var(--gold);
  background: rgba(224, 178, 82, 0.3);
}

.menu-update {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid #6b3f23;
}

.menu-update ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.4;
}

.update-title {
  color: #9be07a;
  font-weight: 600;
}

.muted {
  color: rgba(243, 227, 195, 0.65);
  font-size: 13px;
}

.small {
  font-size: 12px;
  text-align: center;
}

.flash {
  min-height: 16px;
  color: #9be07a;
  font-size: 13px;
}

/* Touch controls */
.touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 230px;
  padding: 0 max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
  opacity: 0.75;
}

body.portrait .touch {
  top: var(--stage-bottom);
  height: auto;
  align-items: center;
  opacity: 1;
}

.stick {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(243, 227, 195, 0.12) 0 55%, rgba(243, 227, 195, 0.05) 56%);
  border: 3px solid rgba(224, 178, 82, 0.55);
  pointer-events: auto;
  touch-action: none;
}

.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  background: rgba(168, 105, 46, 0.85);
  border: 3px solid var(--gold);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.pad {
  position: relative;
  width: 230px;
  height: 200px;
  pointer-events: none;
}

.tbtn {
  position: absolute;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  border-radius: 50%;
  border: 3px solid rgba(0, 0, 0, 0.5);
  color: #fff;
  font: 700 13px system-ui, sans-serif;
  text-shadow: 0 1px 2px #000;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
  -webkit-tap-highlight-color: transparent;
}

.tbtn.down {
  transform: translateY(3px) scale(0.95);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
  filter: brightness(1.25);
}

.tbtn.light { left: 56px; top: 104px; width: 80px; height: 80px; background: #c8322a; }
.tbtn.jump { left: 150px; top: 120px; width: 70px; height: 70px; background: #2f7a2c; }
.tbtn.heavy { left: 146px; top: 30px; width: 70px; height: 70px; background: #a8692e; }
.tbtn.special { left: 64px; top: 22px; width: 58px; height: 58px; background: #5b3a8a; }
.tbtn.dodge { left: 0; top: 136px; width: 52px; height: 52px; background: #3a4a6a; font-size: 11px; }

body.is-touch #hint {
  bottom: auto;
  top: calc(var(--stage-bottom, 50%) + 8px);
}

body.is-touch:not(.portrait) #hint {
  top: max(8px, env(safe-area-inset-top));
}

.again {
  position: absolute;
  left: 50%;
  top: 74%;
  transform: translateX(-50%);
  pointer-events: auto;
  font-size: 18px;
  padding: 12px 28px;
}

.again[hidden] {
  display: none;
}

/* Title, character select, settings */
.screens {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 30%, rgba(58, 38, 25, 0.55), rgba(18, 12, 10, 0.92));
  pointer-events: auto;
  color: var(--cream);
}

.screens[hidden] {
  display: none;
}

.title-screen {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gunungan {
  width: 96px;
  height: 120px;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.6));
}

.logo h1 {
  margin: 6px 0 0;
  font-size: clamp(34px, 9vw, 64px);
  letter-spacing: 0.18em;
  color: var(--gold);
  text-shadow: 0 3px 0 #6b3f23, 0 6px 18px rgba(0, 0, 0, 0.7);
}

.tagline {
  margin: 4px 0 0;
  color: rgba(243, 227, 195, 0.8);
  font-size: 14px;
  letter-spacing: 0.04em;
}

.title-menu {
  width: min(320px, 100%);
}

.nav-hint {
  opacity: 0.7;
}

.screen-center {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.hero-panel {
  width: min(560px, 100%);
}

.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
}

.hero-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  border: 2px solid #6b3f23;
  border-radius: 8px;
  background: #4d321f;
  color: var(--cream);
  font: inherit;
  cursor: pointer;
}

.hero-card canvas {
  width: 64px;
  height: 80px;
  image-rendering: pixelated;
}

.hero-card span {
  font-size: 12px;
  text-align: center;
}

.hero-card.active,
.hero-card:focus-visible {
  border-color: var(--gold);
  background: rgba(224, 178, 82, 0.25);
}

.hero-card.locked {
  opacity: 0.55;
  cursor: default;
}

.menu-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.menu-btn.danger {
  background: #5a1a14;
  border-color: #8a2a20;
}

.menu-row input[type='range'] {
  flex: 1;
  accent-color: var(--gold);
}

body.in-menu .touch,
body.in-menu #hint,
body.in-menu .menu-button {
  display: none;
}

/* Touch button size setting */
body[data-buttons='small'] .touch .stick { transform: scale(0.8); transform-origin: left bottom; }
body[data-buttons='small'] .touch .pad { transform: scale(0.8); transform-origin: right bottom; }
body[data-buttons='large'] .touch .stick { transform: scale(1.18); transform-origin: left bottom; }
body[data-buttons='large'] .touch .pad { transform: scale(1.18); transform-origin: right bottom; }
body.portrait[data-buttons] .touch .stick,
body.portrait[data-buttons] .touch .pad { transform-origin: center; }

.tbtn.special.ready {
  animation: jurus-ready 0.8s ease-in-out infinite;
}

@keyframes jurus-ready {
  0%, 100% { box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45), 0 0 0 0 rgba(120, 200, 255, 0.0); }
  50% { box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45), 0 0 18px 6px rgba(120, 200, 255, 0.85); }
}

.clear-buttons {
  position: absolute;
  left: 50%;
  top: calc(74% + 52px);
  transform: translateX(-50%);
  pointer-events: auto;
}

.clear-buttons .menu-btn {
  font-size: 16px;
  padding: 10px 22px;
  white-space: nowrap;
}

.clear-buttons [hidden] {
  display: none;
}

.stage-panel {
  width: min(420px, 100%);
}

.stage-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
}

.stage-card span {
  font-size: 12px;
}

.era-name {
  text-align: center;
  font-weight: 700;
  color: var(--gold);
}

.era-meter {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, #c8643a, #c8a050, #5aa84a);
  position: relative;
  border: 2px solid #120c0a;
}

.era-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-right: 3px solid #fff;
  background: transparent;
}

.era-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: rgba(243, 227, 195, 0.7);
}

.shop-panel {
  width: min(440px, 100%);
}

.shop-money {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  color: var(--gold);
}

.shop-card {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  text-align: left;
}

.shop-card span {
  font-size: 12px;
}

.shop-card .shop-price {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--gold);
}

/* Story scenes */
.story {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(12, 8, 6, 0.85);
  pointer-events: auto;
  z-index: 5;
}

.story[hidden] {
  display: none;
}

.story-box {
  width: min(560px, 100%);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 14px;
  background: #2a1c13;
  color: var(--cream);
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
}

.wayang {
  width: 100%;
  height: auto;
  border-radius: 4px;
  border: 2px solid #6b3f23;
}

.speaker {
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.05em;
}

.line {
  margin: 0;
  font-size: 16px;
  line-height: 1.45;
}

.dialogue {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.portrait {
  width: 80px;
  height: 80px;
  flex: none;
  image-rendering: pixelated;
  border: 2px solid var(--gold);
  border-radius: 6px;
}

.story-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.bribe {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.envelope {
  font-size: 22px;
  font-weight: 800;
  color: #f2e090;
  padding: 10px 18px;
  border: 2px dashed #c8a050;
  border-radius: 8px;
  background: #3a2a18;
}

.bribe-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.bribe-row .menu-btn {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bribe-row small {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.85;
}

/* Player 2 gamepad choice only matters on a computer. */
.is-touch .desktop-only { display: none; }

/* Stage clear / game over: the fight buttons step aside so nothing overlaps. */
body.choosing .touch {
  display: none;
}

body.portrait .again {
  top: calc(var(--stage-bottom, 60%) + 96px);
}

body.portrait .clear-buttons {
  top: calc(var(--stage-bottom, 60%) + 160px);
}

/* Title language switch and online room screen */
.lang-switch {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}

.room-code {
  font: 900 34px/1.2 monospace;
  letter-spacing: 8px;
  text-align: center;
  color: var(--gold);
  padding: 8px;
  border: 2px dashed rgba(224, 178, 82, 0.6);
  border-radius: 8px;
}

.code-input {
  flex: 1;
  min-width: 0;
  font: 700 20px monospace;
  letter-spacing: 4px;
  text-transform: uppercase;
  padding: 8px 10px;
  border-radius: 6px;
  border: 2px solid rgba(224, 178, 82, 0.55);
  background: #2a1d14;
  color: var(--cream);
}

.net-status {
  margin: 0;
  font-size: 14px;
  color: #f2e090;
}

.net-wait {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  padding: 14px 20px;
  border-radius: 8px;
  background: rgba(18, 12, 10, 0.85);
  color: var(--cream);
  font-size: 16px;
  text-align: center;
  max-width: 90%;
}

.net-wait[hidden] {
  display: none;
}

#hint:empty {
  display: none;
}

/* Controls page */
.controls-panel {
  width: min(560px, 100%);
}

.controls-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.controls-table th {
  text-align: left;
  color: var(--gold);
  font-size: 12px;
  padding: 4px 6px;
  border-bottom: 1px solid rgba(224, 178, 82, 0.4);
}

.controls-table td {
  padding: 6px;
  border-bottom: 1px solid rgba(243, 227, 195, 0.08);
  vertical-align: middle;
}

.controls-table .ctl-name {
  font-weight: 700;
}

.controls kbd {
  display: inline-block;
  min-width: 22px;
  margin: 1px 2px;
  padding: 2px 6px;
  border: 1px solid rgba(243, 227, 195, 0.5);
  border-bottom-width: 3px;
  border-radius: 5px;
  background: #2a1d14;
  font: 700 12px/1.3 monospace;
  text-align: center;
}

.controls-tips {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 13px;
  color: #e6d6b0;
}

.controls-tips li {
  margin: 3px 0;
}

/* Phones held sideways: logo on the left, the whole menu on the right, all on one screen. */
@media (orientation: landscape) and (max-height: 520px) {
  .title-screen {
    display: grid;
    grid-template-columns: auto minmax(260px, 420px);
    grid-template-rows: auto auto;
    align-content: center;
    justify-content: center;
    column-gap: 28px;
    row-gap: 6px;
    padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .title-screen .logo {
    grid-row: 1 / 3;
    align-self: center;
  }
  .title-screen .gunungan {
    width: 64px;
    height: 80px;
  }
  .title-screen .logo h1 {
    font-size: 34px;
  }
  .title-screen .title-menu {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 12px;
  }
  .title-screen .title-menu .menu-btn {
    padding: 8px 10px;
    font-size: 14px;
  }
  .title-screen .title-menu .menu-btn.primary {
    grid-column: 1 / -1;
  }
  .title-screen .lang-switch {
    margin-top: 0;
  }
  .title-screen .lang-switch .menu-btn {
    padding: 4px 12px;
    font-size: 13px;
  }
  .title-screen .nav-hint {
    display: none;
  }
}
