/* =====================================================================
 * Paraphrasing Studio — stylesheet
 * Flat, professional design with light & dark themes via [data-theme].
 * A single solid accent, no gradients, SVG icons throughout.
 * ===================================================================== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f2f3f6;
  --surface-3: #e9ebf0;
  --border: #e2e5ea;
  --border-strong: #d3d7df;
  --text: #14171c;
  --text-muted: #565d6a;
  --text-faint: #868d9a;
  --accent: #2f6feb;
  --accent-hover: #245fd6;
  --accent-soft: #e8f0fe;
  --accent-text: #1d54c0;
  --success: #0f8a4d;
  --success-soft: #e5f5ec;
  --danger: #d23b3b;
  --danger-soft: #fbeaea;
  --mark: #ffe680;
  --shadow-sm: 0 1px 2px rgba(20, 23, 28, 0.05);
  --shadow-md: 0 2px 8px rgba(20, 23, 28, 0.06);
  --shadow-lg: 0 16px 40px rgba(20, 23, 28, 0.14);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #0e1013;
  --surface: #16191f;
  --surface-2: #1b1f27;
  --surface-3: #232833;
  --border: #282d38;
  --border-strong: #333a47;
  --text: #e8eaee;
  --text-muted: #9aa1af;
  --text-faint: #6d7482;
  --accent: #5b8bff;
  --accent-hover: #6f99ff;
  --accent-soft: #182234;
  --accent-text: #93b4ff;
  --success: #35c37e;
  --success-soft: #12271c;
  --danger: #f36b6b;
  --danger-soft: #2c1719;
  --mark: #5a5222;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

svg { width: 1em; height: 1em; display: block; }

/* ===================== HEADER ===================== */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 44px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 1.15rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
.brand-text small { color: var(--text-faint); font-size: 0.72rem; }

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 9px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.icon-btn svg { font-size: 1.05rem; }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.icon-only { padding: 8px; }

/* ===================== INTRO ===================== */
.intro {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(30px, 5vw, 52px) 20px clamp(14px, 2vw, 20px);
  text-align: center;
}
.intro h1 {
  font-size: clamp(1.7rem, 4vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin: 0 0 12px;
}
.intro p { color: var(--text-muted); font-size: clamp(0.98rem, 2vw, 1.08rem); margin: 0; }

/* ===================== MODE TABS ===================== */
.mode-tabs {
  display: inline-flex;
  gap: 4px;
  margin-top: 22px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.mode-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-tab svg { font-size: 1.05rem; }
.mode-tab:hover { color: var(--text); }
.mode-tab.active { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .mode-tab.active { background: var(--surface-3); }

/* ===================== TOOL PICKER + OPTIONS ===================== */
.tool-picker { margin-top: 16px; }
.tool-picker > label { display: block; font-size: 0.75rem; color: var(--text-muted); font-weight: 500; margin-bottom: 6px; }
.tool-picker .select-wrap { width: 100%; }
.tool-desc { margin: 8px 0 0; font-size: 0.83rem; color: var(--text-faint); }

.tool-options { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.tool-options:empty { margin-top: 0; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.opt-row > label { font-size: 0.82rem; color: var(--text-muted); font-weight: 500; min-width: 90px; }
.opt-row .select-wrap { flex: 1; max-width: 220px; }
.opt-val { font-size: 0.82rem; font-weight: 600; color: var(--accent-text); min-width: 22px; text-align: right; }
.opt-row input[type="range"] {
  flex: 1; max-width: 200px; accent-color: var(--accent); cursor: pointer;
}

/* Toggle switch */
.toggle {
  position: relative; width: 42px; height: 24px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface-2); cursor: pointer; padding: 0;
  transition: background 0.15s, border-color 0.15s;
}
.toggle span {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-faint); transition: transform 0.18s, background 0.15s;
}
.toggle.on { background: var(--accent-soft); border-color: var(--accent); }
.toggle.on span { transform: translateX(18px); background: var(--accent); }

.detect-note {
  display: flex; align-items: flex-start; gap: 8px;
  margin: 16px 0 0; padding: 11px 13px;
  font-size: 0.82rem; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
}
.detect-note svg { font-size: 1.05rem; flex-shrink: 0; margin-top: 1px; color: var(--accent); }

/* ===================== WORKSPACE ===================== */
.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 8px clamp(16px, 4vw, 44px) 56px;
  align-items: start;
}
@media (max-width: 900px) { .workspace { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.output-panel { position: sticky; top: 84px; }
@media (max-width: 900px) { .output-panel { position: static; } }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 0.95rem; font-weight: 600; margin: 0; }

.counters { display: flex; gap: 6px; flex-wrap: wrap; }
.counters span {
  font-size: 0.72rem;
  color: var(--text-faint);
  background: var(--surface-2);
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* ===================== INPUT ===================== */
.text-area {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  padding: 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.98rem;
  line-height: 1.6;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.text-area::placeholder { color: var(--text-faint); }
.text-area:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.text-area:disabled { opacity: 0.6; }

.controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-top: 15px;
  flex-wrap: wrap;
}
.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-group label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }

/* Custom select */
.select-wrap { position: relative; display: inline-flex; align-items: center; }
.select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  font-size: 0.88rem;
  padding: 9px 34px 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  width: 100%;
}
.select-wrap select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.select-chevron {
  position: absolute;
  right: 10px;
  font-size: 1rem;
  color: var(--text-faint);
  pointer-events: none;
}
.select-wrap.compact select { padding-top: 8px; padding-bottom: 8px; font-size: 0.84rem; }

.control-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.btn svg { font-size: 1rem; }
.btn:active { transform: translateY(1px); }
.btn-small { padding: 5px 10px; font-size: 0.79rem; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { cursor: default; opacity: 0.75; }

.btn-secondary {
  background: var(--surface);
  color: var(--accent-text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--accent-soft); border-color: var(--accent); }

.btn-ghost { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }

/* Spinner */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  display: none;
  animation: spin 0.7s linear infinite;
}
.btn-primary.loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== STATUS BAR ===================== */
.status-bar {
  margin-top: 13px;
  padding: 10px 13px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 500;
  border: 1px solid transparent;
}
.status-info { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.status-success { background: var(--success-soft); color: var(--success); }
.status-error { background: var(--danger-soft); color: var(--danger); }

/* Rate-limit / quota chip */
.rate-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.rate-info .rate-tool {
  font-weight: 600;
  color: var(--accent-text);
  padding-right: 8px;
  border-right: 1px solid var(--border);
}
.rate-info.rate-low { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.rate-info.rate-low .rate-tool { color: var(--danger); border-right-color: var(--danger); }

/* ===================== OUTPUT ===================== */
.output-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap .search-icon {
  position: absolute;
  left: 10px;
  font-size: 0.95rem;
  color: var(--text-faint);
  pointer-events: none;
}
.search-wrap input {
  font-family: inherit;
  font-size: 0.84rem;
  padding: 8px 12px 8px 32px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-width: 150px;
}
.search-wrap input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.assembled {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  margin-bottom: 15px;
}
.assembled-label { font-size: 0.75rem; font-weight: 600; color: var(--accent-text); margin-bottom: 5px; }
.assembled-label span { color: var(--text-faint); font-weight: 400; }
.assembled-text { margin: 0; font-size: 0.95rem; line-height: 1.65; }

.results { display: flex; flex-direction: column; gap: 12px; min-height: 200px; }

.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.empty-icon { font-size: 2.1rem; color: var(--border-strong); }
.empty-state p { margin: 0; font-weight: 500; color: var(--text-muted); }
.empty-hint { font-size: 0.82rem; max-width: 320px; }

/* ---- Result cards ---- */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 14px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.card-index { font-weight: 600; font-size: 0.8rem; color: var(--text); }
.card-count { font-size: 0.72rem; color: var(--text-faint); }

.card-original {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 8px 11px;
  border-radius: 7px;
  margin: 0 0 10px;
}
.orig-label {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--text-faint);
  margin-right: 5px;
}

.alt-list { display: flex; flex-direction: column; gap: 8px; }
.alt {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.alt:hover { border-color: var(--border-strong); background: var(--surface-2); }
.alt:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.alt-selected { border-color: var(--accent); background: var(--accent-soft); }
.alt-selected:hover { background: var(--accent-soft); }

.alt-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--accent-text);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.alt-badge svg { font-size: 0.85rem; }

.alt-text { margin: 0; font-size: 0.92rem; line-height: 1.55; }
.alt-tools { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.alt-len { font-size: 0.7rem; color: var(--text-faint); }
.alt-copy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.alt-copy svg { font-size: 0.85rem; }
.alt-copy:hover { color: var(--accent-text); border-color: var(--accent); }

mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 3px; }

/* ===================== TEXT / IMPROVE RESULTS ===================== */
.result-text { display: flex; flex-direction: column; gap: 14px; }
.result-body { margin: 0; font-size: 0.98rem; line-height: 1.7; white-space: pre-wrap; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.readability { display: flex; flex-direction: column; gap: 10px; }
.meter .meter-head { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text-muted); margin-bottom: 4px; }
.meter .meter-head strong { color: var(--text); }
.meter-track { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.4s ease; }

.changes { border-top: 1px solid var(--border); padding-top: 12px; }
.changes-title { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.changes ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.changes li { display: flex; align-items: flex-start; gap: 8px; font-size: 0.86rem; color: var(--text-muted); line-height: 1.5; }
.changes li svg { font-size: 0.95rem; color: var(--success); flex-shrink: 0; margin-top: 2px; }

/* ===================== AI DETECTOR RESULT ===================== */
.detect-card { display: flex; flex-direction: column; gap: 16px; }
.gauge { text-align: center; padding: 20px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.gauge-human { background: var(--success-soft); }
.gauge-ai { background: var(--danger-soft); }
.gauge-verdict { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.gauge-human .gauge-verdict { color: var(--success); }
.gauge-ai .gauge-verdict { color: var(--danger); }
.gauge-num { font-size: 2.8rem; font-weight: 700; line-height: 1.1; margin: 4px 0; }
.gauge-num span { font-size: 1rem; font-weight: 500; color: var(--text-muted); margin-left: 4px; }
.gauge-track { height: 10px; border-radius: 999px; background: rgba(0,0,0,0.08); overflow: hidden; margin: 10px auto 6px; max-width: 320px; }
[data-theme="dark"] .gauge-track { background: rgba(255,255,255,0.1); }
.gauge-human .gauge-fill { background: var(--success); }
.gauge-ai .gauge-fill { background: var(--danger); }
.gauge-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }
.gauge-sub { font-size: 0.82rem; color: var(--text-muted); }

.detect-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.detect-stats .stat { text-align: center; padding: 12px 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; }
.detect-stats .stat strong { display: block; font-size: 1.4rem; font-weight: 700; }
.detect-stats .stat span { font-size: 0.72rem; color: var(--text-faint); }

.history-tool { color: var(--accent-text); font-weight: 600; }

/* ===================== HISTORY DRAWER ===================== */
.drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: min(400px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 60;
  display: flex;
  flex-direction: column;
  padding: 18px;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.drawer-head h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.drawer-head-actions { display: flex; gap: 8px; align-items: center; }
.drawer-search { margin-bottom: 12px; }
.drawer-search input { width: 100%; }

.history-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 2px; }
.history-item { border: 1px solid var(--border); border-radius: 9px; padding: 11px 12px; background: var(--surface-2); }
.history-when { font-size: 0.68rem; color: var(--text-faint); margin-bottom: 4px; }
.history-input { font-size: 0.85rem; font-weight: 500; margin-bottom: 4px; }
.history-preview { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 8px; }
.history-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.history-empty { text-align: center; color: var(--text-faint); padding: 30px 12px; font-size: 0.88rem; }

.drawer-overlay { position: fixed; inset: 0; background: rgba(10, 12, 16, 0.5); z-index: 55; }

/* ===================== TOAST ===================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  opacity: 0;
  transition: opacity 0.22s, transform 0.22s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { background: var(--danger); color: #fff; }

/* ===================== FOOTER ===================== */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 22px 20px;
  margin-top: auto;
}
.footer-inner { max-width: 1200px; margin: 0 auto; text-align: center; }
.credit { margin: 0 0 3px; font-size: 0.95rem; color: var(--text-muted); }
.credit strong { color: var(--text); font-weight: 600; }
.attribution { margin: 0; font-size: 0.8rem; color: var(--text-faint); }
.attribution a { color: var(--accent); text-decoration: none; font-weight: 500; }
.attribution a:hover { text-decoration: underline; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 560px) {
  .btn-label { display: none; }
  .controls { flex-direction: column; align-items: stretch; }
  .control-group { width: 100%; }
  .select-wrap { width: 100%; }
  .control-actions { justify-content: space-between; }
  .control-actions .btn { flex: 1; justify-content: center; }
  .output-tools { width: 100%; }
  .search-wrap { flex: 1; }
  .search-wrap input { width: 100%; min-width: 0; }
}
