@font-face {
  font-family: gg;
  src: url('/fonts/gg-sans-400.woff2');
  font-display: swap;
}

@font-face {
  font-family: gg;
  src: url('/fonts/gg-sans-700.woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: gg, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f8fafc;
  background: #09090b;
  --background: #09090b;
  --surface: #0f0f12;
  --card: #121216;
  --popover: #18181b;
  --border: #27272a;
  --border-strong: #3f3f46;
  --foreground: #fafafa;
  --muted: #a1a1aa;
  --muted-foreground: #71717a;
  --primary: #fafafa;
  --primary-foreground: #18181b;
  --accent: #27272a;
  --danger: #ef4444;
  --success: #22c55e;
  --ring: #a1a1aa;
  --radius: 8px;
  --line: var(--border);
}

* {
  box-sizing: border-box;
}

html,
body,
main {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% -20%, rgb(63 63 70 / 0.22), transparent 38rem),
    var(--background);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
input,
textarea,
select,
a {
  transition:
    border-color 150ms ease,
    background-color 150ms ease,
    color 150ms ease,
    box-shadow 150ms ease,
    opacity 150ms ease;
}

button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--foreground);
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--border-strong);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

button:disabled,
[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

p,
small,
.status {
  color: var(--muted);
}

.primary,
.send {
  border-color: var(--primary);
  color: var(--primary-foreground);
  background: var(--primary);
}

.primary:hover:not(:disabled),
.send:hover:not(:disabled) {
  border-color: #d4d4d8;
  background: #d4d4d8;
}

.error,
.modal-error {
  color: #f87171;
}

.brand-mark {
  display: inline-grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid #52525b;
  border-radius: 8px;
  color: var(--background);
  background: var(--foreground);
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 1px 8px rgb(255 255 255 / 0.08);
}

.brand {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  padding-right: 18px;
  border-right: 1px solid var(--border);
  font-size: 15px;
}

.eyebrow,
.settings em {
  display: block;
  margin: 20px 0 10px;
  color: var(--muted-foreground);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.12em;
}

/* Authentication */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(100%, 460px);
  padding: 36px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgb(18 18 22 / 0.82);
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.35);
  backdrop-filter: blur(16px);
}

.card .brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 17px;
}

.card h1 {
  margin-bottom: 12px;
  color: var(--foreground);
  font-size: clamp(26px, 5vw, 34px);
  line-height: 1.12;
  letter-spacing: -0.035em;
}

.card p {
  line-height: 1.65;
}

.card .primary {
  width: 100%;
  margin-top: 12px;
}

/* Chat shell */
.chat {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgb(9 9 11 / 0.72);
}

.control-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px max(20px, calc((100vw - 1120px) / 2));
  border-bottom: 1px solid var(--border);
  background: rgb(9 9 11 / 0.9);
  backdrop-filter: blur(14px);
}

.control-bar label {
  display: grid;
  min-width: 0;
  flex: 0 1 auto;
  gap: 5px;
}

.control-bar label > span {
  color: var(--muted-foreground);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.control-bar select,
.control-bar input,
.settings input,
.settings select,
.settings textarea,
.component-select,
.entity-select input,
.modal-field input[type='text'],
.modal-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--foreground);
  background: var(--surface);
  outline: none;
}

.control-bar select,
.control-bar input {
  height: 36px;
  padding: 7px 10px;
}

.control-bar select {
  min-width: 126px;
}

.control-bar #model-select {
  width: 190px;
}

.control-bar .token-control {
  width: 160px;
}

.control-bar input[type='range'] {
  padding: 0;
  border-color: transparent;
  background: transparent;
  accent-color: var(--foreground);
}

.control-bar output {
  color: var(--muted);
}

.debug-control {
  justify-items: center;
}

.debug-control input {
  width: 16px;
  height: 16px;
  margin: 9px 5px 0;
  accent-color: var(--foreground);
}

.control-bar .admin-link {
  flex: 0 0 auto;
  margin-left: auto;
  white-space: nowrap;
}

.message-pane {
  position: relative;
  min-height: 0;
}

.messages {
  width: min(100%, 880px);
  height: 100%;
  min-height: 0;
  margin: auto;
  overflow: auto;
  padding: 36px 28px;
  scroll-behavior: smooth;
  scrollbar-color: var(--border-strong) transparent;
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted-foreground);
}

.message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 13px;
  padding: 16px 0;
  border-bottom: 1px solid rgb(39 39 42 / 0.58);
}

.message:last-child {
  border-bottom: 0;
}

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--background);
  background: var(--foreground);
  font-size: 12px;
  font-weight: 700;
}

.user .avatar {
  color: var(--foreground);
  background: var(--accent);
}

.meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 24px;
}

.meta time {
  color: var(--muted-foreground);
  font-size: 11px;
}

.body {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #e4e4e7;
  line-height: 1.65;
}

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

.body p {
  margin-bottom: 10px;
  color: inherit;
}

.body pre,
.body code {
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.body pre {
  overflow: auto;
  padding: 14px;
}

.body code {
  padding: 2px 5px;
}

.body pre code {
  padding: 0;
  border: 0;
}

.body a {
  color: #d4d4d8;
  text-underline-offset: 3px;
}

.body blockquote {
  margin-left: 0;
  padding-left: 14px;
  border-left: 2px solid var(--border-strong);
  color: var(--muted);
}

.body ul,
.body ol {
  margin: 6px 0;
  padding-left: 24px;
}

.body .subtext {
  color: var(--muted-foreground);
  font-size: 12px;
}

.composer {
  width: min(calc(100% - 40px), 824px);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 auto 20px;
  padding: 7px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.28);
}

.composer:focus-within {
  border-color: #52525b;
  box-shadow: 0 0 0 1px #3f3f46, 0 12px 40px rgb(0 0 0 / 0.28);
}

.composer textarea {
  min-height: 40px;
  max-height: 180px;
  flex: 1;
  resize: none;
  padding: 10px;
  border: 0;
  outline: 0;
  color: var(--foreground);
  background: transparent;
  line-height: 20px;
}

.composer textarea::placeholder {
  color: var(--muted-foreground);
}

.send {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 8px;
  font-size: 18px;
}

.cancel {
  height: 40px;
  min-height: 40px;
  border-color: rgb(239 68 68 / 0.35);
  color: #fecaca;
  background: rgb(127 29 29 / 0.28);
}

.jump-bottom {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 2;
  transform: translateX(-50%);
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
  white-space: nowrap;
}

/* Rich message components */
.embed,
.component-container,
.debug-timing {
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.embed {
  border-left-width: 3px;
}

.debug-timing {
  color: var(--muted);
  font-size: 12px;
}

.debug-timing summary {
  cursor: pointer;
  font-weight: 700;
}

.debug-timing pre {
  margin: 8px 0 0;
  padding: 0;
  border: 0;
  white-space: pre-wrap;
  background: transparent;
}

.component-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.component-button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--foreground) !important;
  background: var(--surface);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.component-button:hover:not(:disabled) {
  background: var(--accent);
}

.component-button.primary {
  border-color: var(--foreground);
  color: var(--background) !important;
  background: var(--foreground);
}

.component-button.success {
  border-color: rgb(34 197 94 / 0.4);
  color: #bbf7d0 !important;
  background: rgb(20 83 45 / 0.35);
}

.component-button.danger {
  border-color: rgb(239 68 68 / 0.4);
  color: #fecaca !important;
  background: rgb(127 29 29 / 0.35);
}

.component-button.pending::after {
  content: ' ...';
}

.component-emoji {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.entity-select {
  width: min(100%, 480px);
  display: flex;
  gap: 8px;
}

.component-select,
.entity-select input {
  min-width: 0;
  min-height: 38px;
  flex: 1;
  padding: 8px 10px;
}

.component-fallback {
  margin-top: 8px;
  padding: 9px 11px;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  color: var(--muted);
}

.interaction-status {
  margin-top: 7px;
}

/* Settings */
.settings {
  width: min(100%, 780px);
  min-height: 100vh;
  margin: auto;
  padding: 56px 28px 80px;
}

.settings header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}

.settings header h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.03em;
}

.settings em {
  margin-top: 0;
}

.settings form {
  display: grid;
  gap: 17px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
}

.settings #openai-token-form,
.settings #prompt-settings-form,
.settings #session-prompt-settings-form {
  margin-top: 20px;
}

.settings form > label:not(.check),
.modal-field {
  display: grid;
  gap: 7px;
  color: var(--foreground);
  font-size: 13px;
  font-weight: 700;
}

.settings input,
.settings select,
.settings textarea,
.modal-field input[type='text'],
.modal-field textarea {
  min-height: 40px;
  padding: 9px 11px;
  font-weight: 400;
}

.settings textarea {
  min-height: 260px;
  resize: vertical;
  line-height: 1.55;
}

.settings small {
  line-height: 1.5;
  font-weight: 400;
}

.check,
.modal-option {
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.check input,
.modal-option input {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 1px 0 0;
  accent-color: var(--foreground);
}

.notice {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
  line-height: 1.55;
}

.settings form > p:last-child {
  margin-bottom: 0;
}

/* Interaction dialog */
dialog {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  color: var(--foreground);
  background: var(--card);
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.65);
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.72);
  backdrop-filter: blur(3px);
}

#interaction-modal-form {
  padding: 22px;
}

#interaction-modal-form header,
#interaction-modal-form footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#interaction-modal-form h2 {
  margin: 0;
  font-size: 19px;
}

.modal-close {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
}

.modal-field {
  margin: 18px 0;
}

.modal-field textarea {
  resize: vertical;
}

.modal-options {
  display: grid;
  gap: 10px;
}

.modal-option {
  font-weight: 400;
}

.modal-error {
  min-height: 20px;
}

#interaction-modal-form footer {
  justify-content: flex-end;
  padding-top: 6px;
}

@media (max-width: 900px) {
  .control-bar {
    align-items: flex-end;
    overflow-x: auto;
    padding: 10px 14px;
    scrollbar-width: thin;
  }

  .brand strong {
    display: none;
  }

  .brand {
    padding-right: 12px;
  }

  .control-bar .admin-link {
    margin-left: 0;
  }

  .control-bar label {
    flex: 0 0 auto;
  }
}

@media (max-width: 600px) {
  .card {
    padding: 28px 24px;
  }

  .control-bar #model-select {
    width: 160px;
  }

  .control-bar .token-control {
    width: 140px;
  }

  .messages {
    padding: 22px 16px;
  }

  .message {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 10px;
    padding: 14px 0;
  }

  .avatar {
    width: 30px;
    height: 30px;
    border-radius: 7px;
  }

  .composer {
    width: calc(100% - 24px);
    margin-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .entity-select {
    flex-direction: column;
  }

  .settings {
    padding: 32px 16px 56px;
  }

  .settings header {
    align-items: flex-start;
  }

  .settings header h1 {
    font-size: 26px;
  }

  .settings form {
    padding: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
