:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-subtle: #f3f3f5;
  --text: #111113;
  --text-muted: #6b6b74;
  --border: #e5e5e8;
  --btn-bg: #111113;
  --btn-bg-hover: #27272b;
  --btn-text: #ffffff;
  --focus: #2563eb;
  --danger: #dc2626;
  --backdrop: rgba(17, 17, 19, 0.38);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
}

html.dark {
  --bg: #0b0b0d;
  --surface: #141417;
  --surface-subtle: #1c1c21;
  --text: #f4f4f6;
  --text-muted: #9494a0;
  --border: #27272d;
  --btn-bg: #f4f4f6;
  --btn-bg-hover: #e2e2e7;
  --btn-text: #0b0b0d;
  --focus: #60a5fa;
  --danger: #f87171;
  --backdrop: rgba(0, 0, 0, 0.68);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: 'Google Sans', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 180ms cubic-bezier(0.16, 1, 0.3, 1),
    color 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

button,
input,
textarea {
  font-family: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.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;
}

/* Top-right discrete controls */
.top-actions {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.16, 1, 0.3, 1),
    color 150ms cubic-bezier(0.16, 1, 0.3, 1),
    border-color 150ms cubic-bezier(0.16, 1, 0.3, 1);
}

.icon-btn:hover {
  background-color: var(--surface-subtle);
  color: var(--text);
  border-color: var(--border);
}

.icon-btn-sm {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.icon {
  width: 19px;
  height: 19px;
}

.icon-sm {
  width: 15px;
  height: 15px;
}

/* Main centered stage */
.stage {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
}

.quote-wrapper {
  width: 100%;
  max-width: 740px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
}

.quote-text {
  margin: 0;
  font-size: clamp(1.65rem, 3.6vw, 2.75rem);
  font-weight: 500;
  line-height: 1.32;
  letter-spacing: -0.02em;
  text-wrap: balance;
  transition: opacity 160ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

html.dark .quote-text {
  letter-spacing: -0.01em;
}

.quote-text.fade-out {
  opacity: 0;
  transform: translateY(4px);
}

.empty-state {
  margin: 0;
  font-size: 1rem;
  color: var(--text-muted);
  max-width: 420px;
}

.cta-container {
  display: flex;
  justify-content: center;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 12px 28px;
  border: none;
  border-radius: 12px;
  background-color: var(--btn-bg);
  color: var(--btn-text);
  font-size: 0.9375rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 120ms cubic-bezier(0.16, 1, 0.3, 1);
}

.primary-btn:hover:not(:disabled) {
  background-color: var(--btn-bg-hover);
}

.primary-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.primary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background-color: var(--backdrop);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: 100%;
  max-width: 680px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-title-group {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.modal-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.quote-count {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.modal-body {
  padding: 20px 24px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.section-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0;
}

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 9px;
  background-color: var(--surface-subtle);
  border: 1px solid var(--border);
  gap: 2px;
}

.segmented-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 140ms ease, color 140ms ease;
}

.segmented-btn.active {
  background-color: var(--surface);
  color: var(--text);
}

/* Inputs & Textarea */
.textarea,
.text-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background-color: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  padding: 10px 12px;
  transition: border-color 140ms ease;
}

.textarea {
  resize: vertical;
  min-height: 92px;
  line-height: 1.5;
}

.textarea:focus,
.text-input:focus {
  outline: none;
  border-color: var(--focus);
}

/* Buttons inside modal */
.secondary-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 14px;
  border-radius: 9px;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.secondary-btn {
  background-color: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text);
}

.secondary-btn:hover {
  background-color: var(--border);
}

.ghost-btn {
  background-color: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
}

.ghost-btn:hover {
  background-color: var(--surface-subtle);
  color: var(--text);
}

.danger-text:hover {
  color: var(--danger);
}

.file-label {
  position: relative;
}

.paste-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.paste-actions-left,
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Dropdown menu */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 190px;
  padding: 5px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dropdown-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.dropdown-item:hover {
  background-color: var(--surface-subtle);
}

/* Table */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 240px;
  overflow-y: auto;
  background-color: var(--bg);
}

.quote-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.quote-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--surface-subtle);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.quote-table tbody tr {
  border-bottom: 1px solid var(--border);
}

.quote-table tbody tr:last-child {
  border-bottom: none;
}

.col-num {
  width: 48px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  padding: 6px 12px;
  vertical-align: middle;
}

.col-text {
  padding: 4px 6px;
}

.col-del {
  width: 42px;
  padding: 4px 8px;
  text-align: right;
  vertical-align: middle;
}

.row-input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 6px 8px;
  font-size: 0.875rem;
  color: var(--text);
}

.row-input:focus {
  outline: none;
  background-color: var(--surface);
  border-color: var(--focus);
}

.row-del-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.row-del-btn:hover {
  background-color: var(--surface-subtle);
  color: var(--danger);
}

.table-empty {
  margin: 0;
  padding: 22px 16px;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Anti-repeat option row & switch */
.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.option-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.option-sub {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

.option-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 42px;
  height: 24px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background-color: var(--surface-subtle);
  cursor: pointer;
  transition: background-color 150ms cubic-bezier(0.16, 1, 0.3, 1),
    border-color 150ms cubic-bezier(0.16, 1, 0.3, 1);
}

.switch.active {
  background-color: var(--btn-bg);
  border-color: var(--btn-bg);
}

.switch-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: var(--surface);
  transition: transform 150ms cubic-bezier(0.16, 1, 0.3, 1);
}

.switch.active .switch-thumb {
  transform: translateX(18px);
  background-color: var(--btn-text);
}

/* Button label customization */
.button-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button-label-row .text-input {
  flex: 1;
}

.hint-text {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

@media (max-width: 600px) {
  .modal-header,
  .modal-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .modal-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .modal-title-group {
    flex-wrap: wrap;
    gap: 4px 10px;
  }

  .option-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .button-label-row {
    flex-direction: column;
    align-items: stretch;
  }
}

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