:root {
  color-scheme: light;
  --bg: #eef2f8;
  --surface: #ffffff;
  --surface-soft: #f1f4fb;
  --ink: #182236;
  --muted: #64748b;
  --line: #dbe2ee;
  --primary: #3833a8;
  --primary-dark: #292276;
  --primary-light: #e8ebff;
  --accent: #2d7185;
  --danger: #b42318;
  --warning-bg: #fffbeb;
  --warning-line: #f59e0b;
  --success: #047857;
  --shadow: 0 16px 42px rgba(31, 45, 86, 0.1);
  --radius: 18px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 12% 5%, rgba(61, 68, 169, 0.12), transparent 26rem),
    linear-gradient(180deg, #f6f8fc 0, var(--bg) 28rem);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.55;
}

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

button,
summary,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
}

a {
  color: var(--primary);
}

.shell {
  width: min(1440px, calc(100% - 40px));
  margin-inline: auto;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 99;
  transform: translateY(-150%);
  border-radius: 8px;
  background: var(--ink);
  color: white;
  padding: 10px 14px;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(115deg, #30237f 0%, #3937a7 52%, #2d6f83 100%);
  backdrop-filter: blur(14px);
}

.header-inner {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: white;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 1rem;
  font-weight: 800;
  box-shadow: none;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1rem;
}

.brand small {
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.7rem;
}

.home-link {
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  padding: 7px 14px;
  color: white;
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: none;
}

.home-link:hover {
  border-color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.16);
}

.page-main {
  padding-block: 20px 56px;
}

.hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 34px;
  border-radius: 18px;
  background: linear-gradient(115deg, #30237f 0%, #3a3baa 57%, #2d7185 100%);
  color: white;
  padding: 23px 26px;
  margin-bottom: 16px;
  box-shadow: 0 16px 34px rgba(37, 42, 112, 0.18);
}

.hero::before,
.hero::after {
  position: absolute;
  z-index: -1;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 50%;
  content: "";
}

.hero::before {
  width: 310px;
  height: 310px;
  right: -95px;
  top: -165px;
}

.hero::after {
  width: 205px;
  height: 205px;
  right: 18%;
  bottom: -170px;
}

.eyebrow,
.step-label {
  margin: 0 0 7px;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.hero .eyebrow {
  color: #dfe4ff;
}

.hero h1 {
  margin: 0;
  color: white;
  font-size: clamp(1.85rem, 3.3vw, 2.75rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
}

.hero-copy {
  max-width: 760px;
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: clamp(0.94rem, 1.45vw, 1.06rem);
}

.notice {
  width: min(420px, 100%);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-left: 4px solid #f7c451;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.12);
  padding: 11px 13px;
  color: white;
  font-size: 0.88rem;
}

.notice span {
  width: 22px;
  height: 22px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: #f59e0b;
  color: white;
  font-size: 0.78rem;
  font-weight: 900;
}

.notice p {
  margin: 0;
}

.mode-switch {
  width: fit-content;
  display: flex;
  gap: 4px;
  border: 1px solid #d9dfeb;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.78);
  padding: 4px;
  margin-bottom: 15px;
}

.mode-button {
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 750;
}

.mode-button.is-active {
  background: linear-gradient(135deg, var(--primary), #2d7185);
  color: white;
  box-shadow: 0 6px 14px rgba(109, 40, 217, 0.2);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  align-items: start;
  gap: 22px;
}

.panel {
  min-width: 0;
  border: 1px solid #d9e0ec;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 25px;
}

.result-panel {
  position: sticky;
  top: 18px;
  min-height: 760px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.text-button {
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.form-section {
  margin: 0 0 20px;
  border: 0;
  padding: 0;
}

.ai-provider-card {
  margin: 0 0 22px;
  border: 1px solid #cbd4e7;
  border-radius: 14px;
  background: linear-gradient(145deg, #fafbff, #f0f4fb);
  padding: 16px;
}

.ai-provider-card legend {
  color: var(--primary-dark);
  font-size: 0.93rem;
  font-weight: 820;
  padding: 0 7px;
}

.provider-grid {
  margin-top: 2px;
}

.secret-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

.secret-input input {
  border-radius: 10px 0 0 10px;
}

.secret-input button {
  min-width: 66px;
  border: 1px solid #d8dbe2;
  border-left: 0;
  border-radius: 0 10px 10px 0;
  background: #fff;
  color: var(--primary);
  cursor: pointer;
  padding: 0 12px;
  font-size: 0.8rem;
  font-weight: 780;
}

.secret-input:focus-within button {
  border-color: #8b5cf6;
}

.api-help-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 7px 14px;
  margin-top: 8px;
}

.api-help-row a {
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 760;
  text-underline-offset: 3px;
}

.api-test-row {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  margin-top: 11px;
}

.api-test-button {
  min-height: 38px;
  border: 1px solid #aebadd;
  border-radius: 9px;
  background: #fff;
  color: var(--primary-dark);
  cursor: pointer;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 800;
}

.api-test-button:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}

.api-test-button:disabled {
  cursor: wait;
  opacity: 0.66;
}

.api-test-status {
  flex: 1 1 250px;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.api-test-status.is-testing {
  color: #75570b;
}

.api-test-status.is-success {
  color: var(--success);
  font-weight: 750;
}

.api-test-status.is-error {
  color: var(--danger);
  font-weight: 750;
}

.session-key-option {
  padding: 0;
}

.key-privacy-note {
  margin: 10px 0 0;
  border-top: 1px solid #ddd6fe;
  color: var(--muted);
  padding-top: 10px;
  font-size: 0.74rem;
}

.form-section legend {
  margin-bottom: 8px;
  font-size: 0.87rem;
  font-weight: 760;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segmented label {
  min-width: 0;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafafa;
  color: #475569;
  padding: 10px 7px;
  text-align: center;
  font-size: 0.87rem;
  font-weight: 700;
}

.segmented input:checked + span {
  border-color: #8b5cf6;
  background: var(--primary-light);
  color: var(--primary-dark);
  box-shadow: inset 0 0 0 1px #8b5cf6;
}

.segmented input:focus-visible + span {
  outline: 3px solid rgba(109, 40, 217, 0.2);
  outline-offset: 2px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.field {
  margin-bottom: 15px;
}

.form-grid .field {
  margin-bottom: 0;
}

.field-full {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: #334155;
  font-size: 0.85rem;
  font-weight: 750;
}

.field label b {
  color: var(--danger);
}

.field input,
.field select,
.field textarea,
.chat-compose textarea {
  width: 100%;
  border: 1px solid #d8dbe2;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field textarea,
.chat-compose textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.chat-compose textarea:focus {
  border-color: #8b5cf6;
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.11);
}

.field [aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.1);
}

.field small,
.microcopy,
.privacy-note {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.75rem;
}

.advanced-options {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafafa;
  margin-top: 19px;
  padding: 0 14px;
}

.advanced-options summary,
.result-details summary {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 780;
  padding: 12px 0;
}

.details-content {
  border-top: 1px solid var(--line);
  padding-top: 15px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: #475569;
  cursor: pointer;
  font-size: 0.82rem;
  padding: 13px 0 14px;
}

.check-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  margin-top: 2px;
}

.verification-area {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  border: 1px solid #dbe2ee;
  border-radius: 12px;
  background: #f8faff;
  padding: 10px;
  margin-top: 16px;
}

.verification-area .microcopy {
  margin: 0;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 11px;
  background: linear-gradient(115deg, #3430a0, #2e7185);
  color: white;
  cursor: pointer;
  padding: 12px 18px;
  margin-top: 17px;
  font-weight: 800;
  box-shadow: 0 10px 25px rgba(47, 55, 142, 0.24);
}

.primary-button:hover:not(:disabled) {
  background: linear-gradient(115deg, #2c287f, #245f72);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.spinner {
  width: 19px;
  height: 19px;
  display: none;
  border: 3px solid rgba(255, 255, 255, 0.45);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.primary-button.is-loading .spinner {
  display: block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.privacy-note {
  text-align: center;
}

.empty-state {
  min-height: 620px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--muted);
  text-align: center;
  padding: 36px;
}

.empty-icon {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 2rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  margin: 0;
  color: #334155;
  font-size: 1.15rem;
}

.empty-state p {
  margin: 7px 0 17px;
}

.empty-state ul {
  max-width: 430px;
  margin: 0;
  padding-left: 22px;
  text-align: left;
  font-size: 0.87rem;
}

.empty-state li + li {
  margin-top: 5px;
}

.result-heading {
  margin-bottom: 14px;
}

.save-status {
  color: var(--success);
  font-size: 0.76rem;
  font-weight: 700;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  border-block: 1px solid var(--line);
  padding: 10px 0;
}

.action-button,
.quick-actions button {
  border: 1px solid #ddd6fe;
  border-radius: 8px;
  background: #fff;
  color: var(--primary-dark);
  cursor: pointer;
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 740;
}

.action-button:hover,
.quick-actions button:hover {
  border-color: #a78bfa;
  background: var(--primary-light);
}

.article-preview {
  padding: 25px 6px 20px;
}

.article-preview h3 {
  margin: 0 0 12px;
  color: #111827;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.55rem, 3vw, 2.1rem);
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.article-preview .sapo {
  margin: 0 0 18px;
  color: #334155;
  font-size: 1.02rem;
  font-style: italic;
  font-weight: 650;
}

.article-preview #article-body p {
  margin: 0 0 14px;
  color: #293444;
  text-align: justify;
}

.hashtags {
  color: var(--primary);
  font-size: 0.88rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.result-details {
  border-top: 1px solid var(--line);
}

.option-list {
  display: grid;
  gap: 8px;
  padding-bottom: 14px;
}

.title-option {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fafafa;
  padding: 9px 10px;
}

.title-option p {
  margin: 0;
  font-size: 0.84rem;
}

.title-option button {
  flex: 0 0 auto;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 780;
}

.metadata-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding-bottom: 15px;
}

.metadata-list div {
  border-left: 3px solid #c4b5fd;
  background: #fafafa;
  padding: 9px 11px;
}

.metadata-list dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metadata-list dd {
  margin: 3px 0 0;
  font-size: 0.84rem;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.fact-check {
  border: 1px solid #fde68a;
  border-radius: 12px;
  background: var(--warning-bg);
  padding: 14px 16px;
  margin-top: 15px;
}

.fact-check-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.fact-check h3 {
  margin: 0;
  color: #713f12;
  font-size: 0.95rem;
}

.fact-check-heading span {
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  padding: 3px 8px;
  font-size: 0.7rem;
  font-weight: 780;
}

.fact-check ul {
  margin: 10px 0 0;
  padding-left: 21px;
  color: #713f12;
  font-size: 0.83rem;
}

.fact-check li + li {
  margin-top: 5px;
}

.chat-box {
  border-top: 1px solid var(--line);
  margin-top: 20px;
  padding-top: 19px;
}

.chat-box h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-log {
  display: grid;
  gap: 8px;
  max-height: 190px;
  overflow-y: auto;
  margin-top: 12px;
}

.chat-message {
  max-width: 88%;
  border-radius: 12px;
  padding: 9px 11px;
  font-size: 0.81rem;
}

.chat-message.user {
  justify-self: end;
  border-bottom-right-radius: 3px;
  background: var(--primary);
  color: white;
}

.chat-message.assistant {
  justify-self: start;
  border-bottom-left-radius: 3px;
  background: #f1f5f9;
  color: #334155;
}

.chat-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  margin-top: 10px;
}

.chat-compose textarea {
  min-height: 46px;
  padding: 10px 11px;
  font-size: 0.84rem;
}

.chat-compose button {
  height: 46px;
  border-radius: 9px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  padding-inline: 16px;
  font-weight: 760;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 70;
  max-width: min(380px, calc(100% - 44px));
  transform: translateY(20px);
  border-radius: 11px;
  background: #1f2937;
  color: white;
  opacity: 0;
  padding: 11px 15px;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  font-size: 0.86rem;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.25);
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.error-dialog {
  width: min(430px, calc(100% - 30px));
  border: 0;
  border-radius: 18px;
  color: var(--ink);
  padding: 0;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.28);
}

.error-dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
}

.error-dialog form {
  margin: 0;
  padding: 28px;
  text-align: center;
}

.dialog-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fee2e2;
  color: var(--danger);
  font-size: 1.3rem;
  font-weight: 900;
  margin: 0 auto 12px;
}

.error-dialog h2 {
  margin: 0;
  font-size: 1.25rem;
}

.error-dialog p {
  color: var(--muted);
  margin: 10px 0 2px;
}

.site-footer {
  border-top: 1px solid rgba(109, 40, 217, 0.1);
  background: #fff;
  color: var(--muted);
  padding: 24px 0;
  text-align: center;
  font-size: 0.78rem;
}

.site-footer p {
  margin: 3px 0;
}

.site-footer a {
  font-weight: 750;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1020px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .result-panel {
    position: static;
    min-height: 600px;
  }

  .empty-state {
    min-height: 430px;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 24px, 1440px);
  }

  .header-inner {
    min-height: 52px;
  }

  .brand small {
    display: none;
  }

  .home-link {
    padding: 7px 11px;
    font-size: 0.8rem;
  }

  .page-main {
    padding-block: 14px 42px;
  }

  .hero {
    align-items: flex-start;
    flex-direction: column;
    gap: 13px;
    border-radius: 14px;
    padding: 18px;
  }

  .notice {
    width: 100%;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-button {
    flex: 1;
    padding-inline: 8px;
  }

  .panel {
    border-radius: 15px;
    padding: 18px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .segmented span {
    font-size: 0.8rem;
  }

  .empty-state {
    min-height: 360px;
    padding: 24px 8px;
  }

  .article-preview {
    padding-inline: 0;
  }

  .action-button {
    flex: 1 1 calc(50% - 7px);
  }
}

@media print {
  body {
    background: white;
  }

  .site-header,
  .hero,
  .mode-switch,
  .input-panel,
  .result-heading,
  .action-bar,
  .result-details,
  .fact-check,
  .chat-box,
  .site-footer {
    display: none !important;
  }

  .shell,
  .workspace {
    width: 100%;
    display: block;
  }

  .page-main,
  .result-panel {
    padding: 0;
  }

  .result-panel {
    min-height: auto;
    border: 0;
    box-shadow: none;
  }

  .article-preview h3 {
    font-size: 20pt;
  }
}
