/* Advanced Text Separator — premium workspace tokens */
:root {
  --font-sans: "SF Pro Text", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.12);
  --transition: 0.18s ease;
  --header-h: 72px;
  --stats-h: 44px;
  --sticky-actions: 56px;
}

[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --accent-text: #ffffff;
  --success: #059669;
  --favorite: #d97706;
  --danger: #dc2626;
  --preview-bg: #fafbfc;
  --chip: #f1f5f9;
}

[data-theme="dark"] {
  --bg: #0b0f14;
  --bg-elevated: #111827;
  --surface: #151c28;
  --border: #243044;
  --border-strong: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.18);
  --accent-text: #f8fafc;
  --success: #34d399;
  --favorite: #fbbf24;
  --danger: #f87171;
  --preview-bg: #0f141c;
  --chip: #1e293b;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* Toast */
.toast-host {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(420px, 100vw - 24px);
}

.toast {
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  animation: toastIn 0.28s ease;
}

.toast.success {
  border-color: color-mix(in srgb, var(--success) 40%, var(--border));
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #6366f1));
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
}

.brand-text {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 4px 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  max-width: 52ch;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Stats */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.stat-label {
  color: var(--text-muted);
}

.stat strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-output {
  margin-inline-start: auto;
}

@media (max-width: 640px) {
  .stat-output {
    margin-inline-start: 0;
    width: 100%;
  }
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(0, 1fr) minmax(260px, 320px);
  gap: 0;
  min-height: calc(100dvh - var(--header-h) - var(--stats-h) - 48px);
  align-items: stretch;
}

.panel {
  background: var(--bg);
  border-inline-end: 1px solid var(--border);
  padding: 16px;
  overflow-x: hidden;
}

.panel:last-child {
  border-inline-end: none;
}

.panel-left {
  overflow-y: auto;
  max-height: none;
}

.panel-center {
  background: var(--bg-elevated);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-right {
  overflow-y: auto;
  max-height: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.section {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.section:last-of-type {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.section-title {
  margin: 0 0 10px;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field-inline {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.field-inline label {
  flex: 0 0 auto;
}

.field-inline input {
  flex: 1;
  max-width: 88px;
}

.field label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

input[type="text"],
input[type="search"],
input[type="number"],
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea.input-area {
  min-height: 200px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  min-width: 0;
}

.toggle-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  cursor: pointer;
  user-select: none;
  min-height: 44px;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.stack-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (max-width: 400px) {
  .preset-grid {
    grid-template-columns: 1fr;
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform 0.12s ease;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: color-mix(in srgb, var(--accent) 85%, #000);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--chip);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--chip);
}

.btn-sm {
  padding: 8px 10px;
  min-height: 40px;
  font-size: 0.8125rem;
}

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
  background: transparent;
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Center editor */
.editor-split {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1;
}

.pane-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}

.pane-label .hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.preview-pane {
  flex: 1.1;
}

.output {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--preview-bg);
  min-height: 160px;
  max-height: min(50vh, 420px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.output-cards {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 14px;
}

.output-plain {
  margin: 0;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.word-card {
  cursor: grab;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: 0.8125rem;
  box-shadow: var(--shadow-sm);
}

.word-card:nth-child(4n + 1) {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.sep-card {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--chip);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.dragging {
  opacity: 0.65;
}

.kbd-hint {
  margin: 12px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--chip);
}

/* History */
.history-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.search-input {
  min-height: 44px;
}

.history-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
}

.empty-title {
  margin: 0 0 8px;
  font-weight: 600;
  color: var(--text);
}

.empty-text {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.55;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--surface);
  cursor: grab;
  transition: border-color var(--transition);
}

.history-item:hover {
  border-color: var(--border-strong);
}

.history-item.dragging-history {
  opacity: 0.55;
}

.history-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.history-item-name {
  font-size: 0.875rem;
  font-weight: 650;
  cursor: text;
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.history-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.history-snippet {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 8px;
  max-height: 3.2em;
  overflow: hidden;
  word-break: break-word;
}

.history-item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.history-tag-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--chip);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.favorite-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 6px;
  min-height: 44px;
  min-width: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}

.favorite-btn.active {
  color: var(--favorite);
}

.history-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.history-action-btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 8px 10px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.history-action-btn:hover {
  background: var(--chip);
}

/* Footer */
.app-footer {
  padding: 16px 20px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.app-footer p {
  margin: 0;
}

/* Mobile / tablet: stacked */
.sticky-actions {
  display: none;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel {
    border-inline-end: none;
    border-bottom: 1px solid var(--border);
  }

  .panel-right {
    border-bottom: none;
    padding-bottom: calc(var(--sticky-actions) + 12px);
  }

  .sticky-actions {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    z-index: 40;
    gap: 8px;
    justify-content: stretch;
  }

  .sticky-actions .btn {
    flex: 1;
  }
}
