:root {
  color-scheme: light;
  --bg: #0f151b;
  --bg-2: #151f2b;
  --panel: rgba(20, 28, 36, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --ink: #f8f6f2;
  --muted: #c0c5cc;
  --accent: #2dd4bf;
  --accent-2: #fbbf24;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 20%, #203041 0%, var(--bg) 45%) fixed;
  min-height: 100vh;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='2' stitchTiles='stitch'/></filter><rect width='140' height='140' filter='url(%23n)' opacity='0.3'/></svg>");
  mix-blend-mode: soft-light;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 10px;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, #1c3b57, var(--accent));
  box-shadow: 0 16px 30px rgba(45, 212, 191, 0.2);
}

.brand-name {
  font-family: "DM Serif Display", serif;
  font-size: 20px;
}

.brand-sub {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.credits {
  font-size: 13px;
  color: var(--muted);
}

.topup-controls {
  display: none;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.topup-controls label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topup-controls select {
  padding: 8px 12px;
}

.layout {
  max-width: 1100px;
  margin: 0 auto 60px;
  padding: 16px 24px 40px;
  display: grid;
  gap: 18px;
  position: relative;
  z-index: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.login-panel,
.terms-panel {
  display: none;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.login-panel p {
  color: var(--muted);
  max-width: 520px;
}

.login-provider {
  margin-top: 16px;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.login-provider h3 {
  margin: 0 0 4px;
}

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(45, 212, 191, 0.38);
  background: rgba(45, 212, 191, 0.14);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.trial-provider {
  border-color: rgba(45, 212, 191, 0.24);
}

.trial-chat {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.trial-body {
  background: rgba(9, 12, 16, 0.5);
  border-radius: 18px;
  padding: 14px;
  height: 28vh;
  min-height: 180px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.trial-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.trial-form input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}

.trial-note {
  margin: 0;
}

.telegram-login {
  margin: 10px 0;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.muted code,
.alert code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.28);
  color: inherit;
}

.alert {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.12);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.alert a {
  color: inherit;
  text-decoration: underline;
}

.alert.warn {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.12);
}

.terms-panel h2 {
  margin: 0 0 8px;
}

.terms-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.chat-panel {
  display: none;
  min-height: 70vh;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.chat-header h2 {
  margin: 0;
}

.chat-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

select {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 13px;
}

#googleLoginButton {
  margin-top: 10px;
}

#turnstileBox {
  margin-top: 8px;
}

.pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.pill-toggle input {
  cursor: pointer;
}

.chat-body {
  margin-top: 18px;
  background: rgba(9, 12, 16, 0.5);
  border-radius: 18px;
  padding: 16px;
  height: 48vh;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 70%;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.4;
  font-size: 14px;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: rgba(45, 212, 191, 0.2);
  border: 1px solid rgba(45, 212, 191, 0.4);
}

.message.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.message-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.message-meta-text {
  flex: 1;
  min-width: 0;
}

.message-copy-btn {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.message-copy-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.message-copy-btn:disabled {
  cursor: default;
  opacity: 0.65;
}

.chat-input {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.chat-input input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}

.file-upload {
  border: 1px dashed rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}

.file-upload input {
  display: none;
}

.file-list {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.account-panel h1,
.account-panel h2 {
  margin: 0 0 8px;
}

.account-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.account-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.metric {
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.metric-value {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.table-wrap {
  margin-top: 16px;
  overflow-x: auto;
}

.usage-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.usage-table th,
.usage-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
  vertical-align: top;
}

.usage-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 700;
}

.usage-table td.num,
.usage-table th.num {
  text-align: right;
  white-space: nowrap;
}

.usage-table td.model {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn.primary {
  background: var(--accent);
  color: #07252b;
  box-shadow: 0 12px 24px rgba(45, 212, 191, 0.24);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border: 1px solid var(--panel-border);
}

.message.file {
  border-style: dashed;
}

.message.file a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.message.file a:hover {
  text-decoration: underline;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 10, 14, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.modal.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 24px;
  width: min(420px, 90vw);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.modal-card h3 {
  margin: 0 0 8px;
}

.modal-card p {
  margin: 0;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 18px;
}

@media (max-width: 900px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .message {
    max-width: 90%;
  }
  .chat-body {
    height: 52vh;
  }
  .trial-body {
    height: 34vh;
  }
}
