:root {
  --ink: #123a4f;
  --ink-soft: #4c7791;
  --deep: #0d3b57;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.92);
  --line: rgba(18, 58, 79, 0.14);
  --aqua: #4fc3e8;
  --aqua-deep: #1c86b8;
  --sand: #ffe9c7;
  --shadow: 0 18px 44px rgba(9, 51, 74, 0.18);
  --radius: 22px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #bfeaf7;
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

#ocean-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 22px clamp(16px, 3vw, 38px);
}

.hud-top, .hud-bottom {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.hud-bottom { justify-content: center; align-items: flex-end; }

.brand h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 32px);
  letter-spacing: 0.16em;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 3px 14px rgba(6, 48, 72, 0.45);
}

.brand p {
  margin: 6px 0 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 2px 10px rgba(6, 48, 72, 0.4);
  letter-spacing: 0.04em;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.stat {
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(9, 51, 74, 0.14);
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}
.stat b { font-size: 16px; color: var(--aqua-deep); }

.btn {
  pointer-events: auto;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 20px;
  min-height: 40px;
  border-radius: 999px;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, opacity .16s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-sm { padding: 7px 14px; font-size: 13px; min-height: 34px; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary {
  background: linear-gradient(135deg, #ffd48a, #ffb35c);
  color: #4a2f08;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(255, 168, 76, .38);
}
.btn-primary:hover { box-shadow: 0 14px 30px rgba(255, 168, 76, .5); }
.btn-ghost {
  background: var(--glass);
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(9, 51, 74, .14);
}
.btn-ghost:hover { background: var(--glass-strong); }
.btn-soft {
  background: rgba(79, 195, 232, .16);
  color: var(--aqua-deep);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.tip {
  background: var(--glass);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  color: var(--ink-soft);
  box-shadow: 0 8px 22px rgba(9, 51, 74, .12);
  pointer-events: auto;
}

/* ---------- loading ---------- */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: linear-gradient(180deg, #cdeefb 0%, #59b8de 45%, #0e4a6d 100%);
  z-index: 40;
  transition: opacity .6s ease;
  color: #fff;
}
.loading.hide { opacity: 0; pointer-events: none; }
.loading p { font-size: 14px; letter-spacing: .1em; opacity: .95; }
.loading-bubble {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #fff, rgba(255,255,255,.15) 60%, rgba(255,255,255,0) 72%);
  border: 2px solid rgba(255,255,255,.7);
  animation: floatUp 1.8s ease-in-out infinite;
}
@keyframes floatUp {
  0%, 100% { transform: translateY(8px) scale(.9); opacity: .6; }
  50% { transform: translateY(-10px) scale(1.06); opacity: 1; }
}

.fatal {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: #0e4a6d; color: #fff; z-index: 99; font-size: 15px;
}

/* ---------- modal ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(8, 42, 62, .42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fade .22s ease;
  overflow-y: auto;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.modal {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 26px 26px 22px;
  animation: pop .26s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop { from { transform: translateY(14px) scale(.97); opacity: 0 } to { transform: none; opacity: 1 } }
/* 老浏览器没有 aspect-ratio 时给个固定高度兜底 */
@supports not (aspect-ratio: 1 / 1) {
  .pad { height: 300px; }
}

.modal h2 {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .02em;
}
.modal .sub {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.6;
}
.modal label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 6px;
}
.modal input[type=text], .modal input[type=email], .modal input[type=password] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  font-size: 16px; /* 16px 起，避免 iOS 聚焦时整页放大 */
  font-family: inherit;
  color: var(--ink);
  outline: none;
  transition: border-color .16s;
  background: #fbfdff;
  -webkit-appearance: none;
  appearance: none;
}
.modal input:focus { border-color: var(--aqua); }
.modal .row { display: flex; gap: 10px; }
.modal .row > * { flex: 1; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}
.field { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--ink-soft); margin-top: 6px; line-height: 1.5; }
.err { color: #d1564a; font-size: 12.5px; margin-top: 8px; min-height: 16px; }

/* tabs */
.tabs { display: flex; gap: 6px; background: #f1f7fa; padding: 4px; border-radius: 14px; margin-bottom: 18px; }
.tabs button {
  flex: 1; border: none; background: transparent; padding: 9px 6px; border-radius: 11px;
  font-size: 13.5px; font-family: inherit; color: var(--ink-soft); cursor: pointer; transition: .16s;
}
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 4px 12px rgba(9,51,74,.1); font-weight: 600; }

/* ---------- draw pad ---------- */
.pad-wrap { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.pad-stage { flex: 0 0 auto; width: 300px; }
.pad {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  border-radius: 18px;
  background: #f4fbfe;
  border: 2px dashed rgba(31, 134, 184, .35);
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.pad canvas { display: block; width: 100%; height: 100%; }
.pad-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 13px; color: rgba(76,119,145,.75); text-align: center; line-height: 1.7;
  pointer-events: none; padding: 0 24px;
}
.pad-tools {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px;
}
.pad-or { font-size: 12px; color: var(--ink-soft); }
.pad-side { flex: 1 1 190px; min-width: 180px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 2.5px solid #fff; cursor: pointer;
  box-shadow: 0 2px 8px rgba(9,51,74,.22); transition: transform .14s;
  -webkit-tap-highlight-color: transparent;
}
.swatch:hover { transform: scale(1.1); }
.swatch.on { box-shadow: 0 0 0 2px var(--aqua-deep), 0 2px 8px rgba(9,51,74,.22); }
.dir-toggle { display: flex; gap: 8px; }
.dir-toggle button {
  flex: 1; padding: 10px 9px; min-height: 40px; border-radius: 12px; border: 1.5px solid var(--line);
  background: #fbfdff; font-family: inherit; font-size: 14px; color: var(--ink-soft); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dir-toggle button.on { border-color: var(--aqua); color: var(--aqua-deep); background: rgba(79,195,232,.12); font-weight: 600; }

/* ---------- fish card ---------- */
.card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.card-avatar {
  width: 74px; height: 74px; border-radius: 20px; background: #f4fbfe;
  border: 1.5px solid var(--line); flex: 0 0 auto; overflow: hidden;
}
.card-avatar canvas { width: 100%; height: 100%; display: block; }
.card-name { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.card-meta { font-size: 12.5px; color: var(--ink-soft); line-height: 1.7; }
.tag {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: rgba(255,180,92,.2); color: #9a5c14; margin-left: 6px; font-weight: 600;
}
.grow-bar {
  height: 10px; border-radius: 99px; background: #eef6fa; overflow: hidden; margin: 8px 0 6px;
}
.grow-bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #7fd8f3, #ffb35c); transition: width .5s ease; }
.stage { font-size: 12.5px; color: var(--ink-soft); }
.feed-note { font-size: 12px; color: var(--ink-soft); margin-top: 10px; line-height: 1.6; }
.feed-pop {
  position: fixed; z-index: 60; pointer-events: none; font-size: 15px; font-weight: 600;
  color: #ffb35c; text-shadow: 0 2px 10px rgba(255,180,92,.5); animation: popUp 1.1s ease forwards;
}
@keyframes popUp {
  0% { transform: translate(-50%, 0) scale(.8); opacity: 0 }
  25% { transform: translate(-50%, -14px) scale(1.1); opacity: 1 }
  100% { transform: translate(-50%, -52px) scale(1); opacity: 0 }
}

/* ---------- toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; top: 84px; z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: rgba(18,58,79,.92); color: #fff; font-size: 13.5px; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 10px 26px rgba(9,51,74,.28); animation: toastIn .3s ease;
}
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- 移动端 ---------- */
@media (max-width: 720px) {
  .hud {
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
  }
  .brand h1 { font-size: 20px; letter-spacing: .12em; }
  .brand p { display: none; }
  .stat { padding: 6px 12px; font-size: 12px; }
  .stat span { display: none; }
  .top-right { gap: 8px; }
  .btn { padding: 9px 15px; font-size: 13px; min-height: 38px; }
  .tip { font-size: 12px; padding: 7px 14px; }
  .hud-bottom { padding-bottom: 2px; }

  /* 弹窗改成底部抽屉，拇指够得着 */
  .modal-mask { align-items: flex-end; padding: 0; overflow-y: auto; }
  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: 22px 22px 0 0;
    max-height: 92vh;
    max-height: 92dvh;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    animation: sheet .26s cubic-bezier(.2,.9,.3,1.1);
  }
  @keyframes sheet { from { transform: translateY(28px); opacity: 0 } to { transform: none; opacity: 1 } }
  .modal-actions { margin-top: 16px; }
  .modal-actions .btn { flex: 1; }
  .modal-actions .btn-sm { flex: 0 1 auto; }

  /* 画板：单列、正方形、尽量大 */
  .pad-wrap { flex-direction: column; gap: 14px; }
  .pad-stage { width: 100%; }
  .pad { max-width: 440px; margin: 0 auto; }
  .pad-tools { justify-content: center; }
  .pad-or { width: 100%; text-align: center; }
  .pad-side { width: 100%; min-width: 0; }
  .swatches { justify-content: center; }
  .swatch { width: 38px; height: 38px; }
  .card-avatar { width: 62px; height: 62px; border-radius: 16px; }
  .card-name { font-size: 18px; }
  .card-head { gap: 12px; }
  #toast-root { top: calc(64px + env(safe-area-inset-top)); }
}

/* 横屏矮屏（手机横放） */
@media (max-height: 480px) and (orientation: landscape) {
  .pad { max-width: 260px; }
  .modal { max-height: 96vh; padding-top: 14px; }
  .brand h1 { font-size: 18px; }
  .hud { padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 8px; }
}
