:root {
  color-scheme: dark;
  --bg: #0f1216;
  --panel: #151a20;
  --panel-2: #1b222a;
  --text: #e8edf2;
  --muted: #8b98a5;
  --line: #26303a;
  --fish: #5cc8c2;
  --fish-2: #2f8f8a;
  --danger: #ff7a7a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(92, 200, 194, .14), transparent 60%),
    radial-gradient(700px 500px at 110% 10%, rgba(92, 200, 194, .07), transparent 55%),
    var(--bg);
}

.view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(27, 34, 42, .96), rgba(21, 26, 32, .96));
  box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand.small { gap: 10px; }

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--fish), var(--fish-2));
  color: #06211f;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 8px 24px rgba(92, 200, 194, .22);
}

.brand.small .avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  font-size: 16px;
}

h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: .02em;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

label {
  display: block;
  margin: 24px 0 8px;
  color: var(--muted);
  font-size: 13px;
}

input, textarea, button {
  font: inherit;
}

input[type="password"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0d1116;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input[type="password"]:focus, textarea:focus {
  border-color: rgba(92, 200, 194, .7);
  box-shadow: 0 0 0 3px rgba(92, 200, 194, .12);
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 14px;
  padding: 11px 16px;
  transition: transform .08s ease, filter .15s ease, opacity .15s ease;
}

button:active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .5; }

.primary {
  width: 100%;
  margin-top: 14px;
  background: linear-gradient(145deg, var(--fish), var(--fish-2));
  color: #041d1b;
  font-weight: 800;
}

.primary:hover:not(:disabled) { filter: brightness(1.06); }

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 8px 12px;
}

.error {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.fineprint {
  margin: 16px 0 0;
  color: #66727e;
  font-size: 12px;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(38, 48, 58, .8);
  background: rgba(15, 18, 22, .88);
  backdrop-filter: blur(14px);
}

.brand.small strong {
  display: block;
  font-size: 15px;
}

.brand.small span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.messages {
  flex: 1;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 18px 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.day-chip {
  align-self: center;
  color: var(--muted);
  font-size: 11px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(21, 26, 32, .8);
}

.bubble {
  max-width: min(86%, 560px);
  padding: 10px 13px 7px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}

.bubble.bot {
  align-self: flex-start;
  border-top-left-radius: 6px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}

.bubble.user {
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  border-color: rgba(92, 200, 194, .35);
  background: linear-gradient(160deg, rgba(92, 200, 194, .94), rgba(47, 143, 138, .94));
  color: #03201e;
}

.bubble.user time {
  color: rgba(3, 32, 30, .55);
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble time {
  display: block;
  margin-top: 4px;
  color: #66727e;
  font-size: 10px;
  text-align: right;
}

.composer {
  position: sticky;
  bottom: 0;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(38, 48, 58, .8);
  background: rgba(15, 18, 22, .92);
  backdrop-filter: blur(14px);
}

.composer-row {
  width: min(760px, 100%);
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.composer textarea {
  resize: none;
  max-height: 140px;
  min-height: 46px;
  line-height: 1.45;
}

.composer .primary {
  width: auto;
  margin: 0;
  min-height: 46px;
  padding-inline: 20px;
  flex: 0 0 auto;
}

.hint {
  width: min(760px, 100%);
  margin: 8px auto 0;
  color: #66727e;
  font-size: 11px;
  text-align: center;
}

[hidden] { display: none !important; }

@media (max-width: 520px) {
  .login-card { padding: 22px; border-radius: 18px; }
  h1 { font-size: 23px; }
  .bubble { max-width: 92%; }
}

.top-actions { display: flex; align-items: center; gap: 6px; }
.game-link { display: grid; place-items: center; text-decoration: none; }

.connection-bar {
  width: min(760px, calc(100% - 24px));
  margin: 8px auto 0;
  padding: 8px 12px;
  border: 1px solid rgba(255, 176, 92, .24);
  border-radius: 11px;
  background: rgba(255, 176, 92, .08);
  color: #ffc987;
  font-size: 12px;
  text-align: center;
}

.connection-bar.error {
  border-color: rgba(255, 122, 122, .3);
  background: rgba(255, 122, 122, .09);
  color: #ffb0b0;
}

.bubble.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 64px;
  min-height: 36px;
  padding: 10px 14px;
}

.bubble.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8fa6ad;
  animation: fish-typing 1.1s infinite ease-in-out;
}

.bubble.typing span:nth-child(2) { animation-delay: .15s; }
.bubble.typing span:nth-child(3) { animation-delay: .3s; }

@keyframes fish-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.scroll-bottom {
  position: fixed;
  right: 18px;
  bottom: calc(104px + env(safe-area-inset-bottom));
  z-index: 4;
  padding: 8px 12px;
  border: 1px solid rgba(92, 200, 194, .3);
  border-radius: 999px;
  background: rgba(15, 22, 28, .94);
  color: #a8e9e2;
  font: inherit;
  font-size: 11px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  cursor: pointer;
}

.hint.error {
  color: #ff9b9b;
}