:root {
  --ink: #2a1d33;
  --paper: #fbf1dc;
  --paper-2: #efdcb4;
  --red: #d8402f;
  --red-dark: #9e2a1e;
  --gold: #f2cf5b;
  --blue: #3a6ad8;
  --green: #4fc36f;
  --hp: #ff5a5a;
  --spirit: #ffb03a;
  --round: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Segoe UI Rounded", "Segoe UI", system-ui, sans-serif;
  --display: "Impact", "Haettenschweiler", "Arial Black", "Segoe UI Black", sans-serif;
  --shadow: 0 4px 0 rgb(42 29 51 / 0.9);
  font: 15px/1.35 var(--round);
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8fcfff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body { overscroll-behavior: none; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 2px solid var(--ink);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: #fff;
  font: 800 0.78rem/1.35 var(--round);
  text-align: center;
}

canvas#world { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; z-index: 0; }

/* --- Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 900;
  font-size: 1.05rem;
  box-shadow: var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
  text-decoration: none;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.06); box-shadow: 0 6px 0 var(--ink); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.red { background: var(--red); color: #fff; }
.btn.plain { background: var(--paper); }
.btn.big { padding: 14px 34px; font-size: 1.3rem; }
.link { background: none; border: 0; text-decoration: underline; opacity: 0.7; padding: 4px; }

/* --- HUD ------------------------------------------------------------------- */

#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud .hud-left, #hud .hud-center, #hud .hud-right, #hud #moves, #hud #tutorial { pointer-events: none; }
#hud .hud-right > * { pointer-events: auto; }

.hud-left {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.portrait {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: radial-gradient(circle at 40% 35%, #fff4d8, var(--gold));
  display: grid;
  place-items: center;
  font-size: 2rem;
  box-shadow: var(--shadow);
}
.bars { display: flex; flex-direction: column; gap: 5px; padding-top: 3px; }
.bar {
  position: relative;
  width: min(220px, 42vw);
  height: 20px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: rgb(42 29 51 / 0.55);
  overflow: hidden;
  box-shadow: 0 3px 0 rgb(42 29 51 / 0.6);
}
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--hp); transition: width 0.15s; }
.bar span { position: relative; display: block; padding: 0 8px; font: 800 0.75rem/14px var(--round); color: #fff; text-shadow: 0 1px 0 var(--ink), 0 0 3px var(--ink); }
.bar.hp.low i { animation: pulse 0.6s infinite alternate; }
.bar.spirit { height: 16px; width: min(180px, 36vw); }
.bar.spirit i { background: linear-gradient(90deg, #ff8a3a, var(--spirit)); }
.bar.spirit span { line-height: 10px; font-size: 0.68rem; }
.bar.spirit.full i { background: linear-gradient(90deg, #ff5ab8, #ffd05a); animation: pulse 0.5s infinite alternate; }
.bar.ship i { background: #7ac0f0; }
#gear-badge { font-weight: 900; color: #fff; text-shadow: 0 2px 0 var(--red-dark), 0 0 4px var(--red); }
@keyframes pulse { to { filter: brightness(1.4); } }

.hud-center {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(520px, 90vw);
}
#objective {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 8px;
  background: rgb(251 241 220 / 0.94);
  border: 3px solid var(--ink);
  border-radius: 999px;
  font-weight: 800;
  box-shadow: var(--shadow);
  max-width: 100%;
}
#objective-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#compass {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 1rem;
  border: 2px solid var(--ink);
  transition: transform 0.1s linear;
}
#boss-bar { width: 100%; text-align: center; }
.boss-label { color: #fff; font-weight: 900; font-size: 1.1rem; text-shadow: 0 2px 0 var(--ink), 0 0 4px var(--ink); }
.boss-label small { font-weight: 700; font-size: 0.8rem; opacity: 0.9; }
.bar.boss { width: 100%; height: 18px; }
.bar.boss i { background: linear-gradient(90deg, #c8282a, #ff6a3a); }
#boss-bar.armored .bar.boss { border-color: #b08a20; box-shadow: 0 0 0 3px var(--gold); }
#boss-bar.sand .bar.boss i { background: repeating-linear-gradient(45deg, #e8c47a 0 8px, #c8a45a 8px 16px); }

.hud-right {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 44vw;
}
.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  font-size: 1.1rem;
  box-shadow: 0 3px 0 var(--ink);
  text-decoration: none;
  color: var(--ink);
  font-weight: 900;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.icon-btn.off { opacity: 0.45; }
#crew-icons, #pone-icons { display: flex; gap: 3px; align-items: center; padding: 2px 6px; border-radius: 12px; background: rgb(251 241 220 / 0.85); border: 3px solid var(--ink); height: 38px; }
#crew-icons .icon { width: 28px; height: 28px; display: grid; place-items: center; font-size: 1.1rem; border-radius: 50%; background: #fff; border: 2px solid var(--ink); }
#crew-icons .icon.me { background: var(--gold); }
#crew-icons .icon.missing { background: #cfc4b0; color: #7a6a5a; font-weight: 900; font-size: 0.9rem; }
#pone-icons .stone { width: 16px; height: 22px; border-radius: 3px; background: #b8b0a0; border: 2px solid var(--ink); opacity: 0.4; }
#pone-icons .stone.found { background: #d8402f; opacity: 1; box-shadow: 0 0 6px #ff9a6a; }

#moves {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}
.move {
  position: relative;
  width: 64px;
  padding: 5px 2px 4px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: rgb(251 241 220 / 0.94);
  text-align: center;
  overflow: hidden;
  box-shadow: 0 3px 0 var(--ink);
}
.move-icon { display: block; font-size: 1.35rem; line-height: 1.2; }
.move kbd { font-size: 0.66rem; min-width: 1.4em; }
.move-name { display: block; font-size: 0.62rem; font-weight: 800; line-height: 1.1; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.move .cd { position: absolute; inset: 0; background: rgb(42 29 51 / 0.45); transform-origin: bottom; transform: scaleY(0); pointer-events: none; }
.move.locked { opacity: 0.45; }
.move.dim .move-icon { filter: grayscale(1); opacity: 0.6; }

#prompt {
  position: absolute;
  left: 50%;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 92px);
  transform: translateX(-50%);
  padding: 8px 18px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--gold);
  font-weight: 900;
  box-shadow: var(--shadow);
  white-space: nowrap;
  animation: bob 1s ease-in-out infinite alternate;
}
@keyframes bob { to { transform: translate(-50%, -4px); } }

#tutorial {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-50%);
  width: 250px;
  padding: 12px 14px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: rgb(251 241 220 / 0.94);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
}
#tutorial h4 { margin: 0 0 6px; font-size: 1rem; }
#tutorial ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 5px; }

#toast {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(560px, 90vw);
  padding: 10px 20px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--paper);
  font-weight: 800;
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: none;
}
#banner {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  z-index: 41;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 34px;
  background: var(--red);
  color: #fff;
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--ink), 0 18px 50px rgb(0 0 0 / 0.3);
  text-align: center;
  pointer-events: none;
  max-width: 92vw;
}
#banner strong { font: 2rem/1.05 var(--display); letter-spacing: 0.03em; text-shadow: 0 3px 0 var(--red-dark); }
#banner span { font-weight: 700; }
.pop { animation: pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes pop { from { transform: translateX(-50%) scale(0.4); opacity: 0; } }

/* --- Floating text ------------------------------------------------------------- */

#fx { position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; }
.float {
  position: absolute;
  left: 0;
  top: 0;
  font: 900 1.25rem/1 var(--round);
  color: #fff;
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
  will-change: transform;
}
.float.crit { font-size: 1.9rem; color: var(--gold); }
.float.hurt { color: #ff6a6a; }
.float.heal { color: #7aef8a; }
.float.ally { font-size: 1rem; color: #cfe8ff; }
.float.info { font-size: 1rem; color: #fff4c8; }
.float.warn { font-size: 1.8rem; color: #ff4a3a; }
.float.boing { font: 1.9rem/1 var(--display); color: #ffe070; letter-spacing: 0.04em; }
.float.boss { font-size: 1.15rem; color: #ffd0d0; }
.float.callout { font: 2.3rem/1 var(--display); color: #ffe070; letter-spacing: 0.04em; -webkit-text-stroke: 2px var(--ink); text-shadow: 0 4px 0 var(--red-dark); }

/* --- Dialogue --------------------------------------------------------------------- */

#dialogue {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  padding: 0 12px max(16px, env(safe-area-inset-bottom));
}
.dialogue-box {
  display: flex;
  gap: 14px;
  width: min(760px, 100%);
  padding: 14px 18px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--ink), 0 20px 60px rgb(0 0 0 / 0.3);
  cursor: pointer;
}
.dialogue-portrait {
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--paper-2);
  display: grid;
  place-items: center;
  font-size: 2.4rem;
}
#dialogue[data-who="luffy"] .dialogue-portrait { background: var(--gold); }
.dialogue-main { flex: 1; min-width: 0; }
.speaker { font: 1.3rem/1 var(--display); color: var(--red); letter-spacing: 0.03em; }
#dialogue-text { margin: 6px 0 4px; font-size: 1.08rem; font-weight: 600; min-height: 3em; }
.dialogue-foot { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; opacity: 0.75; }
.next { animation: bob 0.7s ease-in-out infinite alternate; font-weight: 800; }

/* --- Title ------------------------------------------------------------------------ */

#title {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgb(0 0 0 / 0) 30%, rgb(20 40 80 / 0.35));
}
.title-card {
  width: min(460px, 100%);
  padding: 22px 26px 18px;
  text-align: center;
  background: linear-gradient(#fbf1dc, #efdcb4);
  border: 4px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 8px 0 var(--ink), 0 30px 80px rgb(0 0 0 / 0.35);
}
.wanted { margin: 0; font: 1rem/1 var(--display); letter-spacing: 0.3em; text-transform: uppercase; color: var(--red-dark); }
.logo {
  margin: 8px 0 4px;
  font: 3.4rem/0.95 var(--display);
  letter-spacing: 0.02em;
  color: var(--gold);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--red);
}
.logo span { display: block; color: #fff; text-shadow: 0 5px 0 var(--blue); }
.tagline { margin: 6px 0 16px; font-weight: 800; }
.title-buttons { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.title-foot { margin: 14px 0 0; font-size: 0.8rem; opacity: 0.7; }
.lang-picker {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 3px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
}
.lang-picker span { padding: 0 4px 0 6px; }
.lang-picker button { border: 0; border-radius: 999px; padding: 4px 12px; background: none; font-weight: 800; }
.lang-picker button.on { background: var(--red); color: #fff; }

/* --- Modal ------------------------------------------------------------------------ */

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 14px; background: rgb(20 20 40 / 0.5); }
.modal-card {
  position: relative;
  width: min(760px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 20px 24px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 8px 0 var(--ink);
  user-select: text;
}
.modal-card h2 { margin: 0 0 10px; font: 2rem/1 var(--display); color: var(--red); letter-spacing: 0.02em; }
.modal-card h3 { margin: 14px 0 6px; }
.modal-card .close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 1.3rem; font-weight: 900; }
.modal-card .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.modal-card .keys { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.modal-card .keys li.locked { opacity: 0.55; }
.modal-card .keys em { display: block; font-size: 0.85em; }
.modal-card .tip { background: var(--paper-2); padding: 8px 12px; border-radius: 12px; }
.modal-card .actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 16px; }
.modal-card canvas { display: block; width: 100%; height: auto; border: 3px solid var(--ink); border-radius: 12px; }
.modal.center .modal-card { text-align: center; width: min(460px, 100%); }
.modal.victory .modal-card { background: linear-gradient(#fff4c8, #f2cf5b); }
.big-emoji { font-size: 4rem; line-height: 1; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-weight: 800; background: var(--paper); margin: 0; }

/* --- Touch ------------------------------------------------------------------------ */

#touch { display: none; }
body.touch #touch { display: block; position: fixed; inset: 0; z-index: 8; }
#stick { position: fixed; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
#stick::before { content: ''; position: absolute; left: -55px; top: -55px; width: 110px; height: 110px; border-radius: 50%; border: 3px solid rgb(255 255 255 / 0.7); background: rgb(42 29 51 / 0.2); }
#stick-knob { position: absolute; left: -24px; top: -24px; width: 48px; height: 48px; border-radius: 50%; background: rgb(255 255 255 / 0.85); border: 3px solid var(--ink); }
.touch-buttons {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 90px);
  display: grid;
  grid-template-columns: repeat(3, 56px);
  gap: 8px;
  direction: rtl;
}
.touch-buttons button, #touch-interact {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: rgb(251 241 220 / 0.9);
  font-size: 1.5rem;
  box-shadow: 0 3px 0 var(--ink);
}
.touch-buttons button.big { background: var(--gold); }
.touch-buttons button.on, #touch-interact.on { transform: translateY(2px); filter: brightness(0.85); }
#touch-interact { position: fixed; left: 50%; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 140px); transform: translateX(-50%); width: 64px; height: 64px; font: 900 1.4rem var(--round); background: var(--gold); }
body.touch.sailing .land-only button:not([data-action="pistol"]):not([data-action="whip"]) { display: none; }
body.touch #tutorial { display: none; }
body.touch #moves .move-name, body.touch #moves kbd { display: none; }
body.touch #moves .move { width: 44px; }

@media (max-width: 700px) {
  .modal-card .cols { grid-template-columns: 1fr; }
  .move { width: 50px; }
  .move-name { display: none; }
  #objective { font-size: 0.8rem; }
  .logo { font-size: 2.6rem; }
  .hud-right { max-width: 50vw; }
  .icon-btn { width: 32px; height: 32px; font-size: 0.95rem; }
  #crew-icons, #pone-icons { height: 32px; }
  #crew-icons .icon { width: 22px; height: 22px; font-size: 0.85rem; }
  .portrait { width: 44px; height: 44px; font-size: 1.5rem; }
  #banner strong { font-size: 1.5rem; }
}
