:root {
  --ink: #06101b;
  --deep: #071827;
  --sea: #0d3448;
  --sea-2: #0f5167;
  --foam: #a8d9d6;
  --gold: #d7a84d;
  --gold-2: #f2d28a;
  --red: #d05a3b;
  --green: #70c191;
  --paper: #f2e0b9;
  --text: #f6ebd0;
  --muted: #b8a985;
  --panel: rgba(6, 16, 27, 0.78);
  --panel-strong: rgba(6, 16, 27, 0.92);
  --line: rgba(242, 210, 138, 0.28);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app,
#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#gameCanvas {
  display: block;
  background:
    radial-gradient(circle at 20% 10%, rgba(91, 155, 161, 0.28), transparent 28%),
    linear-gradient(145deg, #071827 0%, #0b3146 48%, #0d5064 100%);
}

.hidden {
  display: none !important;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: center;
  gap: 44px;
  padding: min(8vw, 96px);
  background:
    linear-gradient(90deg, rgba(6, 16, 27, 0.95), rgba(6, 16, 27, 0.7) 54%, rgba(6, 16, 27, 0.28)),
    radial-gradient(circle at 76% 28%, rgba(215, 168, 77, 0.18), transparent 26%),
    radial-gradient(circle at 78% 72%, rgba(42, 111, 127, 0.5), transparent 34%),
    #071827;
}

.start-screen {
  grid-template-columns: minmax(320px, 680px) minmax(280px, 420px);
}

.start-copy,
.result-card {
  max-width: 720px;
}

.game-mark {
  margin: 0 0 12px;
  color: var(--gold-2);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.2rem, 8vw, 7.4rem);
  line-height: 0.9;
  color: var(--gold-2);
  text-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.subtitle {
  margin: 16px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.2rem, 2vw, 1.8rem);
  color: var(--paper);
}

.intro {
  max-width: 620px;
  color: rgba(246, 235, 208, 0.82);
  font-size: 1.02rem;
  line-height: 1.75;
}

.primary-button {
  min-width: 180px;
  margin-top: 22px;
  border: 1px solid rgba(242, 210, 138, 0.5);
  border-radius: 8px;
  background: linear-gradient(135deg, #bb8132, #f0c66e);
  color: #241405;
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 13px 22px;
  cursor: pointer;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.26);
}

.primary-button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.brief-card,
.result-card,
.modal-box,
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brief-card {
  border-radius: 10px;
  padding: 28px;
}

.brief-card h2,
.modal-box h2 {
  margin: 0 0 16px;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--gold-2);
  font-size: 1.55rem;
}

.brief-card ol {
  margin: 0;
  padding-left: 22px;
  color: rgba(246, 235, 208, 0.82);
  line-height: 1.8;
}

.hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.player-marker {
  position: fixed;
  z-index: 9999;
  left: 50%;
  top: 48%;
  width: 170px;
  height: 170px;
  transform: translate(-50%, -50%) !important;
  pointer-events: none;
}

.player-marker.pinned {
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%) !important;
}

.player-marker-label {
  position: absolute;
  left: 50%;
  top: -42px;
  width: 260px;
  transform: translateX(-50%);
  color: #fff8dc;
  font-size: 22px;
  font-weight: 950;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.9), 0 0 12px rgba(242, 210, 138, 0.7);
}

.player-marker-ring {
  position: absolute;
  inset: 0;
  border: 6px dashed rgba(255, 222, 139, 1);
  border-radius: 50%;
  background: rgba(242, 210, 138, 0.18);
  box-shadow: 0 0 0 5px rgba(6, 16, 27, 0.62), 0 0 54px rgba(242, 210, 138, 0.72);
  animation: markerPulse 1.1s ease-in-out infinite;
}

.player-marker.sailing .player-marker-ring {
  animation-duration: 0.5s;
  box-shadow: 0 0 0 5px rgba(6, 16, 27, 0.62), 0 0 72px rgba(183, 243, 234, 0.7);
}

@keyframes markerPulse {
  0%, 100% { transform: scale(0.94); opacity: 0.82; }
  50% { transform: scale(1.06); opacity: 1; }
}

.player-ship-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 128px;
  height: 92px;
  transform: translate(-50%, -50%);
}

.player-marker.sailing .player-ship-icon {
  animation: shipBob 0.7s ease-in-out infinite;
}

@keyframes shipBob {
  0%, 100% { transform: translate(-50%, -50%) rotate(-2deg); }
  50% { transform: translate(-50%, calc(-50% - 5px)) rotate(2deg); }
}

.player-ship-icon::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 58px;
  width: 110px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.34);
}

.ship-hull {
  position: absolute;
  left: 7px;
  top: 50px;
  width: 116px;
  height: 34px;
  background: #b24c2e;
  border: 5px solid #ffd98d;
  border-radius: 70% 70% 42% 42%;
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.25);
}

.ship-sail {
  position: absolute;
  left: 58px;
  top: 0;
  width: 56px;
  height: 72px;
  background: #fff0c8;
  border: 5px solid #5d321c;
  clip-path: polygon(0 0, 100% 48%, 0 100%);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.28));
}

.panel {
  position: fixed;
  border-radius: 8px;
  padding: 14px;
}

.panel-title {
  margin-bottom: 10px;
  color: var(--gold-2);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-weight: 700;
}

.top-left {
  top: 18px;
  left: 18px;
  width: 290px;
}

.top-right {
  top: 18px;
  right: 18px;
  width: min(360px, calc(100vw - 360px));
}

.enemy-panel {
  top: 178px;
  right: 18px;
  width: min(360px, calc(100vw - 360px));
}

.bottom-left {
  left: 18px;
  bottom: 18px;
}

.bottom-center {
  position: fixed;
  left: 50%;
  bottom: 18px;
  width: min(620px, calc(100vw - 420px));
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 16, 27, 0.72);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.bar-row {
  display: grid;
  grid-template-columns: 42px 1fr 44px;
  align-items: center;
  gap: 9px;
  margin: 8px 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.bar-row b {
  color: var(--text);
  font-size: 0.78rem;
  text-align: right;
}

.bar {
  height: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), #f2a15c);
  transition: width 0.16s linear;
}

.bar:nth-of-type(2) i,
#playerSailBar,
#enemySailBar {
  background: linear-gradient(90deg, #4bbbd2, #b7f3ea);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stat-grid div {
  border: 1px solid rgba(242, 210, 138, 0.18);
  border-radius: 6px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.stat-grid span,
.wind-readout span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.stat-grid b,
.wind-readout b {
  color: var(--text);
  font-size: 0.95rem;
}

.objective-panel p {
  margin: 0;
  color: rgba(246, 235, 208, 0.88);
  line-height: 1.5;
}

.stage-text {
  display: inline-block;
  margin-top: 10px;
  border: 1px solid rgba(112, 193, 145, 0.36);
  border-radius: 999px;
  background: rgba(112, 193, 145, 0.12);
  color: #d9ffe8;
  padding: 5px 10px;
  font-size: 0.76rem;
  font-weight: 850;
}

.wind-readout {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(242, 210, 138, 0.16);
}

#windArrow {
  display: block;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(242, 210, 138, 0.35);
  border-radius: 50%;
  position: relative;
}

#windArrow::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 5px;
  width: 3px;
  height: 20px;
  border-radius: 999px;
  background: var(--gold-2);
}

#windArrow::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 4px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 8px solid var(--gold-2);
}

.controls-panel {
  display: grid;
  gap: 7px;
  color: rgba(246, 235, 208, 0.78);
  font-size: 0.82rem;
  pointer-events: auto;
}

kbd {
  display: inline-grid;
  min-width: 24px;
  height: 22px;
  margin: 0 2px;
  place-items: center;
  border: 1px solid rgba(242, 210, 138, 0.35);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--gold-2);
  font-size: 0.72rem;
  font-weight: 800;
}

.control-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(242, 210, 138, 0.16);
}

.control-buttons button {
  border: 1px solid rgba(242, 210, 138, 0.28);
  border-radius: 6px;
  background: rgba(242, 210, 138, 0.12);
  color: var(--paper);
  padding: 8px 9px;
  font-size: 0.78rem;
  font-weight: 850;
  cursor: pointer;
}

.control-buttons button:hover,
.control-buttons button:active {
  border-color: rgba(242, 210, 138, 0.72);
  background: rgba(242, 210, 138, 0.24);
}

#btnAutoSail {
  grid-column: 1 / -1;
}

#btnInteract {
  border-color: rgba(112, 193, 145, 0.42);
  background: rgba(112, 193, 145, 0.14);
}

#btnFireLeft,
#btnFireRight {
  border-color: rgba(208, 90, 59, 0.42);
  background: rgba(208, 90, 59, 0.14);
}

#btnAmmoSolid,
#btnAmmoChain,
#btnKickAttack,
#btnRallyCrew {
  border-color: rgba(183, 243, 234, 0.34);
  background: rgba(183, 243, 234, 0.1);
}

#btnKickAttack {
  border-color: rgba(112, 193, 145, 0.42);
  background: rgba(112, 193, 145, 0.12);
}

#btnRallyCrew {
  border-color: rgba(242, 210, 138, 0.45);
  background: rgba(242, 210, 138, 0.14);
}

#messageLog {
  min-height: 20px;
  color: var(--paper);
  font-size: 0.94rem;
  line-height: 1.5;
  text-align: center;
}

.small-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 8, 14, 0.62);
}

.modal-box {
  width: min(560px, 100%);
  border-radius: 10px;
  padding: 28px;
}

.modal-box p {
  margin: 0;
  color: rgba(246, 235, 208, 0.84);
  line-height: 1.65;
  white-space: pre-line;
}

.choice-actions {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.choice-actions button {
  width: 100%;
  border: 1px solid rgba(242, 210, 138, 0.28);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
}

.choice-actions button:hover {
  border-color: rgba(242, 210, 138, 0.62);
  background: rgba(215, 168, 77, 0.18);
}

.modal-secondary {
  width: 100%;
  margin-top: 10px;
  border: 1px solid rgba(112, 193, 145, 0.45);
  border-radius: 7px;
  background: rgba(112, 193, 145, 0.14);
  color: #d9ffe8;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 900;
}

.modal-secondary:hover {
  background: rgba(112, 193, 145, 0.24);
}

.result-screen {
  grid-template-columns: minmax(320px, 760px);
  justify-content: center;
}

.result-card {
  border-radius: 12px;
  padding: clamp(28px, 5vw, 54px);
}

.result-card h1 {
  font-size: clamp(2.2rem, 5vw, 4.8rem);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 22px;
}

.result-stats div {
  border: 1px solid rgba(242, 210, 138, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 12px;
}

.result-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.result-stats b {
  color: var(--paper);
}

@media (max-width: 860px) {
  .start-screen {
    grid-template-columns: 1fr;
    align-content: center;
    overflow: auto;
  }

  .brief-card {
    display: none;
  }

  .top-left,
  .top-right,
  .enemy-panel {
    width: calc(100vw - 24px);
    left: 12px;
    right: auto;
  }

  .top-left {
    top: 12px;
  }

  .top-right {
    top: 184px;
  }

  .enemy-panel {
    top: 310px;
  }

  .controls-panel {
    display: none;
  }

  .bottom-center {
    width: calc(100vw - 24px);
    left: 12px;
    transform: none;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }
}
