:root {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #f5f7ed;
  background: #0b3443;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button, input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible, input:focus-visible {
  outline: 3px solid #f6d886;
  outline-offset: 3px;
}

.is-hidden {
  display: none !important;
}

#world {
  display: block;
  width: 100vw;
  height: 100dvh;
  touch-action: none;
  background: linear-gradient(#8ccdd5, #b8e8e0);
}

.game-ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.game-ui button,
.game-ui input,
.joystick {
  pointer-events: auto;
}

/* Glassmorphism Surface Base */
.hud-pill,
.icon-button,
.wind-card,
.action-button,
.sail-control,
.camp-scene,
.modal-card {
  background: linear-gradient(140deg, rgba(8, 46, 60, 0.88), rgba(10, 64, 81, 0.82));
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 40px rgba(2, 47, 51, 0.38);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* Top Bar */
.top-bar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(16px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right)) 0 calc(24px + env(safe-area-inset-left));
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fffbe9;
  font-size: 11px;
  letter-spacing: 0.18em;
  font-weight: 750;
  text-shadow: 0 2px 18px rgba(22, 61, 77, 0.6);
}

.brand-symbol {
  font-size: 26px;
  color: #f3d99c;
  font-weight: 300;
}

.hud-pills {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-pill {
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  min-height: 44px;
}

.hud-label {
  font-size: 9px;
  letter-spacing: 0.13em;
  color: #b7d7d9;
}

.hud-pill strong {
  font-weight: 650;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: #f5f3dc;
  border: 1px solid rgba(255, 255, 255, 0.22);
  font-size: 18px;
  display: grid;
  place-items: center;
  transition: transform 0.15s, background 0.15s;
}

.icon-button:hover {
  background: rgba(14, 82, 103, 0.9);
  transform: translateY(-1px);
}

/* Wind Card */
.wind-card {
  position: absolute;
  top: calc(85px + env(safe-area-inset-top));
  left: calc(24px + env(safe-area-inset-left));
  width: 230px;
  border-radius: 17px;
  padding: 15px 17px;
}

.wind-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.wind-heading {
  font-size: 10px;
  letter-spacing: 0.13em;
  color: #bfd9db;
  font-weight: 700;
}

.point-of-sail-pill {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(230, 246, 239, 0.16);
  color: #e4f7ee;
}

.wind-main {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
}

.wind-main strong {
  font-size: 22px;
  font-weight: 600;
  display: block;
  letter-spacing: -0.04em;
}

.wind-main small {
  display: block;
  color: #b8d3d7;
  font-size: 11px;
  margin-top: 1px;
}

.wind-arrow {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(230, 246, 239, 0.35);
  border-radius: 50%;
  font-size: 22px;
  color: #f4e0ad;
  text-shadow: 0 0 15px rgba(230, 207, 142, 0.45);
  transition: transform 0.25s ease;
}

.wind-meter {
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 99px;
  overflow: hidden;
}

.wind-meter > div {
  width: 65%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #85d9d4, #f4d59b);
}

.wind-tip {
  margin-top: 10px;
  color: #d2e0dd;
  line-height: 1.35;
  font-size: 11px;
}

/* Location Tag */
.location-tag {
  position: absolute;
  top: calc(90px + env(safe-area-inset-top));
  right: calc(24px + env(safe-area-inset-right));
  font-weight: 750;
  letter-spacing: 0.13em;
  font-size: 10px;
  text-shadow: 0 2px 15px rgba(5, 42, 56, 0.7);
}

.location-tag span {
  color: #e6dba4;
  margin: 0 6px;
}

/* Action Buttons */
.game-actions {
  position: absolute;
  right: calc(24px + env(safe-area-inset-right));
  bottom: 215px;
  display: grid;
  gap: 9px;
}

.action-button {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fffbe9;
  border-radius: 13px;
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  min-height: 44px;
  transition: transform 0.15s, opacity 0.15s;
}

.action-button:hover:not(:disabled) {
  transform: translateX(-2px);
}

.action-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.action-button.subtle {
  opacity: 0.88;
}

.action-icon {
  font-size: 18px;
  color: #e9d397;
}

/* Lower Controls Bar */
.control-bar {
  position: absolute;
  left: calc(24px + env(safe-area-inset-left));
  right: calc(24px + env(safe-area-inset-right));
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.steer-control {
  display: flex;
  align-items: center;
  gap: 18px;
}

.joystick {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid rgba(248, 255, 237, 0.54);
  background: rgba(6, 52, 71, 0.4);
  box-shadow: inset 0 0 25px rgba(6, 46, 63, 0.5), 0 3px 18px rgba(7, 51, 64, 0.3);
  touch-action: none;
}

.joystick:before,
.joystick:after {
  content: "";
  position: absolute;
  background: rgba(231, 252, 245, 0.3);
  pointer-events: none;
}

.joystick:before {
  height: 1px;
  left: 15px;
  right: 15px;
  top: 50%;
}

.joystick:after {
  width: 1px;
  top: 15px;
  bottom: 15px;
  left: 50%;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  transform: translate(-50%, -50%);
  background: linear-gradient(145deg, #f7f4d8, #c3e3df);
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(8, 56, 72, 0.65);
  z-index: 1;
}

.joystick-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-shadow: 0 1px 4px #114253;
}

.desktop-guide {
  display: flex;
  gap: 5px;
  align-items: center;
  text-shadow: 0 2px 10px #062f3c;
}

.desktop-guide span {
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
}

.desktop-guide small {
  font-size: 10px;
  margin-left: 6px;
}

/* Sail Trim Controls */
.sail-control {
  width: 260px;
  border-radius: 17px;
  padding: 14px 16px 15px;
}

.trim-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.trim-title-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.trim-title-group span {
  font-size: 10px;
  letter-spacing: 0.13em;
  color: #bfd9db;
  font-weight: 700;
}

.trim-title-group strong {
  font-size: 16px;
  color: #f7f2de;
}

.trim-mode-toggle {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: #e4f5ed;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  min-height: 28px;
}

.trim-feedback-row {
  margin-top: 4px;
}

.trim-badge {
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 6px;
  display: inline-block;
}

.trim-badge.sweet-spot {
  background: rgba(133, 217, 185, 0.22);
  color: #92ffd1;
  border: 1px solid rgba(146, 255, 209, 0.3);
}

.trim-badge.suboptimal {
  background: rgba(246, 216, 134, 0.2);
  color: #f7e099;
  border: 1px solid rgba(247, 224, 153, 0.3);
}

.trim-badge.backwinded {
  background: rgba(255, 120, 100, 0.2);
  color: #ff9d8e;
  border: 1px solid rgba(255, 157, 142, 0.3);
}

.sail-control input[type="range"] {
  width: 100%;
  height: 28px;
  accent-color: #e7d199;
  touch-action: pan-x;
  margin: 6px 0 0;
  cursor: pointer;
}

.trim-scale {
  display: flex;
  justify-content: space-between;
  font-size: 8px;
  margin: 2px 0 10px;
  letter-spacing: 0.05em;
  color: #a7cbcd;
}

.sail-button,
.primary-button,
.secondary-button {
  border: 0;
  font-weight: 800;
  border-radius: 11px;
  padding: 12px 16px;
  min-height: 44px;
  transition: transform 0.15s, background 0.15s;
}

.sail-button,
.primary-button {
  background: #f0d597;
  color: #153b42;
}

.sail-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.sail-button:hover,
.primary-button:hover {
  background: #f9e6af;
  transform: translateY(-1px);
}

.secondary-button {
  background: rgba(255, 255, 255, 0.14);
  color: #f5f7ed;
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.secondary-button:hover {
  background: rgba(255, 255, 255, 0.22);
}

.secondary-button.danger-subtle {
  border-color: rgba(255, 120, 100, 0.35);
  color: #ffd8d2;
}

/* Toast */
.toast {
  position: absolute;
  left: 50%;
  bottom: 175px;
  transform: translateX(-50%) translateY(14px);
  background: rgba(8, 46, 60, 0.92);
  border: 1px solid rgba(255, 243, 180, 0.5);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.toast.shown {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.keyboard-tip {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: #eef6e7;
  text-shadow: 0 2px 8px #0b3649;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  opacity: 0.82;
}

/* Intro & Startup */
.intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(90deg, rgba(7, 40, 51, 0.88) 0%, rgba(5, 50, 63, 0.72) 45%, rgba(12, 67, 82, 0.4) 100%);
  padding: 30px;
  z-index: 10;
}

.intro-card {
  max-width: 520px;
  margin-right: auto;
  margin-left: min(10vw, 140px);
  text-shadow: 0 3px 25px rgba(2, 47, 66, 0.65);
}

.eyebrow {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.27em;
  color: #efdb9b;
  margin: 0;
}

.intro h1 {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: -0.06em;
  font-size: clamp(52px, 7vw, 102px);
  line-height: 0.95;
  margin: 22px 0 20px;
  font-weight: 400;
}

.intro h1 em {
  font-weight: 400;
  color: #f1d89c;
  font-style: italic;
}

.intro-card > p:not(.eyebrow) {
  font-size: 16px;
  line-height: 1.55;
  color: #e3f2eb;
  max-width: 410px;
}

.intro-hint {
  font-size: 11px !important;
  letter-spacing: 0.1em;
  margin-top: 22px;
  opacity: 0.75;
}

#startup-container {
  margin-top: 24px;
}

.startup-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(240, 213, 151, 0.25);
  border-top-color: #f0d597;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.startup-status {
  font-size: 13px;
  color: #d7e8e3;
  margin: 0 0 16px;
}

.webgl-error {
  margin-top: 20px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(90, 25, 25, 0.85);
  border: 1px solid rgba(255, 120, 100, 0.5);
}

.webgl-error h3 {
  margin: 0 0 8px;
  color: #ffb4a6;
}

.webgl-error p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

/* Resting Camp Overlay */
.camp-scene {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 22px;
  padding: 28px 32px;
  width: min(400px, 92vw);
  text-align: center;
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.45);
}

.camp-scene h2 {
  font-family: Georgia, serif;
  font-size: 32px;
  font-weight: 400;
  margin: 8px 0;
}

.camp-scene p:not(.eyebrow) {
  color: #d4e7df;
  font-size: 14px;
  line-height: 1.5;
}

.camp-scene .primary-button {
  margin-top: 14px;
  width: 100%;
}

/* Modal Backdrops & Dialogs */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 25, 33, 0.72);
  padding: 20px;
  z-index: 20;
}

.modal-card {
  width: min(540px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px;
  padding: 28px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.modal-header h2 {
  font-family: Georgia, serif;
  font-size: 28px;
  margin: 6px 0 16px;
  font-weight: 400;
}

.modal-section {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 16px 0;
}

.modal-section h3 {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: #bedade;
  margin: 0 0 12px;
}

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

.stat-item {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 10px 14px;
}

.stat-label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.1em;
  color: #9cbcc1;
  margin-bottom: 4px;
}

.stat-item strong {
  font-size: 16px;
  color: #f7f3e1;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
}

.setting-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: #f0d597;
  cursor: pointer;
}

.controls-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  line-height: 1.7;
  color: #d1e5df;
}

.controls-list strong {
  color: #f0d597;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 20px;
}

.modal-actions button {
  flex: 1;
}

/* Responsive Adaptation */
@media (max-width: 768px) {
  .top-bar {
    padding: calc(10px + env(safe-area-inset-top)) 14px 0;
  }
  .brand {
    font-size: 9px;
    letter-spacing: 0.08em;
  }
  .brand-symbol {
    font-size: 20px;
  }
  .hud-pills {
    gap: 6px;
  }
  .hud-pill {
    padding: 6px 9px;
    font-size: 11px;
    min-height: 38px;
  }
  .landmark-pill {
    display: none;
  }
  .icon-button {
    width: 38px;
    height: 38px;
  }
  .wind-card {
    left: calc(12px + env(safe-area-inset-left));
    top: calc(64px + env(safe-area-inset-top));
    width: 175px;
    padding: 10px 12px;
  }
  .wind-main {
    gap: 8px;
    margin: 6px 0;
  }
  .wind-main strong {
    font-size: 17px;
  }
  .wind-arrow {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }
  .location-tag {
    top: calc(70px + env(safe-area-inset-top));
    right: calc(14px + env(safe-area-inset-right));
    font-size: 8px;
    max-width: 160px;
    text-align: right;
  }
  .control-bar {
    left: calc(12px + env(safe-area-inset-left));
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .joystick {
    width: 100px;
    height: 100px;
  }
  .joystick-knob {
    width: 40px;
    height: 40px;
  }
  .desktop-guide,
  .keyboard-tip {
    display: none;
  }
  .sail-control {
    width: 200px;
    padding: 10px 12px;
  }
  .game-actions {
    right: calc(14px + env(safe-area-inset-right));
    bottom: 180px;
  }
  .action-button {
    padding: 8px 12px;
    font-size: 11px;
  }
  .toast {
    bottom: 155px;
    width: min(290px, 80vw);
    white-space: normal;
  }
  .intro-card {
    margin-left: 2vw;
  }
  .intro h1 {
    font-size: clamp(48px, 11vw, 72px);
  }
}

@media (max-height: 480px) {
  .wind-card {
    top: calc(52px + env(safe-area-inset-top));
    padding: 8px 10px;
  }
  .wind-tip {
    display: none;
  }
  .location-tag {
    display: none;
  }
  .game-actions {
    bottom: 120px;
  }
  .control-bar {
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .joystick {
    width: 82px;
    height: 82px;
  }
  .joystick-knob {
    width: 34px;
    height: 34px;
  }
  .sail-control {
    padding: 8px 11px;
    width: 190px;
  }
  .trim-scale {
    display: none;
  }
  .top-bar {
    padding-top: calc(6px + env(safe-area-inset-top));
  }
  .keyboard-tip {
    display: none;
  }
}
