:root {
  --ink: #1d2733;
  --panel: rgba(16, 32, 44, 0.86);
  --panel-solid: #f6efe0;
  --gold: #f2c14e;
  --hp: #4cd16b;
  --xp: #5ab3ff;
  --danger: #ff4b3e;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e3a4f; font-family: "Trebuchet MS", system-ui, sans-serif; color: #f2f6f8; user-select: none; }
.hidden { display: none !important; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }

/* Sin backdrop-filter: desenfocar el 3D detrás de cada panel en cada cuadro es muy caro en el móvil. */
.hud-panel { position: fixed; z-index: 5; background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.15); border-radius: 14px; padding: 8px 10px; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25); }
/* Destello al recibir daño: sólo se anima la opacidad (lo hace la GPU, sin repintar). */
#hurt { position: fixed; inset: 0; z-index: 4; pointer-events: none; opacity: 0; background: radial-gradient(ellipse at center, transparent 55%, rgba(255, 0, 0, 0.45) 100%); will-change: opacity; }
.mini { border: none; border-radius: 8px; padding: 4px 8px; font: inherit; font-size: 12px; font-weight: 800; cursor: pointer; background: rgba(255, 255, 255, 0.15); color: #fff; text-decoration: none; }
.mini:hover { background: rgba(255, 255, 255, 0.28); }
.lvl { background: var(--gold); color: #3a2a00; border-radius: 999px; padding: 2px 9px; font-weight: 900; font-size: 14px; }
.lvl.small { font-size: 11px; padding: 1px 7px; }

/* Capitán */
#captain { top: max(10px, env(safe-area-inset-top)); left: 10px; width: 260px; }
.cap-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cap-head > div { flex: 1; min-width: 0; }
.cap-head b { display: block; font-size: 15px; }
.cap-head small { display: block; font-size: 11px; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cap-avatar { font-size: 26px; }
.bar { position: relative; height: 14px; border-radius: 7px; background: rgba(0, 0, 0, 0.45); overflow: hidden; margin: 4px 0; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--hp); transition: width 0.2s; }
.bar.xp { height: 9px; }
.bar.xp i { background: var(--xp); }
.bar span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 900; text-shadow: 0 1px 2px #000; }
.bar i.low { background: var(--danger); }
.bar i.mid { background: #f2a33a; }
.money { display: flex; gap: 12px; font-size: 14px; margin-top: 4px; align-items: center; }
#combat-flag { margin-left: auto; color: #ffb0a8; font-weight: 900; font-size: 12px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.4; } }

/* Minimapa */
#minimap-box { top: max(10px, env(safe-area-inset-top)); right: 10px; width: 222px; }
.map-name { font-size: 13px; margin-bottom: 4px; display: flex; justify-content: space-between; }
.zone { font-size: 11px; font-weight: 900; background: #2e8b57; padding: 1px 6px; border-radius: 6px; }
.zone.pvp { background: var(--danger); }
.zone.shield { background: #3a7bd5; }
#minimap { width: 200px; height: 200px; border-radius: 10px; display: block; background: #0d4a63; cursor: pointer; }
.mini-actions { display: flex; gap: 5px; align-items: center; margin-top: 6px; font-size: 11px; flex-wrap: wrap; }
#coords { flex: 1; opacity: 0.75; font-variant-numeric: tabular-nums; }

/* Objetivo */
#target { top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: 280px; text-align: center; }
.tgt-head { font-size: 14px; }
.tgt-foot { display: flex; justify-content: space-between; font-size: 12px; opacity: 0.85; }
#tgt-dist.far { color: #ffb0a8; font-weight: 900; }
#boss-bar { position: fixed; z-index: 5; top: 92px; left: 50%; transform: translateX(-50%); background: rgba(75, 45, 107, 0.85); padding: 4px 12px; border-radius: 10px; font-size: 12px; font-weight: 800; }

/* Barra de acción */
#actionbar { bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 20px); }
#ammo-slots { display: flex; gap: 5px; }
.slot { position: relative; width: 50px; height: 50px; border-radius: 10px; border: 2px solid rgba(255, 255, 255, 0.2); background: rgba(0, 0, 0, 0.35); color: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; font: inherit; padding: 0; }
.slot .ball { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.35); }
.slot small { font-size: 10px; font-weight: 900; margin-top: 2px; }
.slot .key { position: absolute; top: 1px; left: 4px; font-size: 9px; opacity: 0.7; }
.slot.sel { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(242, 193, 78, 0.4); }
.slot.empty { opacity: 0.4; }
.act-buttons { display: flex; gap: 5px; }
.act { width: 56px; height: 50px; border: none; border-radius: 10px; background: rgba(255, 255, 255, 0.14); color: #fff; font-size: 18px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: inherit; }
.act small { font-size: 10px; font-weight: 800; }
.act.on { background: #c0392b; }
.act.gold { background: #b8860b; animation: pulse 1.2s infinite; }
.act:active { transform: translateY(2px); }
@keyframes pulse { 50% { filter: brightness(1.3); } }
#cannon-info { font-size: 11px; opacity: 0.8; max-width: 120px; line-height: 1.3; }

/* Chat */
#chat { left: 80px; bottom: max(10px, env(safe-area-inset-bottom)); width: 300px; padding: 6px; }
.chat-tabs { display: flex; gap: 4px; margin-bottom: 4px; }
.chat-tabs button { border: none; border-radius: 7px; padding: 3px 9px; font: inherit; font-size: 12px; font-weight: 800; background: transparent; color: #cfe; cursor: pointer; }
.chat-tabs button.sel { background: rgba(255, 255, 255, 0.18); color: #fff; }
#chat-toggle { margin-left: auto; }
#chat-log { height: 130px; overflow-y: auto; font-size: 12.5px; line-height: 1.35; padding-right: 4px; }
#chat-log .m b { color: var(--gold); }
#chat-log .m.global b { color: #8fd3ff; }
#chat-log .m.sys { color: #b8f5c4; font-style: italic; }
#chat.collapsed #chat-log, #chat.collapsed #chat-form { display: none; }
#chat-input { width: 100%; margin-top: 4px; border: none; border-radius: 8px; padding: 7px 9px; font: inherit; font-size: 13px; background: rgba(255, 255, 255, 0.92); color: var(--ink); user-select: text; }

/* Etiquetas sobre los barcos */
.elabel { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; white-space: nowrap; will-change: transform; }
.elabel .ename { font-size: 11px; font-weight: 800; text-shadow: 0 1px 2px #000, 0 0 4px #000; }
.elabel.npc .ename { color: #ffd9a8; }
.elabel.player .ename { color: #b8f5c4; }
.elabel.me .ename { color: #fff; }
.elabel.aggro .ename { color: #ff8a80; }
.elabel.boss .ename { color: #e3b5ff; font-size: 14px; }
.elabel.selected .ename { text-decoration: underline; }
.elabel .ehp { width: 56px; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.55); overflow: hidden; }
.elabel.boss .ehp { width: 120px; height: 8px; }
.elabel .ehp i { display: block; height: 100%; background: var(--hp); }
.elabel .ehp i.low { background: var(--danger); }
.elabel .ehp i.mid { background: #f2a33a; }
.elabel.gone { opacity: 0; transition: opacity 1s; }
.fdmg { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 18px; text-shadow: 0 2px 3px #000; animation: rise 1.1s ease-out forwards; pointer-events: none; }
.fdmg.hit { color: #ffe066; }
.fdmg.hurt { color: #ff6b5e; }
.fdmg.gain { color: #9cff8f; font-size: 16px; }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, -20%) scale(0.7); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -220%); } }

/* Avisos: pequeños, en la esquina inferior derecha */
#notices { position: fixed; z-index: 8; right: 10px; bottom: 96px; display: flex; flex-direction: column; gap: 3px; align-items: flex-end; pointer-events: none; max-width: 260px; }
.notice { background: rgba(16, 32, 44, 0.85); border: 1px solid rgba(255, 255, 255, 0.2); padding: 3px 7px; border-radius: 6px; font-weight: 700; font-size: var(--notice-size, 6px); line-height: 1.35; animation: nin 0.25s ease-out; }
.notice.good { border-color: #4cd16b; color: #c8ffd2; }
.notice.bad { border-color: var(--danger); color: #ffd0cc; }
.notice.epic { background: rgba(75, 45, 107, 0.95); border-color: #c98bff; }
@keyframes nin { from { opacity: 0; transform: translateY(-8px); } }

/* Paneles */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(5, 15, 22, 0.55); }
.panel { width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--panel-solid); color: var(--ink); border-radius: 18px; padding: 18px 20px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5); }
.panel h2 { margin: 0 0 6px; }
.panel h3 { margin: 14px 0 6px; font-size: 15px; }
.note { font-size: 13px; opacity: 0.75; margin: 4px 0; }
.shop { display: flex; flex-direction: column; gap: 6px; }
.shop-row { display: flex; align-items: center; gap: 10px; background: #ebe1cc; border-radius: 12px; padding: 8px 10px; }
.shop-row .ball { width: 20px; height: 20px; border-radius: 50%; flex: none; }
.shop-row .info { flex: 1; font-size: 13px; }
.shop-row .info b { display: block; font-size: 14px; }
.btn { border: none; border-radius: 10px; padding: 8px 14px; font: inherit; font-weight: 900; background: #1f7a8c; color: #fff; cursor: pointer; box-shadow: 0 3px 0 #11505c; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #11505c; }
.panel-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
#world-grid { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.wmap { flex: 1 1 140px; background: #ebe1cc; border-radius: 12px; padding: 10px; border: 3px solid transparent; }
.wmap.here { border-color: #1f7a8c; }
.wmap.locked { opacity: 0.55; }
.wmap b { display: block; }
.wmap small { font-size: 12px; }
#rank-list { padding-left: 24px; line-height: 1.7; font-weight: 700; }

#help { position: fixed; z-index: 6; left: 50%; bottom: 96px; transform: translateX(-50%); background: rgba(16, 32, 44, 0.9); padding: 8px 14px; border-radius: 12px; font-size: 13px; max-width: calc(100vw - 20px); text-align: center; }
#loading { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: #0e3a4f; font-weight: 900; font-size: 22px; }

/* Barra lateral izquierda */
#rail { left: 10px; top: 132px; padding: 5px; display: flex; flex-direction: column; gap: 5px; max-height: calc(100vh - 142px); overflow-y: auto; scrollbar-width: none; }
#rail::-webkit-scrollbar { display: none; }
#rail .act { flex: none; }
.rail-zoom { display: flex; flex-direction: column; gap: 3px; }
.rail-zoom .act { height: 34px; font-size: 20px; font-weight: 900; }
#rail-hp { display: none; height: 6px; margin: 0 2px; }
#rail-hp i { display: block; height: 100%; background: var(--hp); border-radius: 999px; transition: width .2s; }
#rail-hp i.mid { background: #f2c14e; }
#rail-hp i.low { background: var(--danger); }

/* Interfaz oculta: sólo la barra lateral, los nombres sobre los barcos y los avisos */
body.ui-hidden #captain, body.ui-hidden #minimap-box, body.ui-hidden #target, body.ui-hidden #actionbar,
body.ui-hidden #chat, body.ui-hidden #boss-bar, body.ui-hidden #happy-banner, body.ui-hidden #patrol-chip,
body.ui-hidden #help, body.ui-hidden .ol-pill, body.ui-hidden .ol-panel { display: none !important; }
body.ui-hidden #rail { top: max(10px, env(safe-area-inset-top)); max-height: calc(100vh - 20px); background: rgba(16, 32, 44, 0.45); }
body.ui-hidden #rail-hp { display: block; }
body.ui-hidden #btn-hide { background: #1f7a8c; }
body.ui-hidden #notices { bottom: 10px; }

@media (max-width: 760px) {
  #rail { top: 114px; max-height: calc(100vh - 124px); gap: 4px; padding: 4px; }
  #chat { left: 64px; }
  #captain { width: 190px; padding: 6px 8px; }
  .cap-head small { display: none; }
  #minimap-box { width: 132px; padding: 6px; }
  #minimap { width: 120px; height: 120px; }
  .mini-actions #coords { display: none; }
  #target { top: auto; bottom: 150px; width: 220px; }
  #chat { width: 200px; bottom: 150px; }
  #chat-log { height: 70px; }
  #actionbar { gap: 6px; padding: 6px; }
  .slot { width: 42px; height: 42px; }
  .act { width: 46px; height: 42px; }
  #cannon-info { display: none; }
  #help { bottom: auto; top: 50%; transform: translate(-50%, -50%); font-size: 12px; width: 88vw; }
  #boss-bar { display: none !important; }
  .map-name { flex-direction: column; gap: 2px; font-size: 12px; }
  .mini-actions { flex-wrap: wrap; }
}

/* Puerto con pestañas */
.panel.wide { width: min(640px, 100%); }
.port-tabs { display: flex; gap: 6px; margin: 10px 0 4px; flex-wrap: wrap; }
.port-tabs button { border: none; border-radius: 10px; padding: 7px 12px; font: inherit; font-weight: 900; cursor: pointer; background: #e3d6bb; color: var(--ink); }
.port-tabs button.sel { background: #1f7a8c; color: #fff; }
.lvlbar { display: flex; gap: 3px; margin-top: 4px; }
.lvlbar i { width: 12px; height: 7px; border-radius: 2px; background: #cdbf9f; }
.lvlbar i.on { background: #1f7a8c; }
.shop-row.elite { background: linear-gradient(90deg, #f6e6a8, #ebe1cc); }
.shop-row .tag { font-size: 10px; font-weight: 900; background: #d4af37; color: #3a2a00; border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 40px; height: 40px; border-radius: 10px; border: 3px solid #fff; box-shadow: 0 2px 4px rgba(0,0,0,.3); cursor: pointer; position: relative; font-size: 13px; color: #fff; text-shadow: 0 1px 2px #000; }
.swatch.sel { border-color: #1f7a8c; transform: scale(1.1); }
.swatch:disabled { opacity: 0.35; cursor: not-allowed; }
#chat-log .m .crown { color: var(--gold); }

.shop-row.special { background: linear-gradient(90deg, #1b2b27, #2d4a42); color: #dffff4; }
.shop-row .tag.special { background: #5cffd2; color: #0b2a22; }

.rename { display: flex; gap: 8px; }
.rename input { flex: 1; border: 2px solid #d7c7a8; border-radius: 10px; padding: 7px 10px; font: inherit; font-weight: 700; user-select: text; }
#btn-auto.on { background: #2e8b57; }

/* Mi barco y timonel */
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; text-align: left; }
.stat { background: #ebe1cc; border-radius: 12px; padding: 8px 10px; }
.stat small { display: block; font-size: 11px; font-weight: 800; opacity: .7; text-transform: uppercase; letter-spacing: .4px; }
.stat b { font-size: 18px; }
.stat .bar { height: 6px; margin-top: 4px; background: rgba(0,0,0,.12); }
.stat .bar i { background: #1f7a8c; }
#patrol-map { width: min(100%, 420px); aspect-ratio: 1; display: block; margin: 8px auto; border-radius: 14px; background: #0d4a63; cursor: crosshair; touch-action: none; }
.patrol-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn.ghost { background: #e3d6bb; color: var(--ink); box-shadow: 0 3px 0 #b8a983; }
.btn.danger { background: var(--danger); color: #fff; }
#patrol-chip { position: fixed; z-index: 5; top: 122px; left: 50%; transform: translateX(-50%); background: rgba(31,122,140,.92); padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 800; }

/* Happy Time y panel de administrador */
#happy-banner { position: fixed; z-index: 6; top: 148px; left: 50%; transform: translateX(-50%); padding: 5px 16px; border-radius: 999px; font-weight: 900; font-size: 14px; color: #3a2a00;
  background: linear-gradient(90deg, #ffd34d, #ff8ad8, #8ad8ff, #ffd34d); background-size: 300% 100%; animation: happy 3s linear infinite; box-shadow: 0 4px 14px rgba(0,0,0,.3); }
@keyframes happy { to { background-position: 300% 0; } }
.adm-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 800; margin: 10px 0 4px; }
.adm-row input { width: 110px; padding: 7px 10px; border-radius: 10px; border: 2px solid #d7c7a8; font: inherit; font-weight: 800; user-select: text; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { border: none; border-radius: 999px; padding: 5px 12px; font: inherit; font-weight: 800; background: #e3d6bb; cursor: pointer; }
.happy-status { background: #ebe1cc; border-radius: 12px; padding: 8px 12px; font-weight: 800; }
.happy-status.on { background: linear-gradient(90deg, #ffe680, #ffc2ec); }

.shop-row .missing { margin-top: 3px; font-size: 12px; font-weight: 800; color: #b3261e; }

/* ID de barco, ficha y denuncias */
.code-box { background: #ebe1cc; border-radius: 12px; padding: 8px 12px; margin: 6px 0; font-size: 14px; }
.code-box b { font-family: ui-monospace, Consolas, monospace; font-size: 16px; letter-spacing: 1px; }
.code-box small { display: block; opacity: .7; margin-top: 3px; }
.btn.small { padding: 3px 10px; font-size: 12px; }
#rep-details { width: 100%; min-height: 70px; border-radius: 10px; border: 2px solid #d7c7a8; padding: 8px; font: inherit; user-select: text; }
#rep-reason { padding: 6px; border-radius: 8px; font: inherit; }
.rep-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; margin-top: 6px; }
.rep { background: #ebe1cc; border-radius: 12px; padding: 8px 10px; font-size: 13px; }
.rep b { font-family: ui-monospace, Consolas, monospace; }
.rep .acts { display: flex; gap: 6px; margin-top: 4px; }
.rep.revisada { opacity: .75; } .rep.descartada { opacity: .55; }
#lookup-result .code-box { font-size: 13px; }
