:root {
  --bg: #f4f2ef;
  --surface: #ffffff;
  --text: #2b2b2b;
  --muted: #7a746c;
  --border: #e4dfd8;
  --accent: #5b7b7a;
  --accent-2: #a87b5b;
  --accent-3: #6b6592;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b19;
    --surface: #262523;
    --text: #ece8e2;
    --muted: #a49c90;
    --border: #3a3733;
  }
}

* {
  box-sizing: border-box;
}

.auth-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.auth-gate[hidden] {
  display: none;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 340px;
  width: 100%;
  text-align: center;
}

.auth-box h2 {
  margin: 0 0 8px;
}

.auth-box p {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 16px;
}

.auth-box input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  margin-bottom: 12px;
}

.auth-box .error-msg {
  display: block;
  margin-top: 10px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Georgia", "Iowan Old Style", serif;
  line-height: 1.5;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.app-header {
  text-align: center;
  margin-bottom: 32px;
}

.app-header h1 {
  font-size: 2rem;
  letter-spacing: 0.04em;
  margin: 0 0 6px;
}

.subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 0.95rem;
}

.input-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 14px 0 6px;
}

.field-label:first-child {
  margin-top: 0;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 120px;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

#context-input {
  min-height: 52px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.input-section > .field-row:first-child {
  margin-top: 0;
}

.field-row .field-label {
  margin: 0;
}

.field-row-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.saved-select {
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  max-width: 180px;
}

.options-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 14px;
}

.option-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

.input-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.error-msg {
  color: #b04a3f;
  font-size: 0.85rem;
  margin-right: auto;
}

button {
  font-family: inherit;
  cursor: pointer;
}

#analyze-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 0.95rem;
  transition: opacity 0.15s ease;
}

#analyze-btn:hover {
  opacity: 0.85;
}

#analyze-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  margin-bottom: 36px;
  align-items: start;
}

.provider-column {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.provider-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.provider-error {
  color: #b04a3f;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.card-emotions {
  border-left-color: var(--accent-3);
}

.card h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card p {
  margin: 0;
  white-space: pre-wrap;
}

.history-section {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.history-header h2 {
  font-size: 1rem;
  color: var(--muted);
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: underline;
  padding: 0;
}

.history-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.history-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-item:hover {
  color: var(--accent);
}

.history-excerpt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.history-date {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.history-empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 12px 0;
}
