:root {
  --sea: #12343c;
  --sea-deep: #0c242b;
  --gold: #f0c14a;
  --sand: #f3e6c4;
  --ink: #24160e;
  --panel: #1a120c;
  --panel-2: #26190f;
  --line: #4a3422;
  --good: #8bd24a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--sea-deep);
  color: var(--sand);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input { font-family: inherit; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 8px 14px;
  background: linear-gradient(#1a5562, var(--sea));
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.logo {
  display: block;
  line-height: 0;
}

.logo img {
  height: 42px;
  width: auto;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.brand strong {
  display: block;
  font-size: 18px;
  letter-spacing: 1px;
  color: #fff8e8;
}

.brand small {
  color: #d7ec9a;
  font-size: 12px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stats span {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(240, 193, 74, 0.35);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
}

.stats b { color: var(--gold); font-variant-numeric: tabular-nums; }

.stats .withdraw {
  padding: 4px 10px;
  font-size: 13px;
  align-self: center;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

#app.raid .hunt-only { display: none; }

.btn {
  background: linear-gradient(#ffbf63, #e0862a);
  border: 2px solid #7a3e10;
  color: #2a1406;
  font-weight: 800;
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 #ffe0b0, 0 2px 0 #5a2c0c;
}

.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); box-shadow: inset 0 1px 0 #ffe0b0; }

.btn.ghost {
  background: #2a2118;
  color: var(--sand);
  border-color: #6a5030;
  box-shadow: inset 0 1px 0 #4a3824;
}

.btn.pulse {
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% { transform: translateY(-1px); filter: brightness(1.12); }
}

.hint {
  background: linear-gradient(90deg, #0e2a32 0%, #143840 50%, #0e2a32 100%);
  color: #c8e0c0;
  padding: 6px 14px;
  font-size: 13px;
  border-bottom: 1px solid rgba(240, 193, 74, 0.28);
  letter-spacing: 0.02em;
}

.layout {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

.voyage-load {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 14, 10, 0.9);
  backdrop-filter: blur(3px);
}
.voyage-load[hidden] { display: none !important; }
.voyage-load-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 200px;
  padding: 22px 28px;
  background: linear-gradient(180deg, #2a2014 0%, #18140c 100%);
  border: 2px solid #8a6230;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  animation: voyage-load-pulse 1.2s ease-in-out infinite;
}
.voyage-load-panel strong {
  color: #ffe08a;
  font-size: 18px;
  letter-spacing: 0.06em;
}
.voyage-load-panel p {
  margin: 0;
  color: #d9cbb0;
  font-size: 13px;
}
@keyframes voyage-load-pulse {
  50% { filter: brightness(1.08); transform: translateY(-1px); }
}

.stage {
  --stage-foam: rgba(180, 220, 230, 0.14);
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(ellipse 70% 45% at 50% 28%, rgba(70, 160, 180, 0.28) 0%, transparent 62%),
    radial-gradient(ellipse 100% 55% at 50% 100%, rgba(6, 28, 36, 0.95) 0%, transparent 58%),
    linear-gradient(165deg, #0a3844 0%, #0c2c36 42%, #081820 100%);
}

/* 遠處海平線光帶 */
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(120, 190, 210, 0.12) 0%, transparent 22%),
    repeating-linear-gradient(
      180deg,
      transparent 0 18px,
      var(--stage-foam) 18px 19px,
      transparent 19px 38px
    );
  opacity: 0.55;
  mask-image: linear-gradient(180deg, transparent 0%, #000 28%, #000 78%, transparent 100%);
  animation: stage-swell 9s ease-in-out infinite;
}

/* 甲板紋理 + 暗角，讓地圖浮在海上 */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 85% 70% at 50% 48%, transparent 42%, rgba(4, 12, 16, 0.72) 100%),
    url("../assets/field/deck.jpg") center bottom / cover no-repeat;
  opacity: 0.22;
  mix-blend-mode: soft-light;
}

@keyframes stage-swell {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-6px); opacity: 0.7; }
}

.frame {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: min(1120px, 100%, calc((100vh - 170px) * 35 / 17 + 16px));
  padding: 10px;
  border-radius: 2px;
  background:
    linear-gradient(145deg, #7a5230 0%, #4a2e14 42%, #3a2410 100%);
  box-shadow:
    0 0 0 2px #c9a24a,
    0 0 0 5px rgba(90, 56, 24, 0.95),
    0 18px 40px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 220, 160, 0.35);
  animation: frame-glow 4.8s ease-in-out infinite;
}

@keyframes frame-glow {
  0%, 100% { box-shadow: 0 0 0 2px #c9a24a, 0 0 0 5px rgba(90, 56, 24, 0.95), 0 18px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 220, 160, 0.35); }
  50% { box-shadow: 0 0 0 2px #e0c06a, 0 0 0 5px rgba(90, 56, 24, 0.95), 0 18px 46px rgba(0, 0, 0, 0.5), 0 0 28px rgba(240, 193, 74, 0.18), inset 0 1px 0 rgba(255, 220, 160, 0.45); }
}

canvas#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 35 / 17;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background:
    linear-gradient(180deg, #1a5a48 0%, #0e3a30 100%);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

/* Boss 場：外圍改成更深、偏夜的海域 */
#app.raid .stage {
  background:
    radial-gradient(ellipse 65% 40% at 50% 30%, rgba(90, 30, 50, 0.35) 0%, transparent 60%),
    radial-gradient(ellipse 100% 55% at 50% 100%, rgba(8, 4, 12, 0.95) 0%, transparent 58%),
    linear-gradient(165deg, #1a1020 0%, #0c1018 45%, #060810 100%);
}
#app.raid .stage::before {
  --stage-foam: rgba(200, 120, 140, 0.1);
  background:
    linear-gradient(180deg, rgba(160, 60, 80, 0.1) 0%, transparent 24%),
    repeating-linear-gradient(
      180deg,
      transparent 0 18px,
      var(--stage-foam) 18px 19px,
      transparent 19px 38px
    );
}

.side {
  width: 340px;
  flex: none;
  background: var(--panel);
  border-left: 3px solid #6a4a28;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidehead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #120c08;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}

.sidehead strong { display: block; color: #fff4d8; }
.sidehead small { color: #c8b48a; }

.sidehead-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stake-box,
.officer-box {
  position: relative;
}

.stake-btn {
  background: #2a2118;
  color: #c8b48a;
  border: 2px solid #5a4028;
  font-weight: 800;
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.5px;
}

.stake-btn.on {
  background: linear-gradient(180deg, #3a1018, #120408);
  border-color: #a01830;
  color: #f0d0d8;
  box-shadow: inset 0 0 0 1px rgba(160, 24, 48, 0.45);
}

.stake-btn.tier-3,
.stake-btn.tier-4 {
  background: linear-gradient(180deg, #1a060a, #050204);
  border-color: #6a1018;
  color: #e8d0d8;
}

.stake-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 5;
  min-width: 188px;
  padding: 8px;
  background: #1a120c;
  border: 2px solid #6b4524;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stake-menu[hidden] { display: none; }

.stake-menu.on {
  border-color: #a01830;
}

.stake-status,
.stake-bonus {
  margin: 0;
  font-size: 11px;
  line-height: 1.4;
  color: #c8b48a;
}

.stake-bonus {
  color: #e8d0d8;
}

.stake-menu button {
  background: linear-gradient(#ffbf63, #e0862a);
  color: #2a1406;
  border: 2px solid #7a3e10;
  font-weight: 800;
  font-size: 12px;
  padding: 5px 8px;
  cursor: pointer;
}

.officer-btn {
  background: #2a4a6a;
  color: #e8f4ff;
  border: 2px solid #1a3048;
  font-weight: 800;
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
}

.officer-btn.on {
  background: #2d6a34;
  border-color: #1a4020;
  color: #e8ffe8;
}

.officer-btn.off {
  background: #5a3a28;
  border-color: #3a2418;
  color: #ffe8d0;
}

.officer-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 5;
  min-width: 140px;
  padding: 8px;
  background: #1a120c;
  border: 2px solid #6b4524;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.officer-menu[hidden] { display: none; }

.officer-status {
  margin: 0;
  font-size: 11px;
  color: #c8b48a;
}

.officer-menu button {
  background: #e0862a;
  color: #2a1406;
  border: 2px solid #7a3e10;
  font-weight: 800;
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
}

.officer-menu button[data-officer="off"] {
  background: #4a3830;
  color: #f6e7c4;
  border-color: #2a2018;
}

.check-filter-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.checkall {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.crew-filter-btn {
  background: #2a2118;
  color: #f0e2c4;
  border: 2px solid #5a4028;
  font-weight: 800;
  font-size: 12px;
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
}

.crew-filter-btn.on {
  border-color: #e0a020;
  color: #ffe6a8;
}

.crew-filter-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  width: min(220px, 70vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: #1a140e;
  border: 2px solid #7a5a30;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}

.crew-filter-panel[hidden] { display: none; }

.crew-filter-panel label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #c8b48a;
}

.crew-filter-panel select {
  background: #120c08;
  color: #fff4d8;
  border: 1px solid #5a4028;
  padding: 4px 6px;
  font-size: 12px;
}

.crew-filter-panel button {
  background: #4a3830;
  color: #f6e7c4;
  border: 2px solid #2a2018;
  font-weight: 800;
  font-size: 12px;
  padding: 5px 8px;
  cursor: pointer;
}

.cards {
  overflow: auto;
  padding: 10px;
  flex: 1;
}

.cards-empty {
  margin: 18px 8px;
  color: #c8b48a;
  font-size: 13px;
  text-align: center;
}

.card {
  display: grid;
  grid-template-columns: 18px 52px 1fr;
  gap: 8px;
  align-items: center;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--panel-2);
  border: 2px solid #3a2c20;
  border-radius: 6px;
  cursor: pointer;
}

.card.selected { border-color: var(--gold); }
.card.working { background: #243018; }
.card.legendary { box-shadow: inset 3px 0 0 #f0c14a; }
.card.epic { box-shadow: inset 3px 0 0 #c58cff; }
.card.rare { box-shadow: inset 3px 0 0 #6ec8ff; }
.card.common { box-shadow: inset 3px 0 0 #b4aa9e; }

.card input { cursor: pointer; accent-color: #e0a020; }

.portrait {
  width: auto;
  height: 42px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: transparent;
  justify-self: center;
}
canvas.portrait {
  width: 48px;
  height: 48px;
  background: #63b34a;
  border: 2px solid #2e2418;
}

.row1, .row2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.row1 b { font-size: 14px; color: #fff8ea; }

.rarity { font-size: 12px; font-weight: 800; }
.rarity.legendary { color: #ffd15a; }
.rarity.epic { color: #d2a6ff; }
.rarity.rare { color: #7ec8ff; }
.rarity.common { color: #d9d0c4; }
.rarity.super { color: #8ec5ff; }
.rarity.superleg { color: #ff8d7a; }
.rarity.mythic { color: #ff4a5a; }
.card.super { box-shadow: inset 3px 0 0 #3aa0ff; }
.card.superleg { box-shadow: inset 3px 0 0 #e23b3b; }
.card.mythic { box-shadow: inset 3px 0 0 #8a1020; }

.stats-line, .sub, .berth, .abs {
  margin-top: 2px;
  font-size: 12px;
  color: #d9cbb0;
}
.berth {
  color: #9fd6ff;
  line-height: 1.35;
}
.abs {
  color: #c8e4ff;
  line-height: 1.3;
}

.bar {
  margin-top: 4px;
  height: 8px;
  background: #3a2418;
  border-radius: 2px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(#d4f07a, #5ea02a);
}

.bar.low > span { background: linear-gradient(#ffb0a0, #d04030); }

.row2 { margin-top: 4px; }
.state { color: #f0d48a; font-size: 12px; }

.go {
  background: #e0862a;
  color: #2a1406;
  border: 2px solid #7a3e10;
  font-weight: 800;
  padding: 2px 8px;
  cursor: pointer;
}

.replace-hint {
  margin: 0;
  padding: 8px 12px 12px;
  font-size: 12px;
  line-height: 1.45;
  color: #b8a88a;
  border-top: 1px solid var(--line);
}

#toast, #err {
  position: fixed;
  left: 50%;
  top: 74px;
  transform: translateX(-50%);
  background: #24160e;
  color: var(--gold);
  border: 2px solid var(--gold);
  padding: 8px 14px;
  z-index: 60;
  font-weight: 700;
}

#err { color: #ffb0a0; border-color: #e07060; }

@media (max-width: 980px) {
  body { overflow: auto; }
  .layout { flex-direction: column; }
  .side { width: 100%; max-height: 46vh; }
  .frame { width: min(976px, 100%); }
}
