:root {
  --bg0: #0c1412;
  --bg1: #13201c;
  --bg2: #1a2c26;
  --ink: #e8f0ec;
  --muted: #8aa399;
  --line: rgba(232, 240, 236, 0.1);
  --accent: #d4a35c;
  --accent-soft: rgba(212, 163, 92, 0.18);
  --mine: #243f36;
  --theirs: #182822;
  --danger: #e07a6a;
  --font-display: "DM Sans", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --radius: 14px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1f3d34 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #3a2a14 0%, transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1) 45%, #0a100e);
}

body {
  min-height: 100dvh;
}

.app {
  min-height: 100dvh;
  display: grid;
}

.gate {
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
  animation: rise 0.55s ease both;
}

.gate-inner {
  width: min(420px, 100%);
}

.brand,
.brand-sm {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.8rem;
}

.brand-sm {
  margin-bottom: 0.2rem;
  font-size: 0.7rem;
  opacity: 0.9;
}

.gate h1,
.chat-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.lede {
  margin: 0.85rem 0 1.6rem;
  color: var(--muted);
  line-height: 1.5;
  font-size: 1rem;
}

.field {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.field span {
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(8, 14, 12, 0.55);
  color: var(--ink);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
textarea:focus {
  border-color: rgba(212, 163, 92, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  border-radius: 12px;
  transition: transform 0.15s ease, background 0.2s, opacity 0.2s;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  width: 100%;
  padding: 0.95rem 1.1rem;
  background: var(--accent);
  color: #1a1208;
  font-size: 1rem;
}

.btn.primary:hover {
  filter: brightness(1.05);
}

.btn.send {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 14px;
  background: var(--accent);
  color: #1a1208;
  font-size: 1.25rem;
  line-height: 1;
}

.hint {
  margin-top: 1rem;
  color: var(--danger);
  font-size: 0.9rem;
}

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100dvh;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  animation: rise 0.4s ease both;
}

.chat-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(
    180deg,
    rgba(12, 20, 18, 0.92),
    rgba(12, 20, 18, 0.55)
  );
  backdrop-filter: blur(10px);
}

.you {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.messages-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  overflow: hidden;
}

.messages {
  overflow-y: auto;
  padding: 1rem 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  scroll-behavior: auto;
  min-height: 0;
}

.load-older {
  appearance: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 14, 12, 0.35);
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.65rem 1rem;
  cursor: pointer;
}

.load-older:hover {
  background: var(--accent-soft);
}

.load-older:disabled {
  opacity: 0.6;
  cursor: default;
}

.empty-history {
  margin: 0;
  padding: 2rem 1.1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.day-sep {
  align-self: center;
  margin: 0.35rem 0;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: rgba(8, 14, 12, 0.45);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

.msg {
  max-width: min(85%, 520px);
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius);
  background: var(--theirs);
  border: 1px solid var(--line);
  animation: pop 0.28s ease both;
}

.msg.mine {
  align-self: flex-end;
  background: var(--mine);
  border-color: rgba(212, 163, 92, 0.22);
}

.msg .author {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.msg .body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  font-size: 0.98rem;
}

.msg .photo {
  display: block;
  margin: 0.35rem 0 0.15rem;
  max-width: 100%;
  border-radius: 10px;
  cursor: zoom-in;
}

.msg .time {
  margin: 0.35rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: right;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  padding: 0.75rem 1rem 0.5rem;
  border-top: 1px solid var(--line);
  background: rgba(10, 16, 14, 0.85);
  backdrop-filter: blur(12px);
}

.attach {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--ink);
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 1.35rem;
  user-select: none;
}

.attach:hover {
  border-color: rgba(212, 163, 92, 0.45);
}

.composer-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 0.4rem;
}

.composer textarea {
  resize: none;
  min-height: 48px;
  max-height: 140px;
  padding: 0.8rem 0.9rem;
  line-height: 1.35;
}

.preview {
  position: relative;
  width: fit-content;
}

.preview img {
  display: block;
  max-height: 96px;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.preview-clear {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
  font-size: 0.7rem;
  line-height: 1;
}

.status {
  margin: 0;
  padding: 0 1rem 0.75rem;
  min-height: 1.2rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 520px) {
  .msg {
    max-width: 92%;
  }
}
