:root {
  color-scheme: dark;
  --ink: #07161f;
  --navy: #0b2634;
  --panel: rgba(5, 20, 29, .9);
  --foam: #e9fff7;
  --mint: #67f1c3;
  --gold: #ffc857;
  --coral: #ff6b6b;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: var(--ink);
  color: var(--foam);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  touch-action: none;
  user-select: none;
  overscroll-behavior: none;
}
button, a { font: inherit; }
button { color: inherit; touch-action: manipulation; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
canvas { display: block; width: 100%; height: 100%; }

.back-link, .icon-btn {
  position: fixed;
  top: 12px;
  z-index: 70;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 9px;
  background: rgba(5,16,23,.76);
  color: rgba(255,255,255,.75);
  padding: 9px 11px;
  font-size: 10px;
  letter-spacing: .08em;
  text-decoration: none;
  cursor: pointer;
}
.back-link { left: 12px; }
.icon-btn { right: 12px; }
.back-link:hover, .icon-btn:hover { color: var(--mint); border-color: var(--mint); }

#hud {
  position: fixed;
  inset: 58px 12px auto;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(250px, auto) minmax(280px, 1fr) auto;
  gap: 10px;
  align-items: start;
  pointer-events: none;
}
#hud[hidden] { display: none; }
body[data-scene="fishing"] #hud { display: none; }
.hud-card, .hud-actions button, #depth-meter, #haul {
  background: var(--panel);
  border: 1px solid rgba(103,241,195,.35);
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
  backdrop-filter: blur(8px);
}
.hud-card { border-radius: 10px; padding: 10px 12px; }
.resources { display: flex; flex-wrap: wrap; gap: 7px 14px; font-size: 10px; }
.resources b { color: var(--mint); }
.resources .coin b, .coin { color: var(--gold); }
.objective { text-align: center; line-height: 1.35; min-height: 62px; }
.objective small { display: block; color: var(--mint); font-size: 9px; letter-spacing: .18em; }
.objective strong { display: block; margin: 3px 0; font-size: 13px; letter-spacing: .08em; }
.objective span { display: block; color: rgba(255,255,255,.72); font-size: 9px; }
.hud-actions { display: flex; gap: 7px; pointer-events: auto; }
.hud-actions button {
  border-radius: 9px;
  padding: 11px 12px;
  font-size: 9px;
  letter-spacing: .08em;
  cursor: pointer;
}
.hud-actions button:hover { border-color: var(--gold); color: var(--gold); }

#prompt, #toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  pointer-events: none;
  text-align: center;
}
#prompt {
  bottom: 66px;
  min-height: 0;
  border-radius: 9px;
  padding: 9px 14px;
  background: rgba(5,16,23,.88);
  color: var(--gold);
  font-size: 10px;
  opacity: 0;
  transition: opacity .15s;
}
#prompt.visible { opacity: 1; }
#toasts { top: 132px; display: grid; gap: 8px; }
.toast {
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 9px;
  background: rgba(5,16,23,.94);
  padding: 10px 16px;
  font-size: 10px;
  animation: rise .2s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

#controls-hint {
  position: fixed;
  z-index: 20;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 10px;
  border-radius: 7px;
  background: rgba(5,16,23,.65);
  color: rgba(255,255,255,.55);
  font-size: 9px;
  white-space: nowrap;
  pointer-events: none;
}
#depth-meter, #haul {
  position: fixed;
  z-index: 22;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 10px;
}
#depth-meter { top: 12px; left: 50%; transform: translateX(-50%); }
#haul { top: 58px; right: 14px; color: var(--gold); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  overflow-y: auto;
  padding: 70px 20px 36px;
  background:
    radial-gradient(circle at 50% 18%, rgba(52,176,164,.2), transparent 34%),
    linear-gradient(180deg, rgba(5,26,36,.97), rgba(3,12,20,.99));
  text-align: center;
}
.overlay.show { display: grid; }
.overlay h1 { margin: 6px 0 12px; color: var(--mint); font-size: clamp(34px, 8vw, 78px); letter-spacing: .12em; text-shadow: 0 6px 0 rgba(0,0,0,.3); }
.overlay > p { max-width: 650px; margin: 0; color: rgba(255,255,255,.8); font-size: clamp(13px, 2.4vw, 20px); line-height: 1.8; }
.overlay > small { margin-top: 30px; color: rgba(255,255,255,.45); font-size: 10px; }
.title-mark { color: var(--gold); font: 80px/1 Georgia, serif; }
.button-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 28px; }
.primary {
  border: 0;
  border-radius: 10px;
  background: var(--gold);
  color: #10212a;
  padding: 14px 20px;
  box-shadow: 0 5px 0 #8f5d1f;
  font-weight: 800;
  letter-spacing: .08em;
  cursor: pointer;
}
.primary:hover:not(:disabled) { background: var(--mint); box-shadow: 0 5px 0 #29785f; transform: translateY(-1px); }
.primary:disabled { filter: grayscale(.7); opacity: .45; cursor: not-allowed; box-shadow: none; }

.panel-overlay { background: rgba(3,12,20,.88); backdrop-filter: blur(12px); }
.panel {
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 100px));
  overflow-y: auto;
  border: 1px solid rgba(103,241,195,.3);
  border-radius: 18px;
  background: #0a2330;
  padding: clamp(20px, 5vw, 42px);
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
}
.panel.wide { width: min(980px, 100%); }
.eyebrow { margin: 0 0 7px; color: var(--gold); font-size: 10px; letter-spacing: .18em; }
.panel h2 { margin: 0; font-size: clamp(22px, 5vw, 38px); letter-spacing: .07em; }
.panel-copy { color: rgba(255,255,255,.6); font-size: 11px; line-height: 1.6; }
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 25px 0; }
.shop-card { display: flex; min-width: 0; flex-direction: column; gap: 9px; border: 1px solid rgba(255,255,255,.15); border-radius: 12px; background: rgba(0,0,0,.2); padding: 16px; text-align: left; }
.shop-card h3 { margin: 0; color: var(--mint); font-size: 13px; line-height: 1.4; }
.shop-card p { min-height: 38px; margin: 0; color: rgba(255,255,255,.62); font-size: 10px; line-height: 1.5; }
.shop-card .level { color: var(--gold); font-size: 10px; }
.shop-card button { margin-top: auto; width: 100%; font-size: 10px; }
.close-btn { margin-top: 4px; }
.aquarium-panel { width: min(620px, 100%); }
.aquarium-list { display: grid; gap: 10px; margin: 24px 0; }
.aquarium-empty { margin: 0; border: 1px dashed rgba(255,255,255,.24); border-radius: 12px; padding: 28px; color: rgba(255,255,255,.55); font-size: 11px; }
.aquarium-fish { display: flex; align-items: center; gap: 14px; border: 1px solid rgba(255,255,255,.15); border-radius: 12px; background: rgba(0,0,0,.2); padding: 12px 16px; text-align: left; }
.aquarium-fish div { display: grid; gap: 5px; }
.aquarium-fish strong { color: var(--mint); font-size: 11px; }
.aquarium-fish span { color: rgba(255,255,255,.7); font-size: 10px; }
.fish-swatch { width: 42px; height: 22px; flex: 0 0 auto; border-radius: 50% 45% 45% 50%; background: var(--fish-color); box-shadow: inset -8px 0 rgba(0,0,0,.15); }
.catch-review-overlay { z-index: 80; }
.catch-review-panel { width: min(620px, 100%); }
.catch-fish-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 24px 0;
  border: 1px solid rgba(103,241,195,.28);
  border-radius: 16px;
  background: rgba(0,0,0,.22);
  padding: 24px;
  text-align: left;
}
.catch-fish-card div { display: grid; gap: 7px; }
.catch-fish-card strong { color: var(--mint); font-size: 14px; }
.catch-fish-card span { color: rgba(255,255,255,.72); font-size: 11px; }
.catch-fish-swatch { width: 82px; height: 42px; }
.catch-action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.catch-action-row button { min-height: 48px; }
.keep-btn { background: var(--mint); box-shadow: 0 5px 0 #29785f; }
.catch-replacement { margin-top: 22px; }
.catch-replacement h3 { margin: 0; color: var(--gold); font-size: 15px; letter-spacing: .08em; }
.catch-replacement > p { margin: 8px 0 16px; color: rgba(255,255,255,.68); font-size: 10px; line-height: 1.5; }
.replacement-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.replacement-fish, .secondary {
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 10px;
  background: rgba(0,0,0,.24);
  color: var(--foam);
  padding: 12px;
  cursor: pointer;
}
.replacement-fish { display: flex; min-width: 0; align-items: center; gap: 10px; text-align: left; }
.replacement-fish:hover, .secondary:hover { border-color: var(--mint); }
.replacement-fish div { display: grid; min-width: 0; gap: 4px; }
.replacement-fish strong { color: var(--mint); font-size: 10px; }
.replacement-fish span { overflow-wrap: anywhere; color: rgba(255,255,255,.7); font-size: 9px; }
.replacement-fish .fish-swatch { width: 34px; height: 18px; }
.catch-replacement .secondary { width: 100%; min-height: 44px; margin-top: 12px; }
.catch-review-error { margin-top: 20px; border: 1px solid rgba(255,107,107,.55); border-radius: 12px; background: rgba(255,107,107,.1); padding: 14px; }
.catch-review-error p { margin: 0 0 12px; color: #ffd8d8; font-size: 10px; line-height: 1.5; }
.catch-review-error button { width: 100%; }

#touch-ui { display: none; }
body.touch #touch-ui { display: block; }
body.touch #controls-hint { display: none; }
#joystick {
  position: fixed;
  z-index: 35;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 116px;
  height: 116px;
  border: 2px solid rgba(255,255,255,.3);
  border-radius: 50%;
  background: rgba(5,16,23,.42);
  touch-action: none;
}
#joystick-knob { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(103,241,195,.9); box-shadow: 0 4px 12px rgba(0,0,0,.35); }
.round-btn {
  position: fixed;
  z-index: 35;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(26px, env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  border: 2px solid rgba(255,255,255,.4);
  border-radius: 50%;
  background: var(--coral);
  color: white;
  font-weight: 800;
  font-size: 10px;
  touch-action: none;
}
.round-btn.fish { bottom: 120px; background: #2378a0; display: none; }

@media (max-width: 760px) {
  #touch-ui { display: block; }
  #controls-hint { display: none; }
  #hud { inset: 54px 8px auto; grid-template-columns: 1fr auto; }
  .resources { grid-column: 1 / -1; justify-content: center; }
  .objective { text-align: left; min-width: 0; }
  .objective strong { font-size: 11px; }
  .hud-actions { flex-direction: column; }
  .hud-actions button { padding: 9px; font-size: 8px; }
  .card-grid { grid-template-columns: 1fr; }
  .shop-card p { min-height: 0; }
  #prompt { bottom: 150px; max-width: 78vw; }
  #toasts { top: 160px; }
  #depth-meter { top: 12px; }
  #haul { top: 50px; }
  .panel { max-height: calc(100vh - 80px); padding: 22px 16px; }
  .catch-review-overlay { align-items: start; padding: 12px 8px; }
  .catch-review-panel { max-height: calc(100dvh - 24px); border-radius: 13px; padding: 18px 14px; }
  .catch-fish-card { margin: 16px 0; padding: 16px; }
  .catch-action-row, .replacement-list { grid-template-columns: 1fr; }
}

@media (max-height: 560px) and (orientation: landscape) {
  #hud { inset: 48px 8px auto; grid-template-columns: auto 1fr auto; }
  .resources { grid-column: auto; max-width: 250px; }
  #joystick { width: 92px; height: 92px; }
  .round-btn { width: 70px; height: 70px; }
  .round-btn.fish { bottom: 98px; }
}
