:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --border: #e3e8f0;
  --border-strong: #c9d1de;
  --text: #1f2937;
  --text-muted: #5b6776;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbe7ff;
  --danger: #dc2626;
  --success: #059669;
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
  --radius: 12px;
}

[data-theme="dark"] {
  --bg: #0f1420;
  --surface: #161c2c;
  --surface-2: #1c2336;
  --border: #2a3450;
  --border-strong: #3a466a;
  --text: #e6ebf5;
  --text-muted: #9aa6bd;
  --primary: #6695ff;
  --primary-hover: #84acff;
  --primary-soft: #1e2c54;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  line-height: 1.5;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(140%) blur(6px);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand h1 {
  font-size: 1.05rem;
  margin: 0;
}

.tagline {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  gap: 0.4rem;
}

.container {
  max-width: 1200px;
  margin: 1.5rem auto 4rem;
  padding: 0 1.25rem;
  display: grid;
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}

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

.card-header h2 {
  margin: 0;
  font-size: 1rem;
}

.meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.meta-row {
  display: flex;
  justify-content: space-between;
  margin: 0.4rem 0 0.6rem;
}

.dot {
  margin: 0 0.35rem;
  opacity: 0.6;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin: 0.4rem 0 0.4rem;
}

textarea {
  width: 100%;
  min-height: 150px;
  padding: 0.85rem 0.95rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.55;
  font-family: inherit;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

#sentenceEditor {
  min-height: 120px;
}

#finalOutput {
  min-height: 220px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

button {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0.55rem 0.95rem;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, color 0.15s,
    transform 0.05s;
}

button:hover {
  background: var(--border);
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

button.primary:hover {
  background: var(--primary-hover);
}

button.ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}

button.ghost:hover {
  background: var(--surface-2);
}

button.danger {
  color: var(--danger);
  border-color: var(--border-strong);
}

button.small {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

button.ai {
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: #fff;
  border-color: transparent;
}

button.ai:hover {
  background: linear-gradient(135deg, #6d28d9, #1d4ed8);
}

button.ai:disabled {
  opacity: 0.6;
  cursor: progress;
}

input[type="password"],
input[type="text"],
select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="password"]:focus,
input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.hint.small {
  font-size: 0.78rem;
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

.workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
}

.progress {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.6rem;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  transition: width 0.25s ease;
}

.sentence-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
}

.sentence-list li {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-muted);
  border: 1px solid transparent;
  margin-bottom: 0.25rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sentence-list li:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sentence-list li.active {
  background: var(--primary-soft);
  color: var(--text);
  border-color: var(--primary);
}

.sentence-list li.edited::before {
  content: "✓";
  color: var(--success);
  font-weight: 700;
  margin-right: 0.15rem;
}

.sentence-list .num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  width: 22px;
}

.sentence-list .preview {
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.reference {
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  margin: 0.25rem 0 0.6rem;
}

.reference-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.reference-text {
  font-size: 0.95rem;
  color: var(--text);
}

.word-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 44px;
}

.word-chip {
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.word-chip:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--text);
}

.word-chip.is-punct {
  cursor: default;
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 0.18rem 0.15rem;
}

.shortcut-hint {
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 0.35rem;
  font-size: 0.75rem;
}

.popover {
  position: fixed;
  z-index: 100;
  width: 260px;
  max-height: 320px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.popover-body {
  padding: 0.5rem;
  overflow-y: auto;
}

.popover-status {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.4rem 0.5rem;
}

.synonym-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.synonym-pill {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.synonym-pill:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 200;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  z-index: 300;
  padding: 1rem;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.32);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.modal-header,
.modal-footer {
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.modal-header {
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 14px 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  padding: 0.85rem 1rem;
  overflow-y: auto;
}

.modal-body label {
  margin-top: 0.65rem;
}

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

.modal-body textarea {
  min-height: 70px;
}

.ai-panel {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}

.ai-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.ai-panel-header strong {
  font-size: 0.92rem;
}

.ai-panel-header .meta {
  flex: 1;
}

.ai-panel-body {
  padding: 0.6rem;
  display: grid;
  gap: 0.5rem;
}

.ai-variant {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.15s, background 0.15s;
}

.ai-variant:hover {
  border-color: var(--primary);
}

.ai-variant .variant-text {
  line-height: 1.5;
}

.ai-variant .variant-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}

.ai-loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.4rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}

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

.ai-error {
  color: var(--danger);
  font-size: 0.88rem;
  padding: 0.5rem 0.4rem;
}

.hint {
  font-style: italic;
}

.hidden {
  display: none !important;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--primary);
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  z-index: 1000;
  font-size: 0.9rem;
  text-decoration: none;
}

.skip-link:focus {
  left: 8px;
}

.seo-content {
  line-height: 1.65;
}

.seo-content h2 {
  margin-top: 0;
}

.seo-content h3 {
  margin-top: 1.4rem;
  margin-bottom: 0.4rem;
  font-size: 1rem;
}

.seo-content p {
  margin: 0.5rem 0;
  color: var(--text);
}

.seo-content ul {
  margin: 0.5rem 0 0.5rem 1.2rem;
  padding: 0;
}

.seo-content li {
  margin: 0.25rem 0;
}

.seo-content a {
  color: var(--primary);
  text-decoration: none;
}

.seo-content a:hover {
  text-decoration: underline;
}

.seo-content details {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  margin: 0.4rem 0;
  background: var(--surface-2);
}

.seo-content details[open] {
  background: var(--surface);
}

.seo-content summary {
  cursor: pointer;
  outline: none;
}

.seo-content summary strong {
  font-weight: 600;
}

.seo-content code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.05rem 0.35rem;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: 1rem;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.footer-inner p {
  margin: 0.25rem 0;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  margin: 0 0.25rem;
}

.footer-links a:hover {
  color: var(--primary);
  text-decoration: underline;
}

@media (max-width: 880px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    max-height: none;
  }
  .sentence-list {
    max-height: 220px;
  }
}
