* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #01111f;
  color: #eaf6ff;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#viewport {
  position: fixed;
  inset: 0;
}
#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  font-size: 15px;
  z-index: 5;
  background: linear-gradient(to bottom, rgba(0,10,20,0.55), rgba(0,10,20,0));
  pointer-events: none;
}

#sea-name {
  font-weight: 700;
  font-size: 17px;
  color: #7fe0ff;
  text-shadow: 0 0 8px rgba(127,224,255,0.6);
}

#counters {
  display: flex;
  gap: 12px;
}

#counter, #treasure-counter, #coin-counter, #cooler-counter {
  color: #ffe9a8;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  font-size: 14px;
}

#treasure-counter { color: #9fe8ff; }
#coin-counter { color: #ffd76b; }
#cooler-counter { color: #cfefff; }

#mission-tracker {
  position: fixed;
  top: 132px;
  left: 18px;
  max-width: 340px;
  z-index: 5;
  background: rgba(0,10,20,0.6);
  border: 1px solid rgba(255,216,74,0.35);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 12.5px;
  line-height: 1.4;
  color: #fff3c4;
  pointer-events: none;
}

#depth-meter {
  position: fixed;
  top: 214px;
  right: 18px;
  z-index: 5;
  background: rgba(0,10,20,0.6);
  border: 1px solid rgba(127,224,255,0.35);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
  color: #9fe8ff;
  pointer-events: none;
}

/* Treasure detector: cold / warm / hot as the explorer nears a hidden chest */
#detector {
  position: fixed;
  top: 250px;
  right: 18px;
  z-index: 5;
  background: rgba(0,10,20,0.6);
  border: 1px solid rgba(255,215,107,0.4);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
  color: #ffe9a8;
  pointer-events: none;
  transition: border-color 0.3s, box-shadow 0.3s;
}
#detector.hot { border-color: #ff8a3a; box-shadow: 0 0 12px rgba(255,138,58,0.6); }
#detector.walk { top: 214px; }
#puzzle-question.riddle-question { font-size: 17px; line-height: 1.4; text-align: center; }
.riddle-choice { font-size: 15px; }

/* ---------------- Fishing ---------------- */
#fishing-ui {
  position: fixed;
  left: 50%;
  bottom: 70px;
  transform: translateX(-50%);
  z-index: 6;
  width: min(380px, 90vw);
  background: rgba(0,15,28,0.78);
  border: 1px solid rgba(127,224,255,0.4);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
  pointer-events: none;
}
#fishing-status { font-weight: 700; font-size: 15px; color: #eaf6ff; }
#fishing-bars { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.fish-bar-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #bfe9ff; }
.fish-bar-row span { width: 58px; text-align: right; }
.fish-bar {
  position: relative;
  flex: 1;
  height: 14px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 7px;
  overflow: hidden;
}
.fish-bar-danger { position: absolute; top: 0; bottom: 0; left: 75%; right: 0; background: rgba(255,60,40,0.25); }
#tension-fill { height: 100%; width: 0; background: linear-gradient(90deg, #7cffcb, #ffd76b); }
#tension-fill.danger { background: linear-gradient(90deg, #ffb347, #ff3b3b); }
#reel-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #3fd0ff, #7cffcb); }

#catch-card {
  position: fixed;
  top: 150px;
  left: 50%;
  transform: translate(-50%, -12px);
  z-index: 7;
  width: min(360px, 90vw);
  background: linear-gradient(160deg, rgba(6,48,79,0.95), rgba(4,28,48,0.95));
  border: 1px solid rgba(255,216,74,0.5);
  border-radius: 14px;
  padding: 12px 16px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.4s, transform 0.4s;
  pointer-events: none;
}
#catch-card.show { opacity: 1; transform: translate(-50%, 0); }
.catch-title { font-size: 13px; color: #9fc6dd; }
.catch-name { font-size: 22px; font-weight: 800; text-shadow: 0 1px 6px rgba(0,0,0,0.6); }
.catch-kg { font-size: 13px; color: #eaf6ff; }
.catch-note { margin-top: 6px; font-size: 13px; color: #ffe9a8; }
.catch-fact { margin-top: 6px; font-size: 12px; color: #cfe8fa; line-height: 1.4; }

/* ---------------- NPC dialogs ---------------- */
/* dialogs always fit the screen: title and buttons stay put, the body scrolls */
.modal-box.dialog-box {
  max-width: 460px;
  text-align: left;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
}
.modal-box.dialog-box.wide { max-width: 880px; width: 94%; }
#dialog-body { overflow-y: auto; min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#dialog-title, #dialog-actions { flex: none; }
/* puzzles and riddles scroll too on short screens */
.modal-box.puzzle-box { max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; }
.dialog-box h2 { font-size: 19px; }
#dialog-body p { margin: 8px 0; }
.mission-meta { background: rgba(255,216,74,0.1); border: 1px solid rgba(255,216,74,0.3); border-radius: 8px; padding: 8px 10px; color: #fff3c4 !important; }
.dialog-tip { font-size: 12px !important; color: #9fc6dd !important; }
#dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.dialog-btn {
  background: rgba(0,20,35,0.6);
  color: #eaf6ff;
  border: 1px solid rgba(127,224,255,0.45);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.dialog-btn.primary { background: #3fd0ff; color: #012a4a; border-color: transparent; }
.dialog-btn:hover { filter: brightness(1.15); }
.sell-table { width: 100%; border-collapse: collapse; font-size: 13px; color: #dbeeff; }
.sell-table td { padding: 4px 6px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sell-table td:last-child { text-align: right; }
.sell-table tr.total td { font-weight: 800; color: #ffd76b; border-bottom: none; }
.shop-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 13px;
  color: #dbeeff;
}
.shop-row small { color: #9fc6dd; }
.shop-buy {
  flex-shrink: 0;
  background: #ffd76b;
  color: #3a2a00;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.shop-buy:disabled { opacity: 0.4; cursor: default; }
.shop-max { color: #7cffcb; font-size: 12px; flex-shrink: 0; }

.journal-section {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  font-size: 14px;
  color: #7fe0ff;
}

#oxygen-wrap {
  position: fixed;
  top: 46px;
  left: 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: rgba(0,10,20,0.55);
  padding: 6px 10px;
  border-radius: 8px;
  z-index: 5;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-label {
  font-size: 12px;
  font-weight: 700;
  color: #bfe9ff;
  width: 16px;
  text-align: center;
}

#oxygen-bar, #health-bar, #cruise-bar {
  width: 150px;
  height: 12px;
  background: rgba(255,255,255,0.15);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.25);
}

#oxygen-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #3fd0ff, #7cffcb);
  transition: width 0.15s linear, background 0.3s;
}

#health-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff7a5f, #ffd76b);
  transition: width 0.15s linear, background 0.3s;
}

#cruise-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8f7cff, #d6b4ff);
  transition: width 0.15s linear;
}
#cruise-row.active #cruise-fill {
  background: linear-gradient(90deg, #ffd76b, #fff4c2);
  box-shadow: 0 0 10px #ffd76b;
}
#cruise-row.active .bar-label { color: #ffd76b; text-shadow: 0 0 6px #ffd76b; }

#hit-flash {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,60,40,0) 40%, rgba(255,40,30,0.55) 100%);
  opacity: 0;
  transition: opacity 0.1s ease-out;
}
#hit-flash.show { opacity: 1; transition: none; }

#boss-bar {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 220px));
  z-index: 6;
  pointer-events: none;
  text-align: center;
}
#boss-name {
  font-size: 15px;
  font-weight: 800;
  color: #ffd0d6;
  text-shadow: 0 2px 8px rgba(0,0,0,0.8);
  margin-bottom: 4px;
}
#boss-track {
  height: 10px;
  border-radius: 6px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,120,140,0.5);
  overflow: hidden;
}
#boss-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #b3203a, #ff6b81);
  transition: width 0.2s ease-out;
}

#radar {
  position: fixed;
  top: 46px;
  right: 18px;
  z-index: 5;
  background: rgba(0,10,20,0.55);
  border-radius: 50%;
  border: 1px solid rgba(127,224,255,0.35);
}

#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255,255,255,0.7);
  font-size: 18px;
  z-index: 5;
  pointer-events: none;
}

#hint {
  position: fixed;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  color: #cfe8fa;
  padding: 0 10px;
  z-index: 5;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  pointer-events: none;
}

#journal-btn {
  position: fixed;
  bottom: 44px;
  right: 18px;
  z-index: 5;
  background: rgba(0,20,35,0.75);
  color: #eaf6ff;
  border: 1px solid rgba(127,224,255,0.4);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
#journal-btn:hover { background: rgba(0,40,65,0.9); }

#menu-btn {
  position: fixed;
  bottom: 44px;
  right: 138px;
  z-index: 5;
  background: rgba(0,20,35,0.75);
  color: #eaf6ff;
  border: 1px solid rgba(127,224,255,0.4);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
#menu-btn:hover { background: rgba(0,40,65,0.9); }

#save-toast {
  position: fixed;
  bottom: 86px;
  right: 18px;
  z-index: 6;
  background: rgba(0,20,35,0.8);
  color: #7cffcb;
  border: 1px solid rgba(124,255,203,0.4);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}
#save-toast.show { opacity: 1; }

/* ---------------- Start screen ---------------- */
#start-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(63,208,255,0.35), transparent 60%),
    linear-gradient(to bottom, rgba(1,17,31,0.55), rgba(1,17,31,0.9));
  user-select: text;
  touch-action: auto;
}
.start-box {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(160deg, rgba(6,48,79,0.92), rgba(4,28,48,0.95));
  border: 1px solid rgba(127,224,255,0.35);
  border-radius: 16px;
  padding: 28px 26px 22px;
  text-align: center;
  box-shadow: 0 16px 50px rgba(0,0,0,0.6);
}
.start-logo { font-size: 44px; animation: start-bob 3s ease-in-out infinite; }
@keyframes start-bob { 50% { transform: translateY(-6px) rotate(-4deg); } }
.start-box h1 {
  margin: 4px 0 0;
  font-size: 34px;
  letter-spacing: 1px;
  color: #7fe0ff;
  text-shadow: 0 0 14px rgba(127,224,255,0.5);
}
.start-subtitle { margin: 2px 0 20px; color: #9fc6dd; font-size: 14px; }
#login-form { display: flex; flex-direction: column; text-align: left; gap: 6px; }
#login-form label { font-size: 12px; color: #bfe9ff; margin-top: 6px; }
#login-form input {
  background: rgba(0,10,20,0.6);
  border: 1px solid rgba(127,224,255,0.35);
  border-radius: 8px;
  color: #eaf6ff;
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
}
#login-form input:focus { border-color: #7fe0ff; box-shadow: 0 0 0 2px rgba(127,224,255,0.2); }
.form-error { min-height: 18px; margin: 4px 0 0; color: #ff8a7a; font-size: 13px; }
.form-note { margin: 10px 0 0; color: #7fa8c2; font-size: 11px; text-align: center; line-height: 1.4; }
.start-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid rgba(127,224,255,0.45);
  background: rgba(0,20,35,0.6);
  color: #eaf6ff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.start-btn:hover { background: rgba(0,40,65,0.9); }
.start-btn.primary { background: #3fd0ff; color: #012a4a; border-color: transparent; }
.start-btn.primary:hover { background: #7cffcb; }
.start-btn:disabled { opacity: 0.4; cursor: default; }
.link-btn {
  margin-top: 14px;
  background: none;
  border: none;
  color: #7fa8c2;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { color: #eaf6ff; }
#welcome-text { font-size: 17px; color: #eaf6ff; margin: 0 0 6px; }
#credits-panel h3 { margin: 0 0 6px; color: #eaf6ff; font-size: 16px; }
.credits-list { max-height: 45vh; overflow-y: auto; text-align: left; font-size: 12px; line-height: 1.45; color: #b8d6e8; }
.credits-list p { margin: 6px 0 2px; }
.credits-list ul { margin: 0; padding-left: 18px; }
.credits-list a { color: #7fe0ff; }
#save-summary { font-size: 13px; color: #9fc6dd; margin: 0 0 8px; line-height: 1.5; }

#zone-banner {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translate(-50%, -10px);
  font-size: 28px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 2px 14px rgba(0,0,0,0.85);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
  z-index: 6;
  white-space: nowrap;
}
#zone-banner.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #01111f;
}
#loading.hidden { display: none; }
.loading-box {
  font-size: 18px;
  color: #7fe0ff;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,5,12,0.72);
  z-index: 20;
}
.modal.hidden { display: none; }

.modal-box {
  background: linear-gradient(160deg, #06304f, #041c30);
  border: 1px solid rgba(127,224,255,0.35);
  border-radius: 14px;
  padding: 24px 30px;
  max-width: 420px;
  width: 86%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.modal-box h2 {
  margin: 6px 0 8px;
  color: #7fe0ff;
}

.modal-box p {
  color: #dbeeff;
  font-size: 14px;
  line-height: 1.5;
}

.modal-hint {
  margin-top: 14px;
  font-size: 11px;
  color: #7fa8c2;
}

.swatch {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  margin: 0 auto 8px;
  border: 2px solid rgba(255,255,255,0.5);
}

.journal-box {
  max-width: 560px;
  text-align: left;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}

.journal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#journal-close {
  background: none;
  border: none;
  color: #eaf6ff;
  font-size: 18px;
  cursor: pointer;
}

#journal-list {
  overflow-y: auto;
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.journal-entry {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 10px;
}

.journal-entry.locked {
  opacity: 0.35;
}

.journal-entry h4 {
  margin: 0 0 4px;
  font-size: 13px;
  color: #ffe9a8;
}

.journal-entry p {
  margin: 0;
  font-size: 11px;
  color: #cfe8fa;
  line-height: 1.4;
}

#restart-btn {
  margin-top: 14px;
  background: #3fd0ff;
  color: #012a4a;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
}
#restart-btn:hover { background: #7cffcb; }

/* ---------------- Treasure puzzle modal ---------------- */
.puzzle-box { max-width: 460px; }

#puzzle-body {
  margin: 14px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#puzzle-question {
  font-size: 22px;
  font-weight: 700;
  color: #ffe9a8;
  margin-bottom: 4px;
}

.math-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.math-choice {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(127,224,255,0.4);
  color: #eaf6ff;
  border-radius: 8px;
  padding: 12px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.math-choice:hover { background: rgba(127,224,255,0.2); }
.math-choice.wrong { background: rgba(255,80,60,0.35); border-color: #ff5f5f; }
.math-choice.correct { background: rgba(124,255,203,0.35); border-color: #7cffcb; }

.slider-grid {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 64px);
  gap: 6px;
}

.slider-tile {
  background: linear-gradient(160deg, #3fd0ff, #1f8fc0);
  color: #012a4a;
  border: none;
  border-radius: 6px;
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slider-tile.empty {
  background: rgba(255,255,255,0.06);
  cursor: default;
}
.slider-tile.solved { background: linear-gradient(160deg, #7cffcb, #3fd0ff); }

#puzzle-cancel {
  margin-top: 6px;
  background: none;
  border: 1px solid rgba(255,255,255,0.25);
  color: #9fc4dc;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
#puzzle-cancel:hover { border-color: #7fe0ff; color: #eaf6ff; }

.hidden { display: none !important; }

/* ---------------- Touch controls (phones / tablets) ---------------- */
#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  display: none;
}

.joystick {
  position: absolute;
  bottom: max(28px, env(safe-area-inset-bottom, 0px));
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  border: 2px solid rgba(255, 255, 255, 0.3);
  pointer-events: auto;
  touch-action: none;
}
#joy-move { left: max(20px, env(safe-area-inset-left, 0px)); }
#joy-look { right: max(20px, env(safe-area-inset-right, 0px)); }

.joy-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.7);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Action buttons sit right beside the joysticks (landscape phones): fire on the
   left thumb, since the right stick aims the cannon; dive/fish by the right stick. */
#vert-buttons {
  position: absolute;
  right: max(214px, calc(env(safe-area-inset-right, 0px) + 194px));
  bottom: max(28px, env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.touch-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(0, 20, 35, 0.55);
  border: 1px solid rgba(127, 224, 255, 0.45);
  color: #eaf6ff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  pointer-events: auto;
  padding: 0;
}
.touch-btn:active { background: rgba(127, 224, 255, 0.35); }
#vert-buttons .touch-btn { width: 46px; height: 46px; font-size: 18px; }

#btn-fire {
  position: absolute;
  left: max(148px, calc(env(safe-area-inset-left, 0px) + 128px));
  bottom: max(34px, env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  font-size: 22px;
  background: rgba(60, 10, 10, 0.55);
  border-color: rgba(255, 140, 100, 0.5);
}

#btn-dive {
  position: absolute;
  right: max(148px, calc(env(safe-area-inset-right, 0px) + 128px));
  bottom: max(92px, env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  font-size: 24px;
}

#btn-fish {
  position: absolute;
  right: max(148px, calc(env(safe-area-inset-right, 0px) + 128px));
  bottom: max(26px, env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  font-size: 22px;
}
#btn-fish.ready { border-color: #7cffcb; box-shadow: 0 0 14px rgba(124,255,203,0.7); }

@media (max-width: 700px) {
  #journal-list { grid-template-columns: 1fr; }
}

/* ---------------- Phones and tablets ---------------- */
@media (pointer: coarse) {
  #touch-controls { display: block; }
  #hint { display: none; }
  /* the logbook lives in the menu; the menu button sits up by the counters */
  #journal-btn { display: none; }
  #menu-btn {
    top: max(6px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: auto;
    padding: 5px 10px;
    font-size: 12px;
  }
  #topbar { padding-right: max(96px, calc(env(safe-area-inset-right, 0px) + 84px)); }
  #save-toast { top: 42px; bottom: auto; right: max(12px, env(safe-area-inset-right, 0px)); }
  #radar { top: 42px; width: 110px; height: 110px; right: max(12px, env(safe-area-inset-right, 0px)); opacity: 0.9; }
  #depth-meter { top: 158px; right: max(12px, env(safe-area-inset-right, 0px)); font-size: 11px; }
  #detector, #detector.walk { top: 186px; right: max(12px, env(safe-area-inset-right, 0px)); font-size: 11px; }
  #detector.walk { top: 158px; }
  #fishing-ui { bottom: 150px; }
}

/* Short landscape screens: slimmer HUD so it doesn't cover the view */
@media (pointer: coarse) and (max-height: 500px) {
  #topbar { padding-top: 6px; padding-bottom: 6px; }
  #sea-name { font-size: 13px; }
  #counter, #treasure-counter, #coin-counter, #cooler-counter { font-size: 12px; }
  #oxygen-wrap { top: 34px; left: max(12px, env(safe-area-inset-left, 0px)); padding: 4px 8px; }
  #oxygen-bar, #health-bar, #cruise-bar { width: 110px; height: 9px; }
  #mission-tracker { top: 96px; left: max(12px, env(safe-area-inset-left, 0px)); max-width: 42vw; font-size: 11px; padding: 5px 8px; }
  #radar { width: 96px; height: 96px; top: 36px; }
  #depth-meter { top: 138px; }
  #zone-banner { top: 70px; font-size: 20px; }
  #catch-card { top: 50px; }
  #fishing-ui { bottom: 100px; width: min(320px, 50vw); }
}

/* Narrow portrait phones: stack the action buttons above the joysticks */
@media (pointer: coarse) and (max-width: 560px) {
  #radar { width: 92px; height: 92px; top: 124px; }
  #depth-meter { top: 222px; }
  #oxygen-wrap { top: 40px; left: max(12px, env(safe-area-inset-left, 0px)); }
  #topbar { flex-direction: column; align-items: flex-start; gap: 2px; }
  #counter, #treasure-counter, #coin-counter, #cooler-counter { font-size: 11px; }
  #counters { gap: 8px; }
  #mission-tracker { top: 118px; max-width: 55vw; font-size: 11px; padding: 5px 8px; }
  #btn-fire { left: max(34px, env(safe-area-inset-left, 0px)); bottom: 158px; }
  #btn-dive { right: max(34px, env(safe-area-inset-right, 0px)); bottom: 158px; }
  #btn-fish { right: max(96px, calc(env(safe-area-inset-right, 0px) + 96px)); bottom: 158px; }
  #vert-buttons { right: auto; left: 50%; transform: translateX(-50%); bottom: 40px; }
  #fishing-ui { bottom: 230px; }
}

/* ---------------- Garaje Náutico ---------------- */
.boat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 4px;
}
.boat-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(127,224,255,0.22);
  border-radius: 10px;
  padding: 10px;
  color: #dbeeff;
  font-size: 13px;
}
.boat-card.in-use { border-color: #7cffcb; background: rgba(124,255,203,0.08); }
.boat-card-head { display: flex; align-items: center; gap: 6px; line-height: 1.2; }
.boat-icon { font-size: 22px; flex: none; }
.boat-tag { align-self: flex-start; font-size: 10px; font-weight: 700; color: #ffd0a8; background: rgba(255,138,58,0.18); border-radius: 6px; padding: 1px 6px; }
#dialog-body .boat-desc { margin: 0; font-size: 11.5px; line-height: 1.35; color: #9fc6dd; flex: 1 1 auto; }
.boat-stats { display: grid; gap: 3px; }
.boat-stat { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: #bfe3f2; }
.boat-stat span { width: 68px; flex: none; }
.boat-stat-bar { flex: 1; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.12); overflow: hidden; }
.boat-stat-bar > div { height: 100%; background: linear-gradient(90deg, #3fd0ff, #7cffcb); }
.boat-btn { width: 100%; margin-top: 4px; padding: 8px 10px; font-size: 13px; }
.boat-btn:disabled { opacity: 0.45; cursor: default; }
.boat-in-use { margin-top: 4px; text-align: center; font-weight: 800; color: #7cffcb; padding: 7px 0; }

/* short landscape phones: tighter dialogs */
@media (max-height: 500px) {
  /* start screen: logo on the left, form / menu on the right */
  #start-screen { overflow-y: auto; align-items: safe center; padding: 10px 16px; }
  .start-box {
    max-width: 720px;
    display: grid;
    grid-template-columns: 0.9fr 1.1fr;
    grid-template-rows: auto auto 1fr;
    column-gap: 22px;
    align-items: center;
    padding: 14px 20px;
  }
  .start-logo { grid-column: 1; grid-row: 1; font-size: 34px; }
  .start-box h1 { grid-column: 1; grid-row: 2; font-size: 28px; }
  .start-subtitle { grid-column: 1; grid-row: 3; align-self: start; margin: 2px 0 0; }
  #login-form, #start-menu, #credits-panel { grid-column: 2; grid-row: 1 / span 3; }
  .credits-list { max-height: calc(100dvh - 120px); }
  #login-form { gap: 4px; }
  #login-form label { margin-top: 2px; }
  #login-form input { padding: 7px 10px; }
  .start-btn { padding: 9px 12px; margin-top: 6px; }
  #welcome-text { font-size: 15px; margin: 0 0 2px; }
  #save-summary { font-size: 12px; margin: 0 0 4px; line-height: 1.4; }
  .form-note { margin-top: 6px; }

  /* puzzles and riddles */
  .modal-box.puzzle-box { padding: 12px 18px; }
  .modal-box.puzzle-box h2 { margin: 0 0 2px; font-size: 18px; }
  #puzzle-intro { margin: 0 0 6px; font-size: 12.5px; line-height: 1.35; }
  #puzzle-question { font-size: 17px; margin-bottom: 2px; }
  #puzzle-question.riddle-question { font-size: 15px; line-height: 1.3; }
  .math-choice { padding: 8px; font-size: 16px; }
  .riddle-choice { font-size: 14px; }
  .math-choices { gap: 7px; }
  .slider-grid { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); gap: 5px; }
  .slider-tile { font-size: 20px; }
  .modal-box.puzzle-box .modal-hint { margin-top: 6px; }
  #puzzle-cancel { margin-top: 6px; padding: 6px 12px; }

  /* journal */
  .journal-box { max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); padding: 12px 18px; }
  .journal-box h2 { font-size: 18px; margin: 0; }
  #journal-list { margin-top: 6px; gap: 7px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .journal-entry { padding: 7px 10px; }

  /* discovery, win */
  .modal-box { padding: 14px 20px; }

  .modal-box.dialog-box { padding: 12px 16px; }
  .modal-box.dialog-box h2 { margin: 0 0 4px; font-size: 16px; }
  #dialog-body p { margin: 4px 0; font-size: 13px; }
  #dialog-actions { margin-top: 8px; }
  .boat-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
  .boat-card { padding: 8px; gap: 4px; }
  #dialog-body .boat-desc { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
}
