:root {
  color-scheme: dark;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #000;
  color: #e8e8e3;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #000;
}

body {
  display: flex;
  justify-content: center;
  min-height: 100dvh;
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.game {
  width: min(100%, 430px);
  min-height: 100dvh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #101111;
  border-inline: 1px solid #242626;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  padding: max(14px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid #292b2b;
}

h1,
header p {
  margin: 0;
}

h1 {
  font-size: 0.92rem;
  letter-spacing: 0.12em;
}

header p {
  margin-top: 4px;
  color: #888d8b;
  font-size: 0.72rem;
}

header button {
  padding: 7px 9px;
  border: 1px solid #373a39;
  border-radius: 5px;
  background: transparent;
  color: #afb3b1;
  font-size: 0.72rem;
  cursor: pointer;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 22px 16px 28px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.message {
  max-width: 92%;
  margin: 0 0 22px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
  font-size: 0.9rem;
}

.message::before {
  display: block;
  margin-bottom: 6px;
  color: #6e7471;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message.assistant::before {
  content: "Host";
}

.message.user {
  margin-left: auto;
  padding: 11px 12px;
  border-radius: 7px 7px 2px 7px;
  background: #202322;
  color: #f0f1ed;
}

.message.user::before {
  content: "You";
}

.message.notice {
  color: #a4a9a6;
  font-style: italic;
}

.message.notice::before {
  content: "System";
}

.message.waiting {
  color: #8e9491;
}

#composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid #292b2b;
  background: #101111;
}

textarea {
  width: 100%;
  max-height: 132px;
  resize: none;
  padding: 11px 12px;
  border: 1px solid #363a38;
  border-radius: 6px;
  outline: none;
  background: #181a19;
  color: #f2f2ef;
  line-height: 1.4;
}

textarea:focus {
  border-color: #747b77;
}

#send {
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid #525754;
  border-radius: 6px;
  background: #e2e4df;
  color: #111312;
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 430px) {
  .game {
    border: 0;
  }
}

.message.markdown {
  white-space: normal;
}

.message.markdown > :first-child {
  margin-top: 0;
}

.message.markdown > :last-child {
  margin-bottom: 0;
}

.message.markdown p {
  margin: 0 0 0.8em;
}

.message.markdown h3,
.message.markdown h4,
.message.markdown h5,
.message.markdown h6 {
  margin: 1em 0 0.5em;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
}

.message.markdown ul,
.message.markdown ol {
  margin: 0 0 0.8em;
  padding-left: 1.3em;
}

.message.markdown li {
  margin-bottom: 0.3em;
}

.message.markdown blockquote {
  margin: 0 0 0.8em;
  padding-left: 0.8em;
  border-left: 2px solid #3a3e3c;
  color: #b9bebb;
}

.message.markdown code {
  padding: 0 3px;
  border-radius: 3px;
  background: #1d201f;
  font-size: 0.86em;
}

.message.markdown hr {
  margin: 1em 0;
  border: 0;
  border-top: 1px solid #2c2f2e;
}

.message.waiting .thinking {
  color: #c9ceca;
}

.message.waiting .dots::after {
  content: "";
  display: inline-block;
  width: 3ch;
  white-space: nowrap;
  overflow-wrap: normal;
  text-align: left;
  animation: thinking-dots 1.2s steps(4, end) infinite;
}

.message.waiting .elapsed {
  color: #6e7471;
}

@keyframes thinking-dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

.message.waiting::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 0.3em;
  vertical-align: text-bottom;
  background: #8e9491;
  animation: thinking-cursor 1s steps(2, start) infinite;
}

@keyframes thinking-cursor {
  to { visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .message.waiting .dots::after {
    animation: none;
    content: "…";
  }
  .message.waiting::after {
    animation: none;
  }
}

.message.waiting .pending[hidden],
.message.waiting .stream[hidden] {
  display: none;
}

.message.streaming::after {
  margin-left: 0;
}
