/* Один образ: тёмная вода на весь экран, панели - матовое стекло над водой. */
:root {
  --water: #0c3446;
  --glass: rgba(9, 32, 44, 0.82);
  --glass-line: rgba(160, 220, 235, 0.18);
  --ink: #e7f4f6;
  --muted: #9cc0c9;
  --accent: #ffb547;
  --accent-ink: #2a1a00;
  --sea: #1d7f96;
  --danger: #ff7b7b;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--water);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
#tank {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

.top {
  position: fixed; top: 0; left: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 0 max(16px, env(safe-area-inset-left, 0px));
  pointer-events: none; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}
.top h1 { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: 0.01em; }
.top p { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 14px) max(16px, env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.bar .btn { pointer-events: auto; }

.btn {
  font: 600 1rem/1 var(--font); color: var(--ink);
  background: var(--glass); border: 1px solid var(--glass-line); border-radius: 999px;
  padding: 0.8rem 1.25rem; cursor: pointer; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.wide { width: 100%; border-radius: 12px; }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn:focus-visible, .tool:focus-visible, .x:focus-visible, input:focus-visible, .swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 480px) {
  .bar { gap: 6px; }
  .bar .btn { padding: 0.72rem 0.8rem; font-size: 0.92rem; }
}

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 66px); transform: translateX(-50%);
  margin: 0; width: max-content; max-width: min(92vw, 460px); padding: 0.55rem 0.95rem; border-radius: 10px;
  background: var(--glass); border: 1px solid var(--glass-line); text-align: center; font-size: 0.92rem;
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
.toast.show { opacity: 1; }

.quick {
  position: fixed; z-index: 6; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 78px); transform: translateX(-50%);
  display: flex; gap: 12px; align-items: center; width: max-content; max-width: calc(100vw - 32px);
  padding: 10px 14px; border-radius: 14px; background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.quick img { width: auto; max-width: 120px; max-height: 72px; flex: none; }
.quick-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.quick-body p { margin: 0; font-size: 0.95rem; overflow-wrap: anywhere; }
.quick-row { display: flex; gap: 8px; }

.card {
  position: fixed; z-index: 5; width: min(260px, calc(100vw - 32px));
  padding: 12px 14px; border-radius: 12px; background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.card strong { display: block; font-size: 1.05rem; overflow-wrap: anywhere; }
.card p { margin: 4px 0 0; color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }
.card-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.card .desc { color: var(--ink); font-style: italic; }
.like {
  font: 600 0.9rem var(--font); color: var(--ink); background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-line); border-radius: 8px; padding: 0.35rem 0.7rem; cursor: pointer; font-variant-numeric: tabular-nums;
}
.like.on { color: #ff7aa8; border-color: rgba(255, 122, 168, 0.5); }
.like.big { font-size: 1.05rem; padding: 0.5rem 0.9rem; align-self: flex-start; }

/* окно рыбы: лайки, описание, сообщения */
.panel-in { gap: 10px; }
.panel-in h3 { margin: 4px 0 0; font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.p-top { display: flex; gap: 14px; align-items: center; }
.p-top img { width: 40%; max-width: 180px; height: auto; flex: none; }
.p-meta { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.p-meta p { margin: 0; color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.p-desc { margin: 0; font-style: italic; overflow-wrap: anywhere; white-space: pre-wrap; }
.p-descedit { display: flex; flex-direction: column; gap: 6px; }
.p-descedit label { color: var(--muted); font-size: 0.85rem; }
.p-descedit .tool { align-self: flex-start; }
.panel-in textarea, .p-send input {
  font: 0.95rem/1.4 var(--font); color: var(--ink); background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-line); border-radius: 8px; padding: 0.5rem 0.65rem; width: 100%; resize: vertical;
}
.msgs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 34vh; overflow-y: auto; }
.msgs li { background: rgba(255, 255, 255, 0.05); border-radius: 10px; padding: 8px 10px; }
.msgs li.empty { color: var(--muted); background: none; padding: 4px 0; }
.m-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.m-head b { overflow-wrap: anywhere; }
.m-head span { color: var(--muted); font-size: 0.78rem; }
.msgs p { margin: 3px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.m-acts { display: flex; gap: 10px; margin-top: 4px; }
.m-acts button { font: 0.8rem var(--font); color: var(--muted); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.p-send { display: grid; grid-template-columns: 1fr; gap: 8px; }
.p-send .btn { border-radius: 10px; }
.p-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tool.danger { color: var(--danger); border-color: rgba(255, 123, 123, 0.45); }
.card .flip { font: 600 0.85rem var(--font); color: var(--ink); background: rgba(255, 255, 255, 0.08); border: 1px solid var(--glass-line); border-radius: 8px; padding: 0.35rem 0.7rem; cursor: pointer; }
.card .del { font: 600 0.85rem var(--font); color: var(--danger); background: none; border: 1px solid currentColor; border-radius: 8px; padding: 0.35rem 0.7rem; cursor: pointer; }

.sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; background: rgba(2, 12, 18, 0.55); }
.sheet-in {
  width: min(600px, 100%); max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 16px) max(16px, env(safe-area-inset-left, 0px));
  background: #0f2b3a; border: 1px solid var(--glass-line); border-radius: 18px 18px 0 0;
}
@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-in { border-radius: 18px; padding-left: 20px; padding-right: 20px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.x { font: 400 1.7rem/1 var(--font); color: var(--muted); background: none; border: 0; cursor: pointer; padding: 0 6px; }

.canvas-wrap { position: relative; }
#draw {
  display: block; width: 100%; height: auto; aspect-ratio: 8 / 5; border-radius: 12px;
  background: linear-gradient(#2b8ba4, #155b74); touch-action: none; cursor: crosshair;
}
.hint { position: absolute; right: 10px; bottom: 8px; color: rgba(255, 255, 255, 0.65); font-size: 0.8rem; pointer-events: none; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.25); cursor: pointer; padding: 0; }
.swatch[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

.tools { display: flex; flex-wrap: wrap; gap: 6px; }
.tool {
  font: 500 0.88rem/1 var(--font); color: var(--ink); background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-line); border-radius: 8px; padding: 0.5rem 0.7rem; cursor: pointer;
}
.tool.on { background: var(--sea); border-color: transparent; }
.photo { position: relative; overflow: hidden; }
.photo input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
/* кнопка «Выпустить» всегда видна, даже если окно рисования выше экрана телефона */
.sheet-in > .btn.wide { position: sticky; bottom: 0; box-shadow: 0 -10px 16px #0f2b3a; }
@media (max-height: 700px) { #draw { max-height: 34vh; width: auto; max-width: 100%; margin: 0 auto; } }
.fields label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 0.85rem; min-width: 0; }
.fields input {
  font: 1rem var(--font); color: var(--ink); background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-line); border-radius: 8px; padding: 0.55rem 0.7rem; width: 100%;
}
.msg { margin: 0; min-height: 1.3em; color: var(--accent); font-size: 0.9rem; }

/* угол: звук и меню */
.corner {
  position: fixed; z-index: 4; display: flex; gap: 8px;
  top: calc(env(safe-area-inset-top, 0px) + 12px); right: max(12px, env(safe-area-inset-right, 0px));
}
.ibtn {
  position: relative; width: 42px; height: 42px; display: grid; place-items: center; padding: 0; cursor: pointer;
  color: var(--ink); background: var(--glass); border: 1px solid var(--glass-line); border-radius: 50%;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.ibtn svg { width: 20px; height: 20px; }
.ibtn.on { color: var(--accent); }
.ibtn:focus-visible, .menu button:focus-visible, .grid li:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #ff5d8f; color: #fff; font: 700 0.72rem/18px var(--font); text-align: center; font-variant-numeric: tabular-nums;
}
.badge.inline { position: static; margin-left: 10px; display: inline-block; }
.menu {
  position: fixed; z-index: 8; display: flex; flex-direction: column; min-width: 200px; padding: 6px;
  top: calc(env(safe-area-inset-top, 0px) + 60px); right: max(12px, env(safe-area-inset-right, 0px));
  border-radius: 12px; background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.menu button {
  display: flex; align-items: center; justify-content: space-between; text-align: left; cursor: pointer;
  font: 500 0.98rem/1.2 var(--font); color: var(--ink); background: none; border: 0; border-radius: 8px; padding: 0.75rem 0.8rem;
}
.menu button:hover { background: rgba(255, 255, 255, 0.08); }

/* «Мои рыбы» */
.sub { margin: 0; color: var(--muted); font-size: 0.88rem; }
.flist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.flist li { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
.flist li.empty { display: block; padding: 4px 0; background: none; color: var(--muted); }
.flist img { width: 76px; height: 50px; object-fit: contain; flex: none; }
.fi-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.fi-body b { overflow-wrap: anywhere; }
.fi-body p { margin: 0; color: var(--muted); font-size: 0.84rem; overflow-wrap: anywhere; }
.fi-body .new { color: #ff9fc0; font-weight: 600; }
.fi-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

/* «Глубина» */
.tabs { display: flex; gap: 6px; }
.tabs .tool { flex: 1; padding: 0.6rem 0.7rem; }
.tabs .tool[aria-selected="true"] { background: var(--sea); border-color: transparent; }

/* «Поддержать» и «Откуда заходят» */
.donate, .stats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.donate li { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
.donate code { display: block; width: 100%; box-sizing: border-box; padding: 8px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.25); font-size: 0.85rem; word-break: break-all; user-select: all; }
.stats li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); }
.stats .flag { font-size: 1.3rem; width: 1.6rem; text-align: center; }
.stats .cn { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.stats .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.stats .ip { font: 500 0.92rem/1.2 ui-monospace, Menlo, Consolas, monospace; color: var(--ink); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; overflow-wrap: anywhere; min-width: 0; flex: 0 1 auto; }
.stats .cn { color: var(--muted); font-size: 0.85rem; text-align: right; }
.sub a { color: var(--ink); }
.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
.grid li {
  display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; text-align: center;
  padding: 10px 8px; border-radius: 12px; background: rgba(255, 255, 255, 0.05);
}
.grid li.empty { grid-column: 1 / -1; background: none; color: var(--muted); text-align: left; padding: 4px 0; }
.grid li[role="button"] { cursor: pointer; }
.grid li[role="button"]:hover { background: rgba(255, 255, 255, 0.1); }
.grid img { width: 100%; max-width: 120px; height: 70px; object-fit: contain; }
.grid li.gone img { filter: grayscale(0.45) brightness(0.85); }
.grid b { font-size: 0.92rem; overflow-wrap: anywhere; }
.grid span { color: var(--muted); font-size: 0.8rem; overflow-wrap: anywhere; }

/* режим ТВ: только вода */
body.tv .top, body.tv .bar, body.tv .corner, body.tv .card, body.tv .menu, body.tv .quick { display: none !important; }
body.tv-idle, body.tv-idle #tank { cursor: none; }
.tvexit { position: fixed; z-index: 12; top: calc(env(safe-area-inset-top, 0px) + 14px); right: max(14px, env(safe-area-inset-right, 0px)); }
.tvhint {
  position: fixed; z-index: 3; margin: 0; padding: 0.45rem 0.85rem; border-radius: 10px; pointer-events: none;
  right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  background: rgba(9, 32, 44, 0.55); color: var(--ink); font-size: 1rem;
}

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
