:root {
  --bg: #0b2530;
  --panel: rgba(16, 32, 40, .92);
  --line: #2c4a56;
  --text: #f0ece0;
  --muted: #9fb4bc;
  --accent: #ffd23f;
  --water: #5fd3f5;
  --font: 'VT323', ui-monospace, Consolas, monospace;
  --display: 'Bungee', 'VT323', system-ui, sans-serif;
  --emoji: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 20px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button, a { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#pond, #pond3d { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }
#pond3d[hidden] { display: none; }

/* ---------- thanh trên ---------- */
#top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  pointer-events: none;
}
#top > * { pointer-events: auto; }
.ibtn {
  display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 34px; padding: 0;
  font-family: var(--emoji); font-size: 18px; text-decoration: none;
  background: var(--panel); border: 2px solid var(--line);
}
.ibtn:hover { border-color: var(--accent); }
.ibtn.small { width: 30px; height: 30px; font-size: 15px; }
.money { display: flex; align-items: center; gap: 4px; padding: 0 10px; height: 34px; font-family: var(--emoji); background: var(--panel); border: 2px solid var(--line); }
.money b { font-family: var(--display); font-weight: 400; font-size: 18px; color: var(--accent); min-width: 40px; }
.money.pop b { animation: pop .35s; }
@keyframes pop { 50% { transform: scale(1.35); color: #fff; } }
.quest { flex: 1; min-width: 200px; display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; padding: 2px 10px; background: var(--panel); border: 2px solid var(--line); }
.quest small { font-family: var(--display); font-size: 10px; color: var(--accent); white-space: nowrap; }
.quest span#questText { font-size: 17px; line-height: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quest .bar { grid-column: span 2; margin-top: 2px; }
.bar { display: block; height: 7px; background: #0b1a20; border: 1px solid #000; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd23f, #b8f2a6); transition: width .4s; }
.water { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 8px; font-family: var(--emoji); background: var(--panel); border: 2px solid var(--line); }
.wbar { width: 70px; height: 10px; }
.wbar i { background: linear-gradient(90deg, #5fd3f5, #b8f2a6); }
.wbar.dirty i { background: linear-gradient(90deg, #8a8a3a, #b0a040); }
.sbtn { padding: 2px 8px; font-family: var(--display); font-size: 10px; background: #1d3a46; border: 2px solid #4a7080; }
.sbtn small { font-family: var(--emoji); font-size: 11px; }
.sbtn:disabled { opacity: .45; cursor: default; }
.sbtn.urge { animation: urge 1s infinite; }
@keyframes urge { 50% { border-color: #ff7a7a; background: #4a2a2a; } }
#shopToggle { display: none; }

/* ---------- cửa hàng ---------- */
#shop {
  flex: none; display: flex; gap: 6px; align-items: stretch; overflow-x: auto; overflow-y: hidden;
  padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: #0e1c22; border-top: 2px solid var(--line);
  scrollbar-width: thin;
}
.shop-sep { flex: none; align-self: center; padding: 0 2px; font-family: var(--display); font-size: 9px; color: var(--muted); writing-mode: vertical-rl; transform: rotate(180deg); }
.item {
  position: relative; flex: none; width: 88px; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 3px 2px 2px; background: #17303a; border: 2px solid #2f5260;
}
.item:hover:not(:disabled) { border-color: var(--accent); }
.item canvas { width: 56px; height: 34px; }
.item .nm { font-size: 15px; line-height: 1; white-space: nowrap; }
.item .pr { font-family: var(--emoji); font-size: 13px; color: var(--accent); }
.item .lv { position: absolute; top: 1px; right: 3px; font-size: 13px; color: var(--muted); }
.item:disabled { cursor: default; }
.item.poor { opacity: .55; }
.item.locked { opacity: .45; }
.item.locked canvas { filter: grayscale(1) brightness(.6); }
.item.locked .pr { color: var(--muted); }
.item.maxed .pr { color: #b8f2a6; }
.item.flash { animation: itemFlash .6s; }
@keyframes itemFlash { 50% { border-color: #ff7a7a; } }

/* ---------- cá đang chọn ---------- */
#fishCard {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 4;
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 10px;
  background: var(--panel); border: 2px solid var(--accent); box-shadow: 4px 4px 0 rgba(0, 0, 0, .5);
}
#fishCard[hidden] { display: none; }
.fc-info { display: flex; flex-direction: column; line-height: 1; min-width: 120px; white-space: nowrap; }
#fishCard { max-width: calc(100% - 16px); }
.fc-info b { font-weight: 400; font-size: 20px; color: var(--accent); }
.fc-info small { font-size: 16px; color: var(--muted); }
.sell { padding: 6px 12px; font-family: var(--display); font-size: 14px; color: #111; background: var(--accent); border: 2px solid #000; box-shadow: 2px 2px 0 #000; }
.sell span { font-family: var(--emoji); }
.sell:disabled { opacity: .45; cursor: default; }

#toast {
  position: absolute; left: 50%; top: 64px; transform: translateX(-50%); z-index: 5;
  max-width: 92%; padding: 4px 14px; font-size: 20px; text-align: center; pointer-events: none;
  background: rgba(10, 20, 26, .85); border: 2px solid var(--line); opacity: 0; transition: opacity .25s;
}
#toast.show { opacity: 1; }
#banner {
  position: absolute; left: 0; right: 0; top: 30%; z-index: 4; text-align: center; pointer-events: none;
  font-family: var(--display); font-size: clamp(22px, 4.5vw, 40px); color: #fff; text-shadow: 3px 3px 0 #000; opacity: 0;
}
#banner.show { animation: banner 2.4s ease-out forwards; }
#banner.warn { color: #ff8a5c; }
@keyframes banner { 0% { opacity: 0; transform: scale(1.3); } 12% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- lớp phủ ---------- */
.overlay { position: fixed; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(4, 12, 16, .72); backdrop-filter: blur(2px); }
.overlay.show { display: flex; }
.panel { width: 100%; max-width: 420px; max-height: 100%; overflow-y: auto; padding: 18px 20px; text-align: center; background: #10222a; border: 2px solid #000; box-shadow: 0 0 0 2px var(--line), 8px 8px 0 rgba(0, 0, 0, .5); }
.panel.help { max-width: 640px; text-align: left; }
.panel h2 { margin: 0 0 10px; font-family: var(--display); font-weight: 400; font-size: 26px; color: var(--water); text-align: center; }
.panel ul { margin: 0 0 12px; padding-left: 4px; list-style: none; }
.panel li { margin-bottom: 8px; line-height: 1.1; }
.panel li b { color: var(--accent); font-weight: 400; }
.col { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.big { padding: 10px 26px; font-family: var(--display); font-size: 18px; color: #111; background: var(--accent); border: 2px solid #000; box-shadow: 3px 3px 0 #000; }
.ghost { display: inline-block; min-width: 230px; padding: 7px 16px; font-family: var(--display); font-size: 13px; text-align: center; text-decoration: none; background: none; border: 2px solid var(--line); }
.ghost:hover { border-color: var(--muted); }
.danger { color: #ff9a9a; }
.danger-bg { background: #ff6b6b; }
.save-note, .stats { margin: 0 0 12px; font-size: 17px; color: var(--muted); }
.stats { margin: 12px 0 0; }
.done-ico { font-family: var(--emoji); font-size: 44px; }

/* ---------- màn thấp (điện thoại xoay ngang): cửa hàng thu vào nút 🛒 ---------- */
body.short #shopToggle { display: inline-flex; }
body.short #shop {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; transform: translateY(105%); transition: transform .2s;
  box-shadow: 0 -6px 16px rgba(0, 0, 0, .5);
}
body.short.shop-open #shop { transform: none; }
body.short.shop-open #shopToggle { border-color: var(--accent); background: #3a3416; }
body.short #top { gap: 5px; padding-top: max(4px, env(safe-area-inset-top)); }
body.short .ibtn, body.short .money, body.short .water { height: 30px; }
body.short .quest { min-width: 160px; }
body.short #fishCard { bottom: 6px; }
/* màn hẹp (điện thoại dựng đứng): nhiệm vụ xuống hàng riêng */
@media (max-width: 560px) {
  .quest { order: 10; flex-basis: 100%; }
  .wbar { width: 46px; }
  .item { width: 78px; }
  #toast { top: 96px; }
}
