/* HUD, avisos, ventana de puzle, carta náutica, llegada a puerto y ficha. */
.panel { position: fixed; z-index: 5; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,0.45); }
#ship-title { top: calc(12px + env(safe-area-inset-top)); left: calc(14px + env(safe-area-inset-left)); padding: 8px 14px; display: flex; flex-direction: column; }
#ship-title b { font-family: 'Pirata One', serif; font-weight: 400; font-size: 22px; color: var(--gold); letter-spacing: 1px; line-height: 1.1; }
#ship-title span { font-size: 14px; color: var(--muted); font-style: italic; }
#topright { top: calc(12px + env(safe-area-inset-top)); right: calc(14px + env(safe-area-inset-right)); padding: 6px; display: flex; align-items: center; gap: 6px; }
#topright .coins { padding: 0 8px; font-size: 17px; }
#topright .coins b { color: #ffd36a; }
#topright button { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border); background: rgba(255,255,255,0.04); cursor: pointer; font-size: 17px; }
#topright button:hover { border-color: var(--gold); }
#hint { top: calc(74px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); padding: 6px 14px; font-style: italic; color: #ffe9b0; text-align: center; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { box-shadow: 0 0 18px rgba(224,183,90,0.35); } }

#voyage { left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom)); width: min(560px, calc(100vw - 24px)); padding: 10px 14px; }
.bars { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 12px; }
.bar span { display: block; font-family: 'Cinzel', serif; font-size: 12px; color: var(--muted); letter-spacing: 0.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar div { height: 10px; border-radius: 5px; background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.14); overflow: hidden; margin-top: 3px; }
.bar i { display: block; height: 100%; width: 0; transition: width 0.3s; }
.wind i { background: linear-gradient(90deg, #8fb8c9, #e8f4ff); }
.water i { background: linear-gradient(90deg, #2f7fb0, #4fb6d9); }
.water i.high { background: linear-gradient(90deg, #c0502a, #ff8a4a); }
.trip i { background: linear-gradient(90deg, #b8862e, #ffd36a); }
#v-status { margin-top: 6px; font-size: 14px; color: var(--muted); font-style: italic; text-align: center; min-height: 18px; }
#v-docked { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#v-port { font-family: 'Cinzel', serif; color: var(--ink); font-size: 15px; }
button.seal { flex: none; font-family: 'Cinzel', serif; font-weight: 700; font-size: 14px; padding: 9px 16px; border-radius: 10px; cursor: pointer; border: 1px solid var(--gold); background: linear-gradient(180deg, #8a2a22, #5a1814); color: #ffe9b0; }
button.seal:hover { filter: brightness(1.15); }
button.seal:disabled { opacity: 0.45; cursor: default; filter: none; }

#toasts { position: fixed; z-index: 30; left: 50%; top: calc(120px + env(safe-area-inset-top)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 7px 16px; font-family: 'Cinzel', serif; font-size: 15px; box-shadow: 0 6px 24px rgba(0,0,0,0.5); animation: drop 0.3s ease-out; transition: opacity 0.5s, transform 0.5s; text-align: center; max-width: calc(100vw - 32px); }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } }

/* Ventanas */
.modal { position: fixed; z-index: 12; left: 50%; top: 50%; transform: translate(-50%, -50%); max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow: auto;
  background: rgba(8, 18, 26, 0.97); border: 1.5px solid var(--gold); border-radius: 14px; padding: 12px 16px 14px; box-shadow: 0 12px 48px rgba(0,0,0,0.85); animation: unroll 0.25s ease-out; }
@keyframes unroll { from { opacity: 0; transform: translate(-50%, -46%); } }
.m-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 10px; }
.m-head small { color: #ffe9b0; font-size: 14px; }
button.close { flex: none; width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: rgba(255,255,255,0.04); cursor: pointer; font-size: 15px; color: var(--muted); }
button.close:hover { color: var(--ink); border-color: var(--gold); }

#puzzle { padding-bottom: 10px; }
.pz-body { display: flex; gap: 14px; align-items: flex-start; }
#pz-canvas { display: block; border-radius: 10px; border: 1px solid rgba(224,183,90,0.3); touch-action: none; user-select: none; cursor: pointer; }
#pz-side { width: 150px; display: flex; flex-direction: column; gap: 8px; }
.st { background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; padding: 5px 9px; }
.st small { display: block; font-size: 12px; color: var(--muted); font-family: 'Cinzel', serif; }
.st b { font-size: 19px; color: var(--ink); }
.st.rank b { color: #ffd36a; font-family: 'Cinzel', serif; font-size: 16px; }
#pz-help { margin: 10px 0 0; font-size: 14px; color: var(--muted); font-style: italic; max-width: 560px; }

#map-canvas { display: block; width: 100%; border-radius: 8px; }
#map { width: min(520px, calc(100vw - 16px)); }
#map-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.dest { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 9px; background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.08); }
.dest b { font-family: 'Cinzel', serif; font-size: 15px; }
.dest small { display: block; color: var(--muted); font-size: 13px; font-style: italic; }
.dest button { flex: none; padding: 6px 12px; font-size: 13px; }
.map-note { color: var(--muted); font-style: italic; text-align: center; margin: 4px 0; }

#arrive { width: min(400px, calc(100vw - 24px)); text-align: center; }
#arrive-body p { margin: 6px 0; font-size: 17px; }
#arrive-body .loot { font-family: 'Cinzel', serif; font-size: 22px; color: #ffd36a; margin: 12px 0 4px; }
#arrive-body small { color: var(--muted); font-style: italic; }

#me { width: min(440px, calc(100vw - 24px)); }
.me-body { display: flex; gap: 14px; align-items: flex-start; }
#me-stats { flex: 1; display: flex; flex-direction: column; gap: 6px; }

@media (max-width: 720px) {
  #ship-title { padding: 5px 10px; }
  #ship-title b { font-size: 18px; }
  #ship-title span { font-size: 12px; }
  #topright button { width: 32px; height: 32px; font-size: 15px; }
  #hint { top: calc(64px + env(safe-area-inset-top)); font-size: 14px; }
  .bars { gap: 8px; }
  .bar span { font-size: 10px; }
  #v-status { font-size: 12px; }
  .pz-body { flex-direction: column; align-items: center; }
  #pz-side { width: 100%; flex-direction: row; flex-wrap: wrap; gap: 6px; }
  #pz-side .st { flex: 1 1 30%; padding: 3px 7px; }
  .st b { font-size: 16px; }
  #pz-help { font-size: 13px; }
}

/* Combate naval */
#battle { left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); width: min(420px, calc(100vw - 24px)); padding: 8px 14px; border-color: #ff9a4a; box-shadow: 0 0 30px rgba(255,120,40,0.3); display: flex; flex-direction: column; gap: 5px; }
.b-row { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 10px; }
.b-row span { font-family: 'Cinzel', serif; font-size: 13px; color: #ffb36a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hp { height: 11px; border-radius: 6px; background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.15); overflow: hidden; }
.hp i { display: block; height: 100%; background: linear-gradient(90deg, #8a2a22, #e0503a); transition: width 0.4s; }
.hp.mine i { background: linear-gradient(90deg, #8a6a3e, #d8b46a); }
.hp.mine i.low { background: linear-gradient(90deg, #c03a2a, #ff6a4a); }
@media (max-width: 720px) {
  #battle { bottom: calc(84px + env(safe-area-inset-bottom)); padding: 6px 10px; }
  .b-row { grid-template-columns: 112px 1fr; }
  .b-row span { font-size: 11px; }
}

/* Tripulación en línea: chat y aviso de conexión */
#crew-line { font-size: 13px; color: var(--muted); }
#chat { top: calc(96px + env(safe-area-inset-top)); left: calc(14px + env(safe-area-inset-left)); display: flex; gap: 4px; padding: 4px; width: min(300px, calc(100vw - 28px)); }
#chat input { flex: 1; min-width: 0; font-size: 15px; padding: 5px 9px; }
#chat button { flex: none; width: 34px; border-radius: 8px; border: 1px solid var(--border); background: rgba(255,255,255,0.04); cursor: pointer; color: var(--gold); }
#chat-log { position: fixed; z-index: 5; top: calc(142px + env(safe-area-inset-top)); left: calc(16px + env(safe-area-inset-left)); width: min(300px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
#chat-log div { font-size: 15px; text-shadow: 0 1px 3px #000, 0 0 6px #000; transition: opacity 1s; }
#chat-log div b { color: #ffd36a; font-family: 'Cinzel', serif; font-size: 13px; }
#chat-log div.out { opacity: 0; }
#net-down { top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 40; padding: 14px 20px; border-color: #ff8a7a; color: #ffd0c8; font-family: 'Cinzel', serif; }
@media (max-width: 720px) {
  #chat { top: calc(78px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); width: min(240px, calc(100vw - 16px)); }
  #chat-log { top: calc(118px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); width: min(240px, calc(100vw - 20px)); }
  #chat-log div { font-size: 13px; }
}

/* Puerto: sin barra de travesía ni combate; el tablón y las tiendas salen como un cartel encima de la plaza */
body.in-port #voyage, body.in-port #battle, body.in-port #btn-map, body.in-port #btn-leave { display: none; }
#intro.over { background: rgba(3, 10, 16, 0.55); backdrop-filter: blur(2px); }
#intro.over .sky, #intro.over .crest, #intro.over h1, #intro.over .lore, #intro.over .features { display: none; }
#intro-close { display: none; position: absolute; top: 12px; right: 12px; z-index: 2; }
#intro.over #intro-close { display: block; }
#tavern { width: min(440px, calc(100vw - 24px)); }
.tav-say { font-size: 17px; font-style: italic; margin: 0 0 10px; }
#tavern h4 { font-family: 'Cinzel', serif; color: var(--gold); font-size: 14px; margin: 8px 0 4px; }
.tav-list { margin: 0; padding-left: 20px; columns: 2; font-size: 15px; }
.arrive-btns { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.arrive-btns button.ghost { align-self: center; }

/* Móvil en vertical: se pide girarlo */
#rotate { display: none; position: fixed; inset: 0; z-index: 100; background: #061219; color: var(--ink); flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 24px; }
#rotate p { font-family: 'Pirata One', 'Cinzel', serif; font-size: 34px; color: var(--gold); margin: 18px 0 0; letter-spacing: 1px; }
#rotate small { color: var(--muted); font-style: italic; font-size: 17px; }
#rotate .phone { width: 46px; height: 78px; border: 3px solid var(--gold); border-radius: 9px; position: relative; animation: turn 2.4s ease-in-out infinite; }
#rotate .phone i { position: absolute; left: 50%; bottom: 5px; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--gold); }
@keyframes turn { 0%, 20% { transform: rotate(0); } 50%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (orientation: portrait) and (pointer: coarse) and (max-width: 900px) { #rotate { display: flex; } }

/* Móvil en horizontal (poca altura): todo más compacto */
@media (max-height: 520px) {
  #ship-title { top: calc(6px + env(safe-area-inset-top)); padding: 4px 10px; }
  #ship-title b { font-size: 17px; }
  #ship-title span { font-size: 12px; }
  #topright { top: calc(6px + env(safe-area-inset-top)); padding: 4px; gap: 4px; }
  #topright button { width: 30px; height: 30px; font-size: 14px; }
  #topright .coins { font-size: 15px; }
  #chat { top: calc(70px + env(safe-area-inset-top)); width: min(240px, 40vw); }
  #chat input { font-size: 14px; padding: 3px 8px; }
  #chat-log { top: calc(108px + env(safe-area-inset-top)); width: min(260px, 40vw); }
  #chat-log div { font-size: 13px; }
  #hint { top: auto; bottom: calc(76px + env(safe-area-inset-bottom)); font-size: 13px; padding: 4px 12px; max-width: min(520px, calc(100vw - 32px)); }
  body.in-port #hint { bottom: calc(14px + env(safe-area-inset-bottom)); }
  #toasts { top: calc(50px + env(safe-area-inset-top)); }
  .toast { font-size: 13px; padding: 5px 12px; }
  #voyage { bottom: calc(6px + env(safe-area-inset-bottom)); padding: 6px 12px; width: min(520px, calc(100vw - 24px)); }
  .bar span { font-size: 10px; }
  #v-status { font-size: 12px; margin-top: 3px; min-height: 14px; }
  #battle { bottom: calc(66px + env(safe-area-inset-bottom)); padding: 4px 10px; gap: 3px; }
  body:has(#battle:not([hidden])) #hint { bottom: calc(124px + env(safe-area-inset-bottom)); }
  .modal { padding: 8px 12px 10px; max-height: calc(100vh - 8px); }
  .m-head { padding-bottom: 5px; margin-bottom: 6px; }
  #puzzle { padding-bottom: 8px; }
  .pz-body { flex-direction: row; align-items: flex-start; gap: 10px; }
  #pz-side { width: 150px; flex-direction: column; gap: 5px; }
  #pz-side .st { padding: 3px 8px; }
  .st b { font-size: 15px; }
  #pz-help { display: none; }
  #pz-title { font-size: 15px; }
  #map-canvas { max-height: 46vh; object-fit: contain; }
  .me-body { align-items: stretch; }
  #me-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
}
@media (max-height: 520px) {
  /* Con un puzle abierto los avisos bajan para no tapar su cabecera */
  body:has(#puzzle:not([hidden])) #toasts { top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); }
}
