:root {
  color-scheme: light dark;
  --bg: #0b1020;
  --ink: #e8e8ec;
  --muted: #7d8391;
  --line: #2a3145;
  --card: #0e1427;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --ink: #1b1f26;
    --muted: #5a6472;
    --line: #d4d8de;
    --card: #e9ebef;
  }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1020;
  --ink: #e8e8ec;
  --muted: #7d8391;
  --line: #2a3145;
  --card: #0e1427;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --ink: #1b1f26;
  --muted: #5a6472;
  --line: #d4d8de;
  --card: #e9ebef;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  width: 100%;
  max-width: 30rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

main.chatting {
  justify-content: flex-start;
}

h1 {
  font-size: clamp(1.5rem, 5vw, 2.4rem);
  text-align: center;
  margin: 0 1rem 1.1rem 1rem;
  letter-spacing: -0.02em;
}

main.chatting h1 {
  margin: 0.75rem 1rem 0.7rem 1rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--line);
}

.thread {
  display: none;
}

main.chatting .thread {
  flex: 1;
  min-height: 10rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.55rem;
  padding: 0 1rem 0.6rem;
}

.bubble {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.55rem 0.85rem;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.45;
  word-wrap: break-word;
}

.bubble .who {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.75;
}

.bubble.me {
  align-self: flex-end;
  background: var(--ink);
  color: var(--bg);
}

.bubble.them {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
}

form {
  display: flex;
  flex-direction: column;
  padding: 0.6rem 1rem 1.4rem;
  background: var(--bg);
}

main.chatting form {
  border-top: 1px solid var(--line);
}

.row {
  display: flex;
  gap: 0.6rem;
}

#input {
  flex: 1;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  background: var(--card);
  color: var(--ink);
}

#input:focus { outline: 2px solid var(--ink); outline-offset: 0; }

#input:disabled { opacity: 0.6; }

#send {
  border: 0;
  border-radius: 12px;
  min-height: 2.75rem;
  background: var(--ink);
  color: var(--bg);
  padding: 0 1.1rem;
  font-size: 1rem;
  cursor: pointer;
}

#send:hover { filter: brightness(0.92); }

#send:disabled { opacity: 0.6; cursor: default; }

.enter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.8rem;
  min-height: 2.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.enter input {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  accent-color: var(--ink);
}

/* Menu chrome (theme toggle) */
#menu-btn {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  z-index: 10;
}

#menu-btn span {
  width: 16px;
  height: 16px;
  display: block;
  background: repeating-linear-gradient(to bottom, currentColor 0 2px, transparent 2px 6px);
  border-radius: 1px;
  pointer-events: none;
}

#menu {
  position: fixed;
  top: 4.55rem;
  right: 0.75rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  min-width: 210px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  color: var(--ink);
  display: none;
  max-width: calc(100vw - 1.5rem);
  z-index: 10;
}

#menu.open { display: block; }

#menu .sec {
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#menu .row {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

#menu .row button {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  min-height: 2.5rem;
  touch-action: manipulation;
}

/* About footer link (fixed at the bottom, both views) */
.about {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 0.5rem 0 0.9rem;
  font-size: 0.8rem;
  color: var(--muted);
  z-index: 10;
}

.about a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* About page */
.back {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  text-decoration: none;
  touch-action: manipulation;
  z-index: 10;
}

main.page {
  justify-content: flex-start;
  overflow-y: auto;
  padding: 4.5rem 1.25rem 3rem;
}

main.page h1 {
  margin: 0 0 1.25rem;
}

main.page p {
  font-size: 1rem;
  line-height: 1.65;
  color: var(--muted);
  margin: 0 0 1rem;
}