:root {
  color-scheme: light;

  font: 16px/1.5 system-ui, sans-serif;

  --page: #f3eee8;
  --text: #2d2623;
  --muted: #766862;

  --message: #eee4dd;
  --message-mine: #ead4cf;

  --input: #fffaf6;
  --control: #f0e5de;
  --control-hover: #e6d8d0;

  --border: #cbbab0;
  --border-strong: #a88d83;

  --accent: #875d55;
  --accent-hover: #734d47;
  --accent-text: #fffaf7;

  --pending: #9b766e;

  --scrollbar: #b9a69c;
  --scrollbar-track: transparent;

  background: var(--page);
  color: var(--text);
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --page: #1d1917;
  --text: #f1e8e3;
  --muted: #b8a79e;

  --message: #322a26;
  --message-mine: #49322f;

  --input: #29221f;
  --control: #332a26;
  --control-hover: #40342f;

  --border: #5d4d47;
  --border-strong: #8f736a;

  --accent: #c28e82;
  --accent-hover: #d2a095;
  --accent-text: #211816;

  --pending: #b88b80;

  --scrollbar: #66534c;
  --scrollbar-track: transparent;
}

/*
 * До загрузки JS используем системную dark-тему.
 * После запуска app.js data-theme станет light или dark.
 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;

    --page: #1d1917;
    --text: #f1e8e3;
    --muted: #b8a79e;

    --message: #322a26;
    --message-mine: #49322f;

    --input: #29221f;
    --control: #332a26;
    --control-hover: #40342f;

    --border: #5d4d47;
    --border-strong: #8f736a;

    --accent: #c28e82;
    --accent-hover: #d2a095;
    --accent-text: #211816;

    --pending: #b88b80;

    --scrollbar: #66534c;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;

  background: var(--page);
  color: var(--text);
}

button,
textarea,
select {
  color: inherit;
}

main {
  width: 100%;
  max-width: 760px;

  height: 100vh;
  height: 100dvh;

  margin: 0 auto;
  padding: 24px;

  display: flex;
  flex-direction: column;

  overflow: hidden;
}

header {
  flex: 0 0 auto;

  display: flex;
  align-items: flex-start;
  justify-content: space-between;

  gap: 24px;
}

.heading {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 32px;
}

header p {
  margin: 6px 0;
}

#status,
footer span {
  color: var(--muted);
  font-size: 13px;
}

/* Theme picker */

.theme-picker {
  flex: 0 0 auto;

  display: flex;
  align-items: center;
  gap: 8px;

  color: var(--muted);
  font-size: 13px;
}

.theme-picker select {
  appearance: none;

  min-width: 94px;

  border: 1px solid var(--border);
  border-radius: 8px;

  background:
    var(--control)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23766862' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat right 10px center;

  padding: 7px 30px 7px 10px;

  font: inherit;

  cursor: pointer;
}

.theme-picker select:hover {
  background-color: var(--control-hover);
}

/* Messages */

#messages {
  flex: 1 1 auto;
  min-height: 0;

  overflow-y: auto;
  overscroll-behavior: contain;

  scrollbar-color: var(--scrollbar) var(--scrollbar-track);

  padding: 12px 2px;

  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 88%;

  align-self: flex-start;

  background: var(--message);

  padding: 10px 14px;

  border-radius: 12px;

  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.mine {
  align-self: flex-end;
  background: var(--message-mine);
}

.message small {
  display: block;

  margin-top: 3px;

  color: var(--muted);
  font-size: 11px;
}

.message.pending {
  border: 1px dashed var(--pending);
}

.message.pending button {
  margin-top: 7px;
}

/* Composer */

form {
  flex: 0 0 auto;
}

textarea {
  display: block;

  width: 100%;
  min-height: 76px;
  max-height: 30dvh;

  resize: vertical;

  border: 1px solid var(--border);
  border-radius: 8px;

  background: var(--input);

  padding: 12px;

  font: inherit;
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

/* Controls */

button {
  border: 0;
  border-radius: 8px;

  background: var(--accent);
  color: var(--accent-text);

  font: inherit;

  padding: 9px 16px;

  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

textarea:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--border-strong);
  outline-offset: 2px;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: 12px;

  margin-top: 8px;
}

@media (max-width: 540px) {
  main {
    padding: 14px;
  }

  header {
    gap: 12px;
  }

  .theme-picker > span {
    display: none;
  }

  .theme-picker select {
    min-width: 90px;
  }

  footer span {
    max-width: 160px;
  }
}
