:root {
  color-scheme: light dark;
  --bg: #f5f4f1;
  --surface: #ffffff;
  --fg: #1a1a1a;
  --fg-muted: #6b6b68;
  --bubble-user: #1f3a5f;
  --bubble-user-fg: #ffffff;
  --bubble-bot: #ffffff;
  --bubble-bot-fg: #1a1a1a;
  --border: #e4e2dc;
  --accent: #1f3a5f;
  --accent-2: #a97e3f;
  --danger: #c0432f;
  --shadow: 0 1px 2px rgba(20, 20, 15, 0.04), 0 8px 24px rgba(20, 20, 15, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --surface: #1d1f26;
    --fg: #ececec;
    --fg-muted: #9a9a9d;
    --bubble-user: #3a5c8c;
    --bubble-bot: #21232b;
    --bubble-bot-fg: #ececec;
    --border: #33353f;
    --accent: #5b83b8;
    --accent-2: #c79a53;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1 {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: -0.01em;
}

[hidden] {
  display: none !important;
}

/* ---------- key gate ---------- */

#key-gate {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 20% 15%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 45%),
    radial-gradient(circle at 85% 80%, color-mix(in srgb, var(--accent-2) 10%, transparent), transparent 40%),
    var(--bg);
}

.mark {
  font-size: 2.25rem;
  line-height: 1;
  margin-bottom: 0.75rem;
}

.mark.small {
  font-size: 1.5rem;
  margin: 0;
  flex-shrink: 0;
}

.key-card {
  max-width: 420px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  padding: 2rem 1.75rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.key-card h1 {
  font-size: 1.4rem;
  margin: 0 0 0.6rem;
}

.key-card p {
  font-size: 0.875rem;
  color: var(--fg-muted);
  margin: 0 0 1.25rem;
  line-height: 1.5;
}

#key-form {
  display: flex;
  gap: 0.5rem;
}

#key-input {
  flex: 1;
  min-width: 0;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  padding: 0.65rem 0.85rem;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#key-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.key-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin: 0.85rem 0 0;
  font-weight: 500;
}

.key-hint {
  margin-top: 1.25rem !important;
  font-size: 0.75rem !important;
  margin-bottom: 0 !important;
}

.key-hint a {
  color: var(--accent);
  text-decoration: none;
}

.key-hint a:hover {
  text-decoration: underline;
}

/* ---------- app shell ---------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  max-width: 720px;
  margin: 0 auto;
}

header h1 {
  margin: 0 0 0.2rem;
  font-size: 1.15rem;
}

header p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--fg-muted);
  line-height: 1.4;
}

/* ---------- chat ---------- */

main#chat {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

#empty-state {
  margin: auto 0;
  text-align: center;
  padding: 2rem 0;
}

.empty-title {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-size: 1.1rem;
  margin: 0 0 0.3rem;
}

.empty-sub {
  font-size: 0.85rem;
  color: var(--fg-muted);
  margin: 0 0 1.25rem;
}

.chip-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.chip {
  font: inherit;
  font-size: 0.82rem;
  max-width: 420px;
  text-align: left;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.chip:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble {
  max-width: 78%;
  padding: 0.65rem 0.95rem;
  border-radius: 1rem;
  line-height: 1.45;
  font-size: 0.93rem;
  white-space: pre-wrap;
  animation: rise 0.18s ease-out;
}

.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-fg);
  border-bottom-right-radius: 0.25rem;
}

.bubble.bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  color: var(--bubble-bot-fg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 0.25rem;
  box-shadow: var(--shadow);
}

.bubble.answer {
  border-left: 3px solid var(--accent-2);
}

.answer-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 0.35rem;
}

.answer-tag a {
  color: inherit;
  text-decoration: none;
}

.answer-tag a:hover {
  text-decoration: underline;
}

.answer-text {
  white-space: pre-wrap;
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  padding: 0.15rem 0;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  animation: bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-3px); opacity: 0.9; }
}

.result-card {
  align-self: flex-start;
  max-width: 78%;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-2);
  background: var(--surface);
  border-radius: 0.7rem;
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: rise 0.18s ease-out;
}

.result-card .case-name {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-weight: 600;
  font-size: 0.98rem;
  margin-bottom: 0.2rem;
}

.result-card .meta {
  color: var(--fg-muted);
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.result-card .snippet {
  font-size: 0.85rem;
  color: var(--fg-muted);
  line-height: 1.45;
  margin-bottom: 0.65rem;
}

.result-card .summary {
  font-size: 0.85rem;
  line-height: 1.5;
  background: color-mix(in srgb, var(--accent-2) 10%, transparent);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.65rem;
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.result-card a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.result-card a:hover {
  text-decoration: underline;
}

.summarize-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.35rem 0.7rem;
  border-radius: 1rem;
  flex-shrink: 0;
}

.summarize-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.query-tag {
  align-self: flex-start;
  font-size: 0.72rem;
  color: var(--fg-muted);
  padding: 0 0.2rem;
  font-style: italic;
}

/* ---------- composer ---------- */

#composer {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.9rem 1.5rem 1.25rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

#input {
  flex: 1;
  resize: none;
  border-radius: 1.1rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  padding: 0.7rem 1rem;
  font: inherit;
  max-height: 8rem;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}

#input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

button {
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}

button:hover:not(:disabled) {
  opacity: 0.92;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

#key-form button {
  padding: 0 1.25rem;
  border-radius: 0.6rem;
}

#composer button {
  width: 2.6rem;
  height: 2.6rem;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 560px) {
  .bubble, .result-card {
    max-width: 88%;
  }
  header, main#chat, #composer {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
