:root {
  color-scheme: dark;
  --ink: #f5f7ec;
  --muted: rgba(245, 247, 236, 0.68);
  --panel: rgba(8, 17, 20, 0.84);
  --panel-strong: rgba(8, 17, 20, 0.95);
  --line: rgba(255, 255, 255, 0.18);
  --accent: #f2c85b;
  --accent-2: #44d4ca;
  --accent-boat: #f2c85b;
  --danger: #ff6f61;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body,
#game,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
}

html,
body {
  overflow: hidden;
  width: 100vw;
  max-width: 100vw;
  background: #071014;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  -webkit-user-select: none; /* Safari */
  -ms-user-select: none;      /* IE 10 y 11 */
  user-select: none;          /* Estándar (Chrome, Firefox, Edge) */
}

button {
  color: inherit;
  font: inherit;
}

#game {
  position: fixed;
  inset: 0;
}

#map {
  z-index: 0;
  background: #081215;
}

.leaflet-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: #081215;
  font-family: inherit;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-map-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  user-select: none;
}

.leaflet-map-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  border: 0;
  max-width: none;
}

.leaflet-tile-container {
  pointer-events: none;
}

.leaflet-control-attribution {
  margin: 0;
  padding: 2px 6px;
  max-width: min(74vw, 540px);
  background: rgba(4, 11, 13, 0.72);
  color: rgba(245, 247, 236, 0.62);
  font-size: 9px;
  line-height: 1.2;
}

.hud {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  z-index: 520;
  height: 42px;
  padding: 4px;
  display: grid;
  grid-template-columns: 34px minmax(44px, 0.9fr) auto 58px auto minmax(48px, 0.8fr);
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.hud-top {
  top: max(12px, env(safe-area-inset-top));
}

.readout,
.gps,
.dock-panel,
.fleet-panel,
.toast,
.start-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.readout {
  min-width: 0;
  height: 32px;
  padding: 4px 8px;
  display: grid;
  align-content: center;
  justify-items: center;
  pointer-events: auto;
}

.readout span,
.readout strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0;
}

.readout span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
}

.readout strong {
  font-size: 15px;
  line-height: 1.05;
}

.hud-boat,
.hud-zone,
.hud-money {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-boat,
.hud-zone {
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.hud-money {
  color: var(--accent);
  font-size: 12px;
  text-align: right;
}

.hud-meter {
  height: 8px;
  min-width: 44px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
}

.hud-meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--danger), var(--accent), var(--accent-2));
}

.icon-button,
.tiny-button,
.dock-actions button,
.fleet-card,
.mission-card,
.start-actions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 18, 21, 0.86);
}

.icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.icon-button:active,
.dock-actions button:active,
.fleet-card:active,
.mission-card:active,
.start-actions button:active {
  transform: translateY(1px) scale(0.99);
}

.icon-button.is-on {
  color: var(--accent);
}

.cargo-strip {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  right: max(150px, env(safe-area-inset-right));
  top: calc(max(12px, env(safe-area-inset-top)) + 48px);
  z-index: 520;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 17, 20, 0.72);
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 430px) {
  .cargo-strip {
    max-width: 210px;
  }
}

.gps {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  top: calc(max(12px, env(safe-area-inset-top)) + 60px);
  z-index: 520;
  width: 112px;
  padding: 8px;
  display: grid;
  justify-items: center;
  gap: 2px;
  opacity: 0.72;
  color: inherit;
  cursor: pointer;
}

.gps.is-active {
  opacity: 1;
  border-color: rgba(242, 200, 91, 0.52);
}

.gps span {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
  transform-origin: 50% 50%;
}

.gps small {
  max-width: 96px;
  color: var(--muted);
  font-size: 10px;
}

.gps:active {
  transform: translateY(1px) scale(0.98);
}

.boat-layer {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 450;
  width: 150px;
  height: 150px;
  margin: -75px 0 0 -75px;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.boat-sprite {
  width: calc(78px * var(--boat-scale, 1));
  height: calc(78px * var(--boat-scale, 1));
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 9px 3px rgba(0, 0, 0, 0.42));
  transform-origin: 50% 50%;
}

.boat-layer.is-sailing .boat-sprite {
  animation: none;
}

.wake {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 34px;
  margin: 20px 0 0 -10px;
  border-radius: 50%;
  border: 2px solid rgba(180, 245, 255, 0.62);
  border-top: 0;
  opacity: 0;
  transform-origin: 50% -18px;
}

.boat-layer.is-sailing .wake {
  animation: wake 1100ms ease-out infinite;
}

.controls-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 540;
  min-height: 218px;
  padding: 12px max(18px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 72px minmax(150px, 190px);
  justify-content: center;
  align-items: end;
  gap: 18px;
  pointer-events: none;
}

.helm-wrap {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.helm-data {
  width: min(190px, 46vw);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.helm {
  position: relative;
  width: min(46vw, 184px);
  min-width: 148px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  touch-action: none;
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
}

.helm-rim {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(35, 76, 74, 0.95) 0 23%, transparent 24%),
    radial-gradient(circle at 50% 50%, transparent 0 51%, rgba(88, 52, 23, 0.98) 52% 65%, #2a170d 66% 71%, transparent 72%),
    radial-gradient(circle at 50% 50%, rgba(6, 20, 22, 0.92), rgba(6, 20, 22, 0.2));
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.55), inset 0 0 0 8px rgba(255, 255, 255, 0.04);
  transition: box-shadow 160ms ease, scale 160ms ease, filter 160ms ease;
}

.helm::before {
  content: "";
  position: absolute;
  width: min(54vw, 216px);
  min-width: 176px;
  aspect-ratio: 1;
  border-radius: 50%;
}

.helm::after {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  width: 3px;
  height: 18px;
  border-radius: 999px;
  background: var(--accent-2);
  box-shadow: 0 0 12px rgba(68, 212, 202, 0.62);
  transform: translateX(-50%);
  opacity: 0.82;
}

.helm.is-steering .helm-rim {
  scale: 1.035;
  filter: saturate(1.14);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.62), 0 0 0 5px rgba(68, 212, 202, 0.12), inset 0 0 0 8px rgba(255, 255, 255, 0.06);
}

.helm-rim > span,
.helm-wheel > i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12%;
  height: 84%;
  margin-left: -6%;
  margin-top: -42%;
  border-radius: 999px;
  background: linear-gradient(#a26d32, #4f2a12);
  transform-origin: 50% 50%;
}

.helm-rim > span:nth-child(2),
.helm-wheel > i:nth-child(2) {
  transform: rotate(45deg);
}

.helm-rim > span:nth-child(3),
.helm-wheel > i:nth-child(3) {
  transform: rotate(90deg);
}

.helm-rim > span:nth-child(4),
.helm-wheel > i:nth-child(4) {
  transform: rotate(135deg);
}

.helm-wheel {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  transition: transform 120ms cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}

.helm-wheel b {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28%;
  aspect-ratio: 1;
  margin: -14% 0 0 -14%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f7ce6a, #946221 64%, #3b210e 65%);
}

.throttle-wrap {
  align-self: end;
  width: 72px;
  height: 184px;
  display: grid;
  grid-template-rows: 14px 1fr 14px;
  justify-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0;
  pointer-events: none;
}

.throttle {
  position: relative;
  width: 48px;
  height: 146px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 17, 20, 0.88);
  box-shadow: var(--shadow);
  touch-action: none;
  pointer-events: auto;
}

.throttle-track {
  position: absolute;
  left: 50%;
  top: 10px;
  bottom: 10px;
  width: 8px;
  margin-left: -4px;
  border-radius: 999px;
  background: linear-gradient(var(--accent-2), rgba(255, 255, 255, 0.18) 50%, var(--danger));
}

.throttle em {
  position: absolute;
  left: 7px;
  right: 7px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: rgba(245, 247, 236, 0.5);
}

.throttle-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 22px;
  margin: -11px 0 0 -17px;
  border-radius: 8px;
  background: linear-gradient(#f2c85b, #8f5d1f);
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

.dock-panel,
.fleet-panel {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  z-index: 560;
  padding: 10px;
  display: none;
  gap: 9px;
}

.dock-panel.is-open,
.fleet-panel.is-open {
  display: grid;
}

.dock-panel {
  bottom: calc(224px + env(safe-area-inset-bottom));
}

.fleet-panel {
  top: calc(max(12px, env(safe-area-inset-top)) + 118px);
}

.dock-panel header,
.fleet-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
}

.tiny-button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.dock-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.dock-actions button {
  min-height: 38px;
  color: var(--ink);
}

.missions-list {
  display: none;
  gap: 7px;
}

.missions-list.is-open {
  display: grid;
}

.missions-list p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.mission-card,
.fleet-card {
  min-width: 0;
  padding: 9px;
  color: var(--ink);
  text-align: left;
}

.mission-card {
  display: grid;
  gap: 3px;
}

.mission-card span,
.fleet-card small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.fleet-list {
  display: grid;
  gap: 8px;
  max-height: min(48vh, 420px);
  overflow: auto;
}

.fleet-card {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 9px;
}

.fleet-card.is-selected {
  border-color: var(--accent-boat);
}

.fleet-card img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  image-rendering: pixelated;
}

.fleet-card span {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.fleet-card strong,
.fleet-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.start-modal {
  position: fixed;
  inset: 0;
  width: 100vw;
  max-width: 100vw;
  z-index: 900;
  display: block;
  overflow: hidden;
  padding: 22px;
  background: radial-gradient(circle at 50% 32%, rgba(68, 212, 202, 0.16), transparent 38%), rgba(3, 9, 11, 0.82);
}

.gps-modal {
  position: fixed;
  inset: 0;
  z-index: 880;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 9, 11, 0.68);
}

.gps-modal.is-hidden {
  display: none;
}

.gps-box {
  width: min(430px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.gps-box header {
  height: 44px;
  padding: 7px 9px 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
}

.gps-map {
  width: 100%;
  height: min(58vh, 390px);
  min-height: 260px;
  background: #081215;
}

.gps-box > small {
  display: block;
  padding: 9px 12px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.start-modal.is-hidden {
  display: none;
}

.start-box {
  position: absolute;
  left: 22px;
  right: 22px;
  top: 50%;
  width: 310px;
  max-width: calc(100vw - 44px);
  padding: 18px;
  display: grid;
  gap: 14px;
  text-align: center;
  transform: translateY(-50%);
}

.start-box h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: 0;
}

.start-box p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.start-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.start-actions button {
  min-height: 42px;
  min-width: 0;
  padding: 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.start-actions button:disabled {
  opacity: 0.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(224px + env(safe-area-inset-bottom));
  z-index: 640;
  max-width: min(84vw, 360px);
  padding: 10px 12px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes bob {
  0%, 100% {
    translate: 0 -2px;
  }
  50% {
    translate: 0 2px;
  }
}

@keyframes wake {
  0% {
    opacity: 0.55;
    scale: 0.7;
    translate: 0 0;
  }
  100% {
    opacity: 0;
    scale: 1.8;
    translate: 0 20px;
  }
}

@media (min-width: 760px) {
  .hud {
    left: 24px;
    right: auto;
    width: 520px;
  }

  .cargo-strip {
    left: 24px;
    right: auto;
    width: 360px;
  }

  .gps {
    right: 24px;
  }

  .controls-panel {
    left: 50%;
    right: auto;
    width: 430px;
    margin-left: -215px;
    border-radius: 24px 24px 0 0;
  }

  .dock-panel,
  .fleet-panel {
    left: 24px;
    right: auto;
    width: 360px;
  }

  .start-box {
    left: 50%;
    right: auto;
    width: 380px;
    max-width: calc(100vw - 44px);
    transform: translate(-50%, -50%);
  }
}

@media (max-height: 720px) {
  .controls-panel {
    min-height: 184px;
    grid-template-columns: 60px minmax(132px, 158px);
  }

  .helm {
    width: min(38vw, 148px);
    min-width: 126px;
  }

  .throttle-wrap {
    height: 158px;
  }

  .throttle {
    height: 122px;
  }

  .dock-panel,
  .toast {
    bottom: calc(188px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 360px) {
  .start-actions {
    grid-template-columns: 1fr;
  }
}
