* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: #0b1020; }
body {
  font-family: "Courier New", Courier, monospace;
  color: #fff;
  display: flex; justify-content: center; align-items: flex-start;
  min-height: 100vh; padding: 10px;
}
#game-wrap {
  position: relative; width: 100%; max-width: 960px;
  border: 4px solid #000; outline: 3px solid #75aadb;
  background: #1a6fb5; overflow: hidden;
  box-shadow: 0 0 0 4px #0b1020, 0 10px 40px rgba(0,0,0,.6);
}
canvas#race { display: block; width: 100%; height: auto; image-rendering: pixelated; background: #7ec8f7; }
.screen {
  position: absolute; inset: 0; display: flex; justify-content: center; align-items: center;
  background: rgba(6, 20, 50, .88); padding: 16px; overflow-y: auto;
}
.hidden { display: none !important; }
.panel {
  background: #101d3a; border: 4px solid #75aadb; padding: 20px; width: 100%; max-width: 560px;
  text-align: center; box-shadow: 6px 6px 0 #000;
}
.panel.wide { max-width: 880px; }
.title-box { text-align: center; max-width: 680px; }
.title-brand {
  font-weight: bold; letter-spacing: 3px; color: #bfe3ff; font-size: 15px; margin-bottom: 8px;
}
h1.arcade {
  font-size: clamp(38px, 8vw, 66px); line-height: 1; margin: 0;
  color: #ffb300; text-shadow: 3px 3px 0 #b71c1c, 6px 6px 0 #000; letter-spacing: 1px;
}
h1.arcade.blue { color: #eaf6ff; text-shadow: 3px 3px 0 #1a6fb5, 6px 6px 0 #000; margin-top: 4px; }
h2 { font-size: clamp(20px, 4vw, 30px); margin: 0 0 16px; color: #ffd75e; text-shadow: 3px 3px 0 #000; letter-spacing: 1px; }
.subtitle { font-weight: bold; letter-spacing: 2px; margin: 10px 0 2px; color: #fff; font-size: 20px; }
.subtitle.small { font-size: 15px; color: #bfe3ff; margin-top: 2px; }
.disclaimer { font-size: 12px; color: #c9d6e8; line-height: 1.5; margin-top: 14px; }
.menu-buttons { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.menu-buttons button, button.back, #hud-buttons button {
  font-family: inherit; font-weight: bold; cursor: pointer;
  border: 3px solid #000; box-shadow: 4px 4px 0 #000; text-transform: uppercase;
}
.menu-buttons button {
  font-size: clamp(16px, 3vw, 22px); padding: 13px 18px;
  background: #75aadb; color: #06142e;
}
.menu-buttons button:hover, .menu-buttons button:active { background: #a5d0f5; }
.menu-buttons button.gold { background: #ffd75e; color: #3a2700; }
.menu-buttons button.gold:hover { background: #ffe89a; }
button.back { background: #26314f; color: #fff; padding: 10px 18px; font-size: 15px; margin-top: 8px; }
.how-text { text-align: left; line-height: 1.65; font-size: 15px; color: #dce9f7; }
.how-text b { color: #ffd75e; }
/* Tarjetas de categoría (como la foto: 4 en fila) */
.category-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.cat-card {
  background: #0b1a38; border: 3px solid #3a5a8c; padding: 14px 6px; cursor: pointer;
}
.cat-card:hover, .cat-card:active { border-color: #ffd75e; background: #122549; }
.cat-card .boat-icons { font-size: 30px; letter-spacing: 1px; }
.cat-card .cat-name { font-weight: bold; font-size: 17px; margin-top: 8px; line-height: 1.3; }
/* Tira de embarcaciones (como la foto) */
.crew-strip {
  display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 14px; margin-bottom: 12px;
  scroll-snap-type: x proximity;
}
.crew-card {
  flex: 0 0 200px; background: #0b1a38; border: 3px solid #3a5a8c; padding: 12px; cursor: pointer;
  text-align: center; scroll-snap-align: start; position: relative;
}
.crew-card:hover, .crew-card:active { border-color: #ffd75e; }
.crew-card.featured { border-color: #ffd75e; box-shadow: 0 0 0 2px #ffd75e inset; }
.crew-card .tag {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: #ffd75e; color: #3a2700; font-size: 10px; font-weight: bold; padding: 2px 8px; white-space: nowrap;
}
.crew-card .faces { display: block; margin: 6px auto 2px; image-rendering: pixelated; background: #7ec8f7; border: 2px solid #000; }
.crew-card .flag { font-size: 26px; margin-top: 6px; }
.crew-card .names { font-weight: bold; font-size: 14px; line-height: 1.35; margin: 4px 0 2px; min-height: 38px; }
.crew-card .meta { font-size: 12px; color: #9fb9dd; line-height: 1.4; }
.crew-card .note { font-size: 11px; color: #ffd75e; margin-top: 6px; line-height: 1.4; }
/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
#race-top { padding-right: 150px !important;
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: stretch;
  background: rgba(6, 20, 50, .88); border-bottom: 3px solid #000; padding: 8px 12px; font-weight: bold;
}
#hud-pos { font-size: clamp(18px, 3.4vw, 26px); color: #fff; display: flex; align-items: center; }
#hud-pos b { color: #ffd75e; font-size: 1.4em; margin: 0 2px; }
#hud-center { text-align: center; }
#hud-lap { font-size: clamp(16px, 3vw, 22px); color: #ffd75e; letter-spacing: 1px; }
#hud-dist { font-size: 13px; color: #bfe3ff; margin-top: 2px; }
#hud-time { font-size: clamp(16px, 3vw, 22px); display: flex; align-items: center; }
#hud-time b { color: #ffd75e; margin-left: 6px; }
#commentary {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  background: #b71c1c; border: 3px solid #000; box-shadow: 4px 4px 0 #000;
  color: #fff; font-weight: bold; font-size: clamp(13px, 2.4vw, 20px);
  padding: 7px 14px; text-align: center; max-width: 92%; letter-spacing: 1px; z-index: 2;
}
#standings {
  position: absolute; top: 118px; left: 10px; background: rgba(6, 20, 50, .88);
  border: 3px solid #000; padding: 8px 10px; font-size: 13px; line-height: 1.65; min-width: 196px;
}
#standings .head { color: #ffd75e; font-weight: bold; letter-spacing: 1px; margin-bottom: 2px; }
#standings .me { color: #ffd75e; font-weight: bold; }
#hud-right {
  position: absolute; top: 118px; right: 10px; background: rgba(6, 20, 50, .88);
  border: 3px solid #000; padding: 8px; width: 236px;
}
#minimap { display: block; width: 100%; height: auto; background: #0b1a38; border: 2px solid #000; image-rendering: pixelated; }
.bar-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 11px; font-weight: bold; }
.bar-row span { width: 78px; }
.bar { flex: 1; height: 14px; background: #26314f; border: 2px solid #000; overflow: hidden; }
.bar .fill { height: 100%; transition: width .15s; }
.bar .fill.green { background: #4caf50; }
.bar .fill.blue { background: #2196f3; }
.bar .fill.red { background: #e53935; }
#hud-buttons {
  position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; gap: 8px; align-items: flex-end; justify-content: space-between;
}
#hud-mid { display: flex; gap: 8px; align-items: center; }
#hud-buttons button { font-size: 15px; padding: 12px 14px; touch-action: manipulation; }
#hud-buttons button.paddle { font-size: 19px; line-height: 1.25; padding: 24px 22px; min-width: 170px; background: #ffd75e; color: #3a2700; user-select: none; -webkit-user-select: none; }
#btn-sprint { background: #e53935; color: #fff; }
#btn-portage { background: #2e7d32; color: #fff; }
#btn-portage:disabled { opacity: .45; }
#btn-mute { background: #26314f; color: #fff; padding: 13px 14px; }
#hud-buttons button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #000; }
#hud-spm { text-align: center; font-weight: bold; font-size: 13px; color: #bfe3ff; padding: 6px 0 2px; line-height: 1.2; }
#hud-spm b { font-size: 30px; color: #7dff8a; }
#hud-spm small { font-size: 11px; color: #9fb9dd; }
.bar .fill.gold { background: #ffd75e; }
#countdown {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  font-size: clamp(70px, 18vw, 150px); font-weight: bold; color: #ffd75e;
  text-shadow: 6px 6px 0 #000; pointer-events: none;
}
#podium { display: flex; justify-content: center; gap: 12px; margin: 6px 0 16px; flex-wrap: wrap; }
.podium-place {
  background: #0b1a38; border: 3px solid #3a5a8c; padding: 12px; min-width: 150px; text-align: center;
}
.podium-place.first { border-color: #ffd75e; }
.podium-place .medal { font-size: 34px; }
.podium-place .names { font-weight: bold; font-size: 14px; margin-top: 6px; line-height: 1.3; }
.podium-place .time { color: #9fb9dd; font-size: 13px; margin-top: 4px; }
#classification { text-align: left; font-size: 15px; line-height: 1.9; background: #0b1a38; border: 3px solid #3a5a8c; padding: 12px 16px; margin-bottom: 10px; }
#classification .me { color: #ffd75e; font-weight: bold; }
/* compacto (juego chico en pantalla) */
body.compact .category-cards { grid-template-columns: repeat(2, 1fr); }
body.compact #standings { font-size: 11px; min-width: 150px; top: 110px; }
body.compact #hud-right { width: 172px; top: 110px; }
body.compact .bar-row span { width: 60px; font-size: 10px; }
body.compact #hud-buttons button { font-size: 12px; padding: 9px 7px; }
body.compact #hud-buttons button.paddle { font-size: 13px; padding: 16px 8px; min-width: 96px; }
body.compact #hud-mid { position: absolute; right: 0; bottom: 62px; flex-direction: column; gap: 4px; align-items: flex-end; }
body.compact #hud-spm b { font-size: 22px; }
body.compact #standings { display: none; }
body.compact #minimap { display: none; }
body.compact #commentary { top: 58px; font-size: 12px; padding: 5px 10px; }
body.compact #hud-right { top: 98px; left: 6px; right: auto; width: auto; padding: 3px 8px; }
body.compact #hud-right .bar-row { display: none; }
body.compact #hud-spm small { font-size: 9px; }
body.compact #hud-buttons { left: 6px; right: 6px; bottom: 6px; }
body.compact #hud-buttons button { font-size: 10px; padding: 6px 5px; }
body.compact #hud-buttons button.paddle { font-size: 11px; padding: 14px 6px; min-width: 80px; opacity: .88; }

/* Botones del sistema (pantalla completa / salir) */
#sys-buttons { position: absolute; top: 8px; right: 8px; z-index: 30; display: flex; gap: 6px; }
#sys-buttons button {
  font-family: inherit; font-weight: bold; font-size: 14px; color: #fff; background: #26314f;
  border: 3px solid #000; box-shadow: 3px 3px 0 #000; padding: 6px 10px; cursor: pointer; min-width: 38px;
}
#sys-buttons button#btn-exit { background: #b71c1c; }
#sys-buttons button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
/* Pantalla completa: el juego ocupa todo el alto/ancho manteniendo 3:2 */
body.is-fs { padding: 0; align-items: center; min-height: 100vh; height: 100vh; overflow: hidden; }
body.is-fs #game-wrap { max-width: min(100vw, calc((100vh - 8px) * var(--ar, 1.5))); border-width: 2px; outline: none; box-shadow: none; }
#game-wrap:fullscreen, #game-wrap:-webkit-full-screen { max-width: none; width: min(100vw, calc(100vh * var(--ar, 1.5))); background: #000; }
/* compacto (juego chico en pantalla) */
body.compact #race-top { padding-right: 112px !important; }
body.compact #sys-buttons { top: 6px; right: 6px; gap: 4px; }
body.compact #sys-buttons button { font-size: 11px; padding: 4px 6px; min-width: 30px; }

/* Puntaje y compartir */
#score-box { background: #0b1a38; border: 3px solid #ffd75e; padding: 12px 14px; margin-bottom: 10px; text-align: center; }
#score-line { font-weight: bold; font-size: 18px; color: #fff; letter-spacing: 1px; }
#score-line b { color: #ffd75e; font-size: 34px; margin: 0 6px; }
#score-line small { display: block; font-size: 12px; color: #9fb9dd; font-weight: normal; letter-spacing: 0; margin-top: 2px; }
#score-box label { display: block; font-size: 12px; color: #bfe3ff; margin: 10px 0 4px; letter-spacing: 2px; font-weight: bold; }
#player-name {
  width: 100%; max-width: 360px; font-family: inherit; font-size: 18px; font-weight: bold; text-align: center;
  padding: 8px 10px; background: #fff; color: #101d3a; border: 3px solid #000; outline: none;
}
#player-name:focus { border-color: #ffd75e; }
#player-name.need { animation: shake .35s; border-color: #e53935; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
#share-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
#share-row button {
  font-family: inherit; font-weight: bold; font-size: 14px; padding: 10px 14px; cursor: pointer;
  border: 3px solid #000; box-shadow: 3px 3px 0 #000; color: #fff; background: #2196f3;
}
#btn-wa { background: #25a244 !important; }
#btn-copy { background: #26314f !important; }
#share-row button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
#share-msg { min-height: 18px; margin-top: 8px; font-size: 13px; color: #7dff8a; font-weight: bold; }
#best-line { font-size: 12px; color: #9fb9dd; }

/* ---- Responsive ---- */
html, body { max-width: 100%; overflow-x: hidden; }
/* compacto (juego chico en pantalla) */
body.compact body { padding: 0; }
body.compact #game-wrap { border-width: 2px; outline-width: 2px; box-shadow: none; }
body.compact .screen { padding: 8px; align-items: flex-start; }
body.compact .panel { padding: 12px; box-shadow: 4px 4px 0 #000; margin: auto; }
body.compact h1.arcade { font-size: clamp(28px, 10vw, 44px); }
body.compact .subtitle { font-size: 16px; }
body.compact .subtitle.small { font-size: 12px; }
body.compact .menu-buttons { margin: 10px 0; gap: 8px; }
body.compact .menu-buttons button, body.compact button.back { font-size: 15px; padding: 11px 10px; }
body.compact .how-text { font-size: 13px; line-height: 1.45; }
body.compact .crew-card { flex-basis: 150px; padding: 8px; }
body.compact .crew-card .names { font-size: 12px; min-height: 32px; }
body.compact .crew-card .note { font-size: 10px; }
body.compact #podium { gap: 6px; }
body.compact .podium-place { min-width: 0; flex: 1 1 90px; padding: 8px; }
body.compact .podium-place .names { font-size: 12px; }
body.compact .podium-place .medal { font-size: 26px; }
body.compact #classification { font-size: 12px; line-height: 1.7; padding: 8px 10px; }
body.compact #score-line { font-size: 15px; }
body.compact #score-line b { font-size: 28px; }
body.compact #share-row button { flex: 1 1 100px; font-size: 12px; padding: 9px 6px; }
body.compact #player-name { font-size: 16px; }
/* Celular en horizontal (poca altura): HUD compacto */

/* compacto (juego chico en pantalla) */
body.compact #race-top { padding-top: 5px !important; padding-bottom: 5px !important; padding-left: 8px !important; }
body.compact #hud-pos { font-size: 16px; }
body.compact #hud-pos b { font-size: 1.25em; }
body.compact #hud-lap { font-size: 13px; letter-spacing: 0; white-space: nowrap; }
body.compact #hud-dist { font-size: 10px; white-space: nowrap; }
body.compact #hud-time { font-size: 13px; white-space: nowrap; }
body.compact #hud-time b { margin-left: 3px; }
body.compact #commentary { top: 52px; }
/* El juego siempre entra completo en la altura disponible (celular horizontal, ventanas bajas) */
body { align-items: center; }
#game-wrap { max-width: min(960px, calc((100vh - 28px) * var(--ar, 1.5))); margin: 0 auto; }
body.in-iframe { padding: 0; min-height: 0; }
body.in-iframe #game-wrap { max-width: min(960px, calc((100vh - 8px) * var(--ar, 1.5))); }
/* compacto (juego chico en pantalla) */
body.compact #game-wrap { max-width: min(960px, calc((100vh - 4px) * var(--ar, 1.5))); }

/* Modo juego en teléfono: ocupa toda la pantalla, sin marcos */
body.expanded { padding: 0; background: #000; min-height: 100vh; min-height: 100dvh; overflow: hidden; }
body.expanded #game-wrap { border-width: 0; outline: none; box-shadow: none; }
body.expanded #sys-buttons button, body.compact #sys-buttons button { touch-action: manipulation; }
body.rot { overflow: hidden; }
#hud-buttons button, #btn-exit, #btn-fs { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.compact #hud-buttons button.paddle { min-width: 0; width: 22vmax; max-width: 150px; }
html:fullscreen, html:-webkit-full-screen { background: #000; }
