/* Base, portada y creador. El mismo aire que Broomwick (tinta de pergamino, oro viejo, paneles oscuros), aquí con agua de mar. */
:root {
  --ink: #f3e9d2;
  --muted: #b3a98d;
  --gold: #e0b75a;
  --sea: #4fb6d9;
  --panel: rgba(8, 20, 28, 0.9);
  --border: rgba(224, 183, 90, 0.42);
}
* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: rgba(224, 183, 90, 0.35) transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #061219; color: var(--ink); font-family: 'Crimson Text', Georgia, serif; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
canvas#game.over { cursor: pointer; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* Portada */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); z-index: 10; }
.sky { position: absolute; inset: 0; overflow: hidden; background: linear-gradient(180deg, #0b1830 0%, #173a52 48%, #0b2a3a 62%, #04131c 100%); }
.stars { position: absolute; inset: 0 0 45% 0; background-image: radial-gradient(1px 1px at 12% 20%, #fff, transparent), radial-gradient(1px 1px at 32% 8%, #fff, transparent), radial-gradient(1.5px 1.5px at 58% 26%, #fff, transparent), radial-gradient(1px 1px at 76% 12%, #fff, transparent), radial-gradient(1px 1px at 88% 30%, #fff, transparent), radial-gradient(1px 1px at 22% 38%, #fff, transparent), radial-gradient(1px 1px at 45% 16%, #fff, transparent); opacity: 0.7; animation: twinkle 5s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: 0.35; } }
.moon { position: absolute; right: 14%; top: 10%; width: 70px; height: 70px; border-radius: 50%; background: radial-gradient(circle at 40% 40%, #fff7da, #e8d9a8 60%, #c9b77e); box-shadow: 0 0 60px rgba(255, 240, 190, 0.45); }
.far-ship { position: absolute; left: 12%; top: 52%; width: 70px; height: 50px; opacity: 0.55; animation: drift 9s ease-in-out infinite;
  background: linear-gradient(#0a1520, #0a1520) 50% 100% / 70px 10px no-repeat, linear-gradient(#0a1520, #0a1520) 30px 0 / 3px 42px no-repeat,
  conic-gradient(from 200deg at 30px 40px, transparent 0 25deg, #0d1c28 25deg 55deg, transparent 55deg) 0 0 / 70px 42px no-repeat; }
@keyframes drift { 50% { transform: translate(8px, 2px) rotate(1deg); } }
.waves { position: absolute; left: -10%; right: -10%; bottom: 0; height: 40%; opacity: 0.55;
  background: repeating-radial-gradient(ellipse 60px 10px at 50% 0, transparent 0 6px, rgba(160, 220, 240, 0.12) 7px 8px, transparent 9px 24px);
  animation: swell 7s ease-in-out infinite; }
.waves.near { height: 26%; opacity: 0.8; animation-duration: 5s; animation-direction: reverse; }
@keyframes swell { 50% { transform: translate(30px, 6px); } }
.card { position: relative; width: min(600px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px; padding: 24px 28px; box-shadow: 0 20px 80px rgba(0,0,0,0.6), inset 0 0 40px rgba(224,183,90,0.05); }
.crest { text-align: center; font-size: 26px; color: var(--gold); text-shadow: 0 0 14px rgba(224,183,90,0.5); }
h1 { font-family: 'Pirata One', 'Cinzel', serif; font-weight: 400; text-align: center; margin: 0 0 8px; color: var(--gold); letter-spacing: 2px; font-size: 52px; line-height: 1; text-shadow: 0 0 18px rgba(224,183,90,0.4); }
h1 small { display: block; font-family: 'Cinzel', serif; font-size: 14px; color: var(--muted); letter-spacing: 6px; margin-top: 4px; }
h3 { font-family: 'Cinzel', serif; color: var(--gold); margin: 0; font-size: 18px; }
.lore { font-style: italic; color: var(--muted); text-align: center; margin: 0 0 18px; font-size: 17px; }
.create { display: flex; gap: 20px; align-items: flex-start; }
.mirror { flex: none; border: 1.5px solid var(--gold); border-radius: 24px 24px 12px 12px; background: radial-gradient(ellipse at 50% 70%, rgba(79,182,217,0.22), rgba(6,16,22,0.9) 75%); box-shadow: 0 0 16px rgba(224,183,90,0.2); }
.mirror canvas { display: block; }
.fields { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
label { font-size: 15px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
input { font: inherit; font-size: 17px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: rgba(0,0,0,0.35); color: var(--ink); outline: none; }
input:focus { border-color: var(--gold); }
.editor { display: flex; flex-direction: column; gap: 6px; }
.erow { display: flex; align-items: center; gap: 8px; }
.erow > span { flex: none; width: 74px; font-size: 14px; color: var(--muted); }
.swatches, .chips { display: flex; gap: 5px; flex-wrap: wrap; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.12); cursor: pointer; padding: 0; }
.swatches button.on { border-color: var(--gold); box-shadow: 0 0 8px var(--gold); }
.chips button { padding: 2px 9px; border-radius: 12px; border: 1px solid var(--border); background: rgba(0,0,0,0.3); cursor: pointer; font-size: 14px; }
.chips button.on { background: rgba(224,183,90,0.22); border-color: var(--gold); color: #ffe9b0; }
button.primary { display: block; width: 100%; margin-top: 18px; font-family: 'Cinzel', serif; font-size: 16px; font-weight: 700; letter-spacing: 1px; padding: 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--gold); background: linear-gradient(180deg, #8a2a22, #5a1814); color: #ffe9b0; box-shadow: 0 4px 16px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.15); }
button.primary:hover { filter: brightness(1.15); }
button.ghost { align-self: flex-start; padding: 4px 12px; border-radius: 8px; border: 1px solid var(--border); background: rgba(255,255,255,0.04); color: var(--muted); cursor: pointer; }
button.ghost:hover { color: var(--ink); }
.error { color: #ff8a7a; text-align: center; margin: 10px 0 0; }
.features { list-style: none; padding: 0; margin: 18px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; font-size: 14px; color: var(--muted); }
.features b { display: block; color: var(--ink); font-family: 'Cinzel', serif; font-size: 13px; }

@media (max-width: 560px) {
  .card { padding: 18px 16px; }
  h1 { font-size: 42px; }
  .create { flex-direction: column; align-items: center; }
  .fields { width: 100%; }
  .features { grid-template-columns: 1fr; }
}

/* Cuenta y tablón */
.loading { text-align: center; color: var(--muted); font-style: italic; padding: 20px 0; animation: twinkle 2s ease-in-out infinite; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; padding: 8px; border-radius: 9px; border: 1px solid var(--border); background: rgba(0,0,0,0.3); cursor: pointer; font-family: 'Cinzel', serif; font-size: 14px; color: var(--muted); }
.tabs button.on { background: rgba(224,183,90,0.2); border-color: var(--gold); color: #ffe9b0; }
.hint { color: var(--muted); font-size: 14px; font-style: italic; text-align: center; margin: 10px 0 0; }
h2 { font-family: 'Cinzel', serif; color: var(--gold); text-align: center; font-size: 19px; margin: 4px 0 0; }
#ship-list { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; max-height: 280px; overflow-y: auto; }
.ship-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-radius: 10px; background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.08); }
.ship-row b { font-family: 'Pirata One', serif; font-weight: 400; font-size: 20px; color: var(--gold); letter-spacing: 0.5px; }
.ship-row small { display: block; color: var(--muted); font-size: 14px; }
.ship-row button { flex: none; padding: 7px 14px; border-radius: 9px; cursor: pointer; font-family: 'Cinzel', serif; font-weight: 700; font-size: 13px; border: 1px solid var(--gold); background: linear-gradient(180deg, #8a2a22, #5a1814); color: #ffe9b0; }
.ship-empty { text-align: center; color: var(--muted); font-style: italic; padding: 14px; border: 1px dashed rgba(224,183,90,0.3); border-radius: 10px; }
.links { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.links button.ghost { align-self: auto; }
.purse { text-align: center; font-family: 'Cinzel', serif; color: #ffd36a; font-size: 15px; margin: 6px 0 0; }

/* Tiendas del puerto */
#shop-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; max-height: 340px; overflow-y: auto; }
.shop-row { display: flex; align-items: center; gap: 10px; padding: 4px 12px 4px 4px; border-radius: 10px; background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.08); }
.shop-row.far { opacity: 0.55; }
.shop-pic { flex: none; width: 64px; height: 76px; border-radius: 8px; background: radial-gradient(circle at 50% 70%, rgba(224,183,90,0.16), transparent 70%); }
.shop-info { flex: 1; min-width: 0; }
.shop-info b { display: block; font-family: 'Cinzel', serif; font-size: 15px; color: var(--ink); }
.shop-info small { display: block; color: var(--muted); font-size: 14px; font-style: italic; }
.shop-row button { flex: none; min-width: 84px; padding: 7px 12px; border-radius: 9px; cursor: pointer; font-family: 'Cinzel', serif; font-weight: 700; font-size: 13px; border: 1px solid var(--gold); background: linear-gradient(180deg, #8a2a22, #5a1814); color: #ffe9b0; }
.shop-row button:disabled { cursor: default; opacity: 0.6; filter: grayscale(0.4); }
.shop-row button.far { background: transparent; border-color: var(--border); color: var(--muted); font-weight: 400; font-size: 12px; }
@media (max-width: 520px) {
  .shop-row { gap: 6px; padding-right: 8px; }
  .shop-pic { width: 48px; height: 57px; }
  .shop-info small { font-size: 12px; }
  .shop-row button { min-width: 0; padding: 6px 8px; }
}

/* Móvil en horizontal: la portada sin adornos para que quepa */
@media (max-height: 520px) {
  .screen { padding: 8px 16px; }
  .card { padding: 12px 20px; max-height: calc(100vh - 16px); }
  .crest, .lore, .features { display: none !important; }
  h1 { font-size: 30px; margin-bottom: 4px; }
  h1 small { font-size: 11px; letter-spacing: 4px; }
  h2 { font-size: 16px; }
  button.primary { margin-top: 10px; padding: 8px; font-size: 14px; }
  .create { flex-direction: row; align-items: flex-start; gap: 14px; }
  .mirror canvas#preview { width: 120px; height: 147px; }
  .erow > span { width: 62px; font-size: 13px; }
  #ship-list { max-height: 34vh; margin-top: 8px; }
  #shop-list { max-height: 44vh; }
  .hint { margin-top: 6px; font-size: 13px; }
  .tabs { margin-bottom: 6px; }
  .tabs button { padding: 5px; }
  .editor { gap: 3px; }
  .fields { gap: 5px; }
  input { font-size: 15px; padding: 5px 10px; }
  .swatches button { width: 20px; height: 20px; }
  .chips button { padding: 1px 8px; font-size: 13px; }
  .shop-pic { width: 48px; height: 57px; }
  .shop-row { padding-top: 2px; padding-bottom: 2px; }
  .purse { font-size: 13px; margin-top: 2px; }
  #shop-note { display: none; }
}
