:root {
  color-scheme: light dark;
  --bg: #f3f1ec;
  --surface: #ffffff;
  --text: #1d2422;
  --muted: #5f6b67;
  --line: #dfdbd2;
  --accent: #0f6e62;
  --on-accent: #ffffff;
  --mine: #d6efe8;
  --error: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101514;
    --surface: #1b2220;
    --text: #e8ece9;
    --muted: #9dabA6;
    --line: #2d3734;
    --accent: #3fb8a4;
    --on-accent: #06221d;
    --mine: #17423b;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  /* Só fontes do sistema: nada externo, para carregar igual no Brasil e na China. */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  display: grid;
  gap: 12px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-card label { color: var(--muted); font-size: 14px; }

.login-card input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-card button, .composer button {
  padding: 10px 16px;
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 8px;
  font-weight: 600;
}

.login-error { margin: 0; color: var(--error); font-size: 14px; }

.chat {
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.status { margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; }
.status.is-online { color: var(--accent); }

.game-toggle {
  align-self: center;
  margin-left: auto;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.game {
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.game-bar, .game-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-status { flex: 1; min-width: 0; margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.game-timer { margin: 0 0 6px; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.game-timer.is-ending { color: var(--error); font-weight: 600; }

.board {
  display: block;
  width: min(100%, calc(38dvh * 4 / 3));
  aspect-ratio: 4 / 3;
  margin: 0 auto;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  touch-action: none;
}

.board.is-drawing { cursor: crosshair; }

.tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 6px;
}

.tool {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.swatch { width: 32px; padding: 0; color: #1d2422; }
.tool.is-selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.size-dot { display: block; background: currentColor; border-radius: 50%; }

.game-footer { margin-top: 6px; }
.game-score { flex: 1; min-width: 0; margin: 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

.game-primary, .game-secondary {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}

.game-primary { background: var(--accent); color: var(--on-accent); border: 0; }
.game-secondary { background: transparent; color: var(--muted); border: 1px solid var(--line); }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 16px;
}

.older {
  display: block;
  margin: 0 auto 12px;
  padding: 6px 12px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}

#list { list-style: none; margin: 0; padding: 0; }

.day {
  width: fit-content;
  margin: 14px auto 10px;
  padding: 2px 10px;
  background: var(--surface);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.message { display: flex; margin-bottom: 8px; }
.message.mine { justify-content: flex-end; }

.bubble {
  max-width: min(82%, 520px);
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.mine .bubble { background: var(--mine); border-color: transparent; }

.primary, .secondary {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.secondary {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid color-mix(in srgb, var(--muted) 30%, transparent);
  color: var(--muted);
  font-size: 14px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.retry {
  padding: 2px 8px;
  background: transparent;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 6px;
}

.typing {
  width: fit-content;
  margin: 4px 0;
  padding: 2px 10px;
  background: var(--surface);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.photo { display: block; margin-bottom: 4px; }
.photo img { display: block; width: 100%; max-width: 300px; min-height: 80px; border-radius: 6px; }

.hair-panel {
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  overflow-y: auto;
  max-height: 60dvh;
}

.hair-top { display: flex; gap: 10px; }
.hair-preview { flex: none; width: 96px; height: auto; border-radius: 8px; align-self: flex-start; }
.hair-options { flex: 1; min-width: 0; }
.hair-title { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.hair-styles { display: flex; flex-wrap: wrap; gap: 6px; }

.hair-chip {
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.hair-chip.is-selected { background: var(--mine); border-color: var(--accent); }

.hair-custom {
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.hair-note { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.hair-error { margin: 6px 0 0; color: var(--error); font-size: 13px; }
.hair-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.hair-open {
  flex: none;
  width: 44px;
  height: 44px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 140px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
