:root {
  --bg: #f2f6f3;
  --surface: #ffffff;
  --surface-soft: #f8fbf9;
  --text: #11231d;
  --muted: #567268;
  --accent: #0f766e;
  --accent-2: #0ea5e9;
  --border: #d2e3db;
  --danger: #b91c1c;
  --shadow: 0 14px 40px rgba(8, 32, 24, 0.08);
}

body.theme-dark {
  --bg: #08100f;
  --surface: #101a18;
  --surface-soft: #14211f;
  --text: #e6f2ee;
  --muted: #9fbab0;
  --accent: #16a394;
  --accent-2: #4bb6f0;
  --border: #243b36;
  --danger: #ff8f8f;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  background:
    radial-gradient(140% 90% at 14% 10%, rgba(15, 118, 110, 0.2) 0%, rgba(15, 118, 110, 0) 58%),
    radial-gradient(120% 80% at 86% 12%, rgba(14, 165, 233, 0.18) 0%, rgba(14, 165, 233, 0) 56%),
    linear-gradient(165deg, #f4faf7 0%, #eef7f3 48%, #edf6fa 100%),
    #f2f6f3;
}

html[data-theme="dark"] {
  background:
    radial-gradient(150% 95% at 12% 8%, rgba(22, 163, 148, 0.12) 0%, rgba(22, 163, 148, 0) 62%),
    radial-gradient(130% 85% at 88% 10%, rgba(75, 182, 240, 0.08) 0%, rgba(75, 182, 240, 0) 60%),
    linear-gradient(180deg, #0a1213 0%, #0a1214 52%, #0a1215 100%),
    #08100f;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(140% 90% at 14% 10%, rgba(15, 118, 110, 0.2) 0%, rgba(15, 118, 110, 0) 58%),
    radial-gradient(120% 80% at 86% 12%, rgba(14, 165, 233, 0.18) 0%, rgba(14, 165, 233, 0) 56%),
    linear-gradient(165deg, #f4faf7 0%, #eef7f3 48%, #edf6fa 100%),
    var(--bg);
  background-attachment: fixed;
}

.site-shell {
  width: calc(100% - 32px);
  max-width: 1260px;
  margin: 20px auto 30px;
}

.age-gate {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 18, 15, 0.65);
  backdrop-filter: blur(2px);
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.age-gate-card {
  width: 100%;
  max-width: 560px;
  padding: 24px;
  border-radius: 20px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.25);
}

.age-gate-card p {
  margin: 10px 0 0;
  color: #2b4a41;
}

.age-gate-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

body.gate-active {
  overflow: hidden;
}

body.gate-active .age-gate {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.topbar {
  padding: 14px 18px;
  margin-bottom: 18px;
  background: linear-gradient(120deg, #ffffff 10%, #f1f8f5 90%);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #cfe1da;
  background: rgba(255, 255, 255, 0.85);
  color: #194236;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.nav-link:hover {
  background: #edf7f3;
  border-color: #b8d2c7;
}

.nav-link-active {
  border-color: #a3d5c7;
  background: #def3ec;
  color: #0f5d56;
}

.topbar-nav .theme-toggle {
  width: auto;
  min-width: 0;
  gap: 8px;
  background: rgba(255, 255, 255, 0.85);
  color: #194236;
  border: 1px solid #cfe1da;
  font-weight: 600;
}

.topbar-nav .theme-toggle:hover {
  background: #edf7f3;
  border-color: #b8d2c7;
  filter: none;
}

.theme-toggle-icon {
  font-size: 0.95rem;
  line-height: 1;
}

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

.brand-logo {
  width: 46px;
  height: 46px;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 1.4rem;
  letter-spacing: 0.03em;
  text-transform: lowercase;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.1rem;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
}

.about-layout {
  display: grid;
}

.chat-column {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.auth-column {
  align-self: start;
  padding: 16px;
}

.chat-panel,
.compose-panel {
  padding: 16px;
  min-width: 0;
}

#messages {
  display: grid;
  gap: 8px;
  max-height: 500px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  min-width: 0;
}

.msg {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px;
  background: var(--surface-soft);
  min-width: 0;
  width: fit-content;
  max-width: 92%;
  justify-self: start;
}

.msg-own {
  justify-self: end;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 26%, var(--border));
}

.msg-own .msg-meta-left b {
  color: var(--accent);
}

.msg-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

.msg-meta-left {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-meta-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.msg-time,
.msg-ttl {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.grid {
  display: grid;
  gap: 10px;
}

.compose-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

input,
textarea,
button {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
}

input,
textarea {
  background: #fff;
}

textarea {
  min-height: 42px;
  line-height: 1.35;
  resize: none;
  overflow: hidden;
  font-family: inherit;
}

.compose-input-row textarea {
  flex: 1 1 auto;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.14);
}

input:disabled,
textarea:disabled {
  background: #eef3f1;
  color: #6f847b;
  cursor: not-allowed;
}

button {
  background: linear-gradient(135deg, var(--accent), #0f9c8f);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  border-color: transparent;
}

button:hover {
  filter: brightness(1.03);
}

.send-inline-btn {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 999px;
  flex: 0 0 auto;
  font-size: 16px;
  line-height: 1;
}

.emoji-toggle-btn {
  font-size: 18px;
}

.emoji-panel {
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 6px;
  background: linear-gradient(120deg, #ffffff 0%, #f6fbf8 100%);
}

.emoji-panel[hidden] {
  display: none;
}

.emoji-item-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.emoji-item-btn:hover {
  filter: none;
  background: #edf7f3;
  border-color: #b8d2c7;
}

.emoji-item-btn:focus-visible {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.14);
}

.btn-secondary {
  background: #e6efea;
  color: #244237;
  border-color: #c5d8cf;
}

.btn-secondary:hover {
  filter: none;
  background: #dbe9e3;
}

.error {
  color: var(--danger);
  min-height: 20px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

.compose-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compose-hint-shortcut {
  text-align: right;
}

.security-footer {
  margin-top: 18px;
  padding: 18px;
  background: linear-gradient(120deg, #ffffff 0%, #f5fbf8 100%);
}

.security-footer h2 {
  margin-bottom: 12px;
}

.thesis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.thesis-item {
  border: 1px solid #b8d2c7;
  border-radius: 22px;
  padding: 22px 20px;
  background: #eef1ef;
}

.thesis-item p {
  margin: 14px 0 0;
  font-size: 0.95rem;
  line-height: 1.35;
  color: #2b4a41;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.thesis-badge {
  display: inline-block;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: #0f766e;
  background: #cfe4de;
  border-radius: 999px;
  padding: 10px 20px;
}

input::placeholder,
textarea::placeholder {
  color: #7a9289;
}

body.theme-dark {
  background:
    radial-gradient(150% 95% at 12% 8%, rgba(22, 163, 148, 0.12) 0%, rgba(22, 163, 148, 0) 62%),
    radial-gradient(130% 85% at 88% 10%, rgba(75, 182, 240, 0.08) 0%, rgba(75, 182, 240, 0) 60%),
    linear-gradient(180deg, #0a1213 0%, #0a1214 52%, #0a1215 100%),
    var(--bg);
  background-attachment: scroll;
}

body.theme-dark .topbar {
  background: linear-gradient(120deg, #111b19 10%, #0e1716 90%);
}

body.theme-dark .security-footer {
  background: linear-gradient(120deg, #111b19 0%, #0f1716 100%);
}

body.theme-dark .emoji-panel {
  background: linear-gradient(120deg, #101a18 0%, #0f1716 100%);
}

body.theme-dark .emoji-item-btn {
  background: #13201d;
  border-color: #2b463f;
  color: #e6f2ee;
}

body.theme-dark .emoji-item-btn:hover {
  background: #1b2a27;
  border-color: #3a5d54;
}

body.theme-dark .nav-link {
  border-color: #2a443e;
  background: rgba(17, 28, 26, 0.9);
  color: #d8ebe4;
}

body.theme-dark .nav-link:hover {
  background: #182523;
  border-color: #35554d;
}

body.theme-dark .nav-link-active {
  border-color: #267a6e;
  background: #16302c;
  color: #a7f0df;
}

body.theme-dark .topbar-nav .theme-toggle {
  background: rgba(17, 28, 26, 0.9);
  color: #d8ebe4;
  border-color: #2a443e;
}

body.theme-dark .topbar-nav .theme-toggle:hover {
  background: #182523;
  border-color: #35554d;
}

body.theme-dark .age-gate-card p {
  color: #b7d2ca;
}

body.theme-dark input,
body.theme-dark textarea {
  background: #0c1514;
  color: var(--text);
  border-color: #2b463f;
}

body.theme-dark input::placeholder,
body.theme-dark textarea::placeholder {
  color: #7f9a91;
}

body.theme-dark input:disabled,
body.theme-dark textarea:disabled {
  background: #101917;
  color: #81988f;
}

body.theme-dark .btn-secondary {
  background: #1a2925;
  color: #d3e6df;
  border-color: #2f4942;
}

body.theme-dark .btn-secondary:hover {
  background: #21332e;
}

body.theme-dark .thesis-item {
  border-color: #2f4a43;
  background: #111d1b;
}

body.theme-dark .thesis-item p {
  color: #c0dad2;
}

body.theme-dark .thesis-badge {
  color: #98f0dd;
  background: #16322d;
}

@media (max-width: 1080px) {
  .topbar-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-nav {
    width: 100%;
    flex-wrap: wrap;
  }

  .nav-link {
    flex: 1 1 auto;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .chat-column,
  .auth-column {
    grid-column: auto;
  }

  .auth-column {
    order: -1;
  }

  .thesis-grid {
    grid-template-columns: 1fr;
  }

  .compose-hint {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .compose-hint-shortcut {
    text-align: left;
  }

  .compose-input-row {
    align-items: stretch;
  }

  .send-inline-btn {
    align-self: flex-end;
  }

  .thesis-badge {
    font-size: 0.82rem;
  }

  .thesis-item p {
    font-size: 0.92rem;
  }

  .age-gate-actions {
    grid-template-columns: 1fr;
  }
}
