:root {
  --glass: rgba(6, 28, 44, 0.55);
  --glass-strong: rgba(8, 30, 46, 0.86);
  --line: rgba(190, 235, 255, 0.16);
  --text: #eaf6fc;
  --muted: #9cbccc;
  --accent: #ff9a5c;
  --accent-2: #ffcf7a;
  --accent-ink: #3a1600;
  --danger: #ff7b6b;
  --good: #6be3a6;
  --radius: 18px;
  --sheet: #0d2638;
  --sheet-2: #12324a;
  --hd-bg: #12324a; --hd-text: #eaf6fc; --hd-muted: #9cbccc; --hd-field: rgba(0, 0, 0, 0.25); --hd-accent: #ff9a5c; --hd-accent-ink: #3a1600; --hd-shadow: rgba(255, 140, 70, 0.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #031a28; }
body {
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
canvas#tank { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- top bar ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 18px 0; pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { display: flex; gap: 10px; align-items: center; color: var(--text); text-decoration: none; }
.brand img { border-radius: 11px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
.brand span { display: grid; line-height: 1.2; text-shadow: 0 1px 10px rgba(0, 0, 0, 0.45); }
.brand b { font-size: 18px; letter-spacing: -0.01em; }
.brand small { font-size: 12.5px; color: var(--muted); }
.top-right { display: flex; gap: 8px; align-items: center; position: relative; }
.stats { display: flex; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: 13.5px; white-space: nowrap; color: var(--text);
}
.chip svg { width: 16px; height: 16px; color: var(--muted); }
.chip b { font-variant-numeric: tabular-nums; font-weight: 650; }
.chip.warn { border-color: rgba(190, 220, 90, 0.5); }
.chip.warn svg { color: #c6e06a; }
.btn-chip:hover { background: rgba(20, 60, 85, 0.7); }
.btn-chip svg { color: var(--accent-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 10px var(--good); }
.account {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px 0 4px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 700; font-size: 14px;
  box-shadow: 0 6px 20px rgba(255, 140, 70, 0.35);
}
.account.in { background: var(--glass); color: var(--text); border: 1px solid var(--line); box-shadow: none; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 13.5px; font-weight: 800;
  background: rgba(255, 255, 255, 0.35); color: var(--accent-ink);
}
.account.in .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.menu {
  position: absolute; right: 0; top: 46px; width: 240px; padding: 8px; border-radius: 16px; z-index: 6;
  background: var(--glass-strong); border: 1px solid var(--line); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45); animation: pop 0.16s ease both;
}
.menu-head { margin: 6px 10px 2px; display: grid; }
.menu-head small, .menu-quota { color: var(--muted); font-size: 12.5px; }
.menu-quota { margin: 2px 10px 8px; }
.menu button { display: block; width: 100%; text-align: left; padding: 9px 10px; border: 0; border-radius: 10px; background: none; font-size: 14px; }
.menu button:hover { background: rgba(255, 255, 255, 0.08); }
.menu .danger { color: var(--danger); }
.menu-link { display: block; padding: 9px 10px; border-radius: 10px; color: var(--accent-2); text-decoration: none; font-size: 14px; font-weight: 650; }
.menu-link:hover { background: rgba(255, 255, 255, 0.08); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }

/* ---------- activity feed ---------- */
.feed { position: fixed; left: 18px; top: calc(max(14px, env(safe-area-inset-top)) + 58px); width: min(340px, calc(100vw - 36px)); pointer-events: none; z-index: 2; }
#log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#log li {
  font-size: 13px; padding: 7px 12px; border-radius: 12px; width: fit-content; max-width: 100%;
  background: rgba(4, 22, 34, 0.5); border: 1px solid rgba(190, 235, 255, 0.1); color: #d6ecf5;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: rise 0.45s ease both;
}
#log li:nth-child(2) { opacity: 0.75; }
#log li:nth-child(3) { opacity: 0.5; }
#log li:nth-child(n + 4) { display: none; }
#log li time { color: var(--muted); font-size: 11.5px; margin-left: 6px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- action dock ---------- */
.dock {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 3;
  display: flex; gap: 4px; padding: 6px; border-radius: 24px;
  background: var(--glass-strong); border: 1px solid var(--line); box-shadow: 0 18px 50px rgba(0, 10, 20, 0.5);
  backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
}
.act {
  display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 16px;
  border: 0; border-radius: 18px; background: transparent; font-size: 14px; font-weight: 650; color: var(--text);
}
.act svg { width: 20px; height: 20px; }
.act:hover { background: rgba(255, 255, 255, 0.07); }
.act.primary { background: linear-gradient(135deg, var(--accent), #ffb36b); color: var(--accent-ink); box-shadow: 0 6px 18px rgba(255, 140, 70, 0.35); }
.act.primary svg { fill: currentColor; stroke: none; }
.act:disabled { opacity: 0.5; cursor: progress; }
:is(.act, .btn, .seg button, .swatches button, .account, .chip, .tabs button):focus-visible { outline: 3px solid #6fd3ff; outline-offset: 2px; }

.placing {
  position: fixed; left: 50%; top: 84px; transform: translateX(-50%); z-index: 6;
  display: flex; gap: 14px; align-items: center; padding: 10px 16px; border-radius: 999px;
  background: var(--glass-strong); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); font-size: 14px;
}
.link { border: 0; background: none; color: var(--accent); font-weight: 700; padding: 0; }

/* ---------- fish card ---------- */
.card {
  position: fixed; z-index: 5; width: 280px; padding: 14px 16px 16px; border-radius: 22px;
  background: var(--glass-strong); border: 1px solid var(--line); box-shadow: 0 24px 60px rgba(0, 10, 20, 0.55);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); animation: pop 0.18s ease both;
}
.card canvas { display: block; width: 100%; height: auto; border-radius: 14px; background: radial-gradient(120% 90% at 50% 20%, #1a7aa6, #0a3b57); }
.card h2 { margin: 12px 0 0; font-size: 20px; letter-spacing: -0.01em; word-break: break-word; }
.card-by { margin: 2px 0 10px; color: var(--muted); font-size: 13px; }
.card dl { margin: 0; display: grid; gap: 4px; font-size: 13.5px; }
.card dl div { display: flex; justify-content: space-between; gap: 10px; }
.card dt { color: var(--muted); }
.card dd { margin: 0; text-align: right; font-weight: 600; }
.card .hungry { color: var(--accent-2); }
.card .starving { color: var(--danger); }
.card-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.heart { display: inline-flex; align-items: center; gap: 6px; }
.heart svg { color: #ff7d9a; }
.heart.on svg { fill: #ff7d9a; }
.card-mine { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.card-mine form { display: flex; gap: 6px; }
.card-mine input { flex: 1; min-width: 0; width: 0; padding: 8px 11px; }
.x { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 26px; line-height: 1; color: var(--muted); padding: 2px 6px; z-index: 1; }
.x:hover { color: var(--text); }

/* ---------- sheets ---------- */
dialog.sheet {
  width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 26px;
  background: linear-gradient(180deg, var(--sheet-2), var(--sheet)); color: var(--text); box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6);
}
dialog.sheet.narrow { width: min(420px, calc(100vw - 24px)); }
dialog.sheet[open] { animation: pop 0.2s ease both; }
dialog.sheet::backdrop { background: rgba(1, 12, 20, 0.55); backdrop-filter: blur(3px); }
dialog.sheet form { padding: 20px 22px 22px; }
dialog.sheet header { display: flex; justify-content: space-between; align-items: center; position: relative; }
dialog.sheet h2 { margin: 0; font-size: 21px; letter-spacing: -0.01em; }
dialog.sheet header .x { position: static; }
#preview { display: block; width: 100%; height: auto; margin: 14px 0 16px; border-radius: 18px; background: radial-gradient(120% 100% at 50% 10%, #1d86b4, #083a55); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.field { display: grid; gap: 7px; margin: 0 0 12px; padding: 0; border: 0; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; }
.grid .field { margin: 0; }
.field legend { padding: 0; margin-bottom: 7px; }
.field.wide { grid-column: 1 / -1; }
input:not([type="range"]) {
  font: inherit; font-weight: 500; color: var(--text); background: rgba(0, 0, 0, 0.22);
  padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line); outline: none; min-width: 0;
}
input:focus { border-color: #6fd3ff; box-shadow: 0 0 0 3px rgba(111, 211, 255, 0.2); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04);
  font-size: 13.5px; font-weight: 600; color: var(--text);
}
.seg button[aria-pressed="true"] { background: var(--text); color: #08283b; border-color: var(--text); }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.swatches button, .swatches label { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.18); padding: 0; position: relative; }
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--sheet), 0 0 0 4px var(--text); }
.swatches label { overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); cursor: pointer; }
.swatches input[type="color"] { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; padding: 0; }
.hint { color: var(--muted); font-size: 13.5px; margin: 10px 0 14px; }
.hint.err { color: var(--danger); font-weight: 600; margin: 4px 0 0; }
dialog footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.btn {
  padding: 10px 18px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05);
  font-weight: 700; font-size: 14.5px; color: var(--text);
}
.btn:hover { background: rgba(255, 255, 255, 0.1); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ffb36b); color: var(--accent-ink); border-color: transparent; }
.btn.wide { width: 100%; }
.btn.small { padding: 7px 13px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; margin-bottom: 16px; border-radius: 14px; background: rgba(0, 0, 0, 0.25); }
.tabs button { border: 0; background: none; padding: 9px; border-radius: 10px; font-weight: 650; color: var(--muted); }
.tabs button[aria-selected="true"] { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.decor-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.decor-grid button {
  display: grid; gap: 4px; justify-items: center; padding: 10px 4px 12px; border-radius: 16px;
  border: 1px solid var(--line); background: radial-gradient(120% 100% at 50% 0%, #1a7aa6, #0a3b57); color: var(--text); font-size: 13px; font-weight: 650;
}
.decor-grid button:hover { border-color: var(--accent); transform: translateY(-1px); }
.decor-grid canvas { width: 100%; max-width: 110px; height: auto; }
.rules { margin: 14px 0 0; padding-left: 18px; display: grid; gap: 9px; color: #d3e6ef; }
.rules b { color: var(--text); }
.board-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.board-grid section { padding: 12px 14px; border-radius: 16px; background: rgba(0, 0, 0, 0.2); border: 1px solid var(--line); }
.board-grid h3 { margin: 0 0 8px; font-size: 13px; color: var(--accent-2); text-transform: uppercase; letter-spacing: 0.04em; }
.rank { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; counter-reset: r; font-size: 14px; }
.rank li { display: flex; gap: 8px; align-items: baseline; counter-increment: r; }
.rank li::before { content: counter(r); width: 18px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.rank li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank li small { color: var(--muted); white-space: nowrap; }
.rank .empty { color: var(--muted); }
.rank .empty::before { content: none; }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, calc(-100% - 40px)); z-index: 20; max-width: calc(100vw - 32px);
  padding: 11px 18px; border-radius: 14px; background: #f3fbff; color: #062236; font-size: 14px; font-weight: 650;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.4); transition: transform 0.3s ease, visibility 0.3s; pointer-events: none; visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.toast.err { background: #ffe4df; color: #6b1608; }

@media (max-width: 760px) {
  .btn-chip span { display: none; }
  .btn-chip { padding: 0 10px; }
}
@media (max-width: 640px) {
  .top { flex-wrap: wrap; padding: max(12px, env(safe-area-inset-top)) 12px 0; gap: 8px; }
  .brand small { display: none; }
  .brand b { font-size: 16px; }
  .brand img { width: 32px; height: 32px; }
  .top-right { width: 100%; justify-content: space-between; }
  .stats { gap: 4px; }
  .chip { height: 30px; padding: 0 9px; font-size: 12.5px; }
  .account { position: absolute; right: 0; top: -44px; height: 34px; font-size: 13px; }
  .account #account-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .avatar { width: 26px; height: 26px; }
  .menu { top: -4px; }
  .feed { left: 12px; top: auto; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 76px); }
  #log { flex-direction: column-reverse; }
  #log li:nth-child(n + 3) { display: none; }
  .dock { width: calc(100vw - 20px); justify-content: space-between; bottom: max(12px, env(safe-area-inset-bottom)); }
  .act { flex: 1; flex-direction: column; gap: 2px; height: 54px; padding: 0 2px; font-size: 11.5px; justify-content: center; }
  .grid, .board-grid { grid-template-columns: minmax(0, 1fr); }
  .card { left: 10px !important; right: 10px; top: auto !important; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 76px); width: auto; }
  .card canvas { max-height: 120px; object-fit: contain; }
  .placing { top: 100px; }
  .toast { top: 100px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
