:root {
  --bg: #f3f5f8; --card: #fff; --text: #17212b; --muted: #707a85; --line: #e3e7ec;
  --accent: #2a7fd4; --accent-2: #e8f1fb; --mine: #d9f2c9; --other: #fff; --danger: #d33b3b;
  --online: #2bb24c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1621; --card: #17212b; --text: #e8edf2; --muted: #8b98a5; --line: #243140;
    --accent: #4ea4f6; --accent-2: #1d2f42; --mine: #2b5278; --other: #182533; --danger: #ef6a6a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

.screen { min-height: 100%; }
.app { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; height: 100dvh; background: var(--bg); }

/* ---------- Игра ---------- */
#game { height: 100dvh; overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.sea {
  position: relative; height: 100%;
  background: linear-gradient(#8fd3ff 0%, #bfe8ff 42%, #2a86c9 42%, #0b3d5c 100%);
  display: flex; flex-direction: column; align-items: center;
}
.sky { position: absolute; inset: 0 0 58% 0; pointer-events: none; }
.sun { pointer-events: auto; position: absolute; top: calc(14px + env(safe-area-inset-top, 0px)); right: 16px;
  font-size: 44px; background: none; border: 0; padding: 4px; line-height: 1; }
.sun:active { transform: scale(.92); }
.cloud { position: absolute; font-size: 42px; opacity: .9; animation: drift 40s linear infinite; }
.c1 { top: 18%; left: -60px; } .c2 { top: 30%; left: -60px; animation-delay: -20s; font-size: 30px; }
@keyframes drift { to { transform: translateX(120vw); } }
.game-head { margin-top: calc(80px + env(safe-area-inset-top, 0px)); text-align: center; color: #0b3d5c; z-index: 1; }
.game-head h1 { margin: 0; font-size: 40px; letter-spacing: 1px; text-shadow: 0 2px 0 #fff8; }
.scores { display: flex; gap: 18px; justify-content: center; font-size: 18px; margin-top: 4px; }
.seal { margin-top: 12vh; font-size: min(38vw, 190px); background: none; border: 0; padding: 0; line-height: 1;
  filter: drop-shadow(0 8px 6px #0004); transition: transform .08s; z-index: 1; }
.seal:active, .seal.bump { transform: scale(.9) rotate(-4deg); }
.hint { color: #e8f6ff; text-align: center; padding: 0 20px; z-index: 1; }
.ice { position: absolute; bottom: 0; left: 0; right: 0; height: 12%; background: #eaf6fbcc; border-radius: 50% 50% 0 0 / 30% 30% 0 0; }
.fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.float { position: absolute; font-size: 26px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px #0008;
  animation: up .8s ease-out forwards; }
@keyframes up { to { transform: translateY(-90px); opacity: 0; } }

/* ---------- Общие элементы ---------- */
.card { background: var(--card); border-radius: 16px; padding: 20px; margin: 16px; box-shadow: 0 2px 12px #0001; }
.auth-card { margin-top: max(10vh, 16px); }
.auth-top { display: flex; align-items: center; justify-content: space-between; }
.auth-top h2 { margin: 0; }
label { display: block; margin: 12px 0; font-size: 14px; color: var(--muted); }
label input { display: block; width: 100%; margin-top: 4px; }
input, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 11px 16px; width: 100%; font-weight: 600; }
.primary:disabled { opacity: .6; }
.danger { background: none; color: var(--danger); border: 1px solid var(--danger); border-radius: 10px; padding: 10px; width: 100%; margin-top: 12px; }
.text-btn { background: none; border: 0; color: var(--accent); padding: 8px; }
.icon-btn { background: none; border: 0; font-size: 22px; padding: 6px 8px; color: var(--text); line-height: 1; border-radius: 8px; }
.icon-btn:active { background: var(--accent-2); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0; font-size: 14px; }
.error:empty { min-height: 0; margin: 0; }
.pad { padding: 12px 16px; overflow-y: auto; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
h3 { margin: 16px 0 6px; font-size: 15px; color: var(--muted); font-weight: 600; }

.tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 3px; margin-top: 14px; }
.tab { flex: 1; background: none; border: 0; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px #0002; }
.main-tabs { margin: 8px 12px; background: var(--line); }

.bar { display: flex; align-items: center; gap: 6px; padding: 8px 8px; padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-left: 6px; }
.bar-title b, .bar-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.panel { flex: 1; overflow-y: auto; }
.search { width: calc(100% - 24px); margin: 4px 12px 8px; display: block; }
.pad .search { width: 100%; margin: 8px 0; }

.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--card); border-bottom: 1px solid var(--line); cursor: pointer; }
.item:active { background: var(--accent-2); }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 18px; position: relative; }
.avatar.on::after { content: ""; position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%;
  background: var(--online); border: 2px solid var(--card); }
.item-body { flex: 1; min-width: 0; }
.item-top { display: flex; justify-content: space-between; gap: 8px; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub.on { color: var(--online); }
.item-time { color: var(--muted); font-size: 12px; flex: none; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; min-width: 20px; text-align: center; }
.item-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.pick .item { cursor: default; }
.pick input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.row-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; color: var(--accent); font-size: 14px; }
.row-btn.del { color: var(--danger); }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }

/* ---------- Сообщения ---------- */
.messages { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.msg { max-width: 80%; padding: 6px 10px 4px; border-radius: 14px; background: var(--other); align-self: flex-start;
  box-shadow: 0 1px 1px #0001; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg-from { font-size: 13px; font-weight: 600; color: var(--accent); }
.msg-text { white-space: pre-wrap; }
.msg-time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.day { align-self: center; font-size: 12px; color: var(--muted); padding: 6px; }
.composer { display: flex; gap: 8px; padding: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--card); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 140px; border-radius: 18px; }
.send { width: 46px; height: 42px; padding: 0; border-radius: 50%; flex: none; }
.composer-err { padding: 0 12px; background: var(--card); margin: 0; }
