:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --line: #d6dde6;
  --line-strong: #aeb9c7;
  --ink: #15202b;
  --muted: #5f6d7c;
  --accent: #1f5fa8;
  --accent-strong: #16497f;
  --accent-soft: #e7f0fb;
  --success: #1f7a46;
  --success-soft: #e8f6ee;
  --danger: #b5493c;
  --danger-soft: #fceceb;
  --warning: #7b5a1d;
  --warning-soft: #f8f1df;
  --shadow: 0 14px 34px rgba(21, 32, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

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

button {
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0.72rem 0.95rem;
  border-radius: 4px;
  transition: background 150ms ease, border-color 150ms ease;
}

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

button.secondary {
  background: #fff;
  color: var(--accent);
}

button.secondary:hover {
  background: var(--accent-soft);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

button.ghost:hover {
  background: #fff;
  border-color: var(--line-strong);
}

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

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: 2rem;
}

.app-header,
.workspace {
  width: min(1280px, calc(100vw - 2rem));
  margin-left: auto;
  margin-right: auto;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.25rem 0 0.9rem;
}

.header-kicker {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.32rem;
}

.app-header h1,
.about-head h2,
.detail-title {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
}

.header-copy,
.muted {
  color: var(--muted);
}

.header-copy {
  margin: 0.45rem 0 0;
  max-width: 54rem;
  line-height: 1.5;
}

.header-actions,
.button-row,
.section-head,
.phrase-actions,
.detail-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.section-head {
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(390px, 0.92fr);
  gap: 1rem;
  align-items: start;
}

.library-pane,
.draft-pane {
  display: grid;
  gap: 1rem;
}

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

.sticky-card {
  position: sticky;
  top: 1rem;
}

.panel-title {
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field span,
.toggle span {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  padding: 0.68rem 0.75rem;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.search-field {
  margin-bottom: 0.9rem;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
}

.toggle input {
  width: auto;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.stat-chip {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.72rem 0.8rem;
}

.stat-chip span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.15rem;
}

.stat-chip strong {
  font-size: 1.15rem;
}

.phrase-list {
  display: grid;
  gap: 0.8rem;
}

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

.phrase-card.is-active {
  border-color: rgba(31, 95, 168, 0.55);
  background: var(--accent-soft);
}

.phrase-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}

.phrase-title {
  font-weight: 700;
  font-size: 1.03rem;
}

.phrase-meta,
.tag-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.45rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.16rem 0.48rem;
  background: #fff;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.badge.specialty {
  color: var(--accent);
  border-color: rgba(31, 95, 168, 0.25);
}

.badge.format {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: rgba(123, 90, 29, 0.25);
}

.phrase-preview {
  margin: 0.75rem 0 0;
  color: var(--ink);
  line-height: 1.45;
}

.phrase-actions {
  margin-top: 0.85rem;
}

.favorite-btn {
  min-width: 2.75rem;
  padding-left: 0.7rem;
  padding-right: 0.7rem;
}

.favorite-btn.is-favorite {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: rgba(123, 90, 29, 0.4);
}

.draft-text,
.rendered-text {
  min-height: 20rem;
}

.copy-status {
  color: var(--muted);
  margin-top: 0.65rem;
  font-size: 0.9rem;
}

.detail-card {
  min-height: 16rem;
}

.empty-detail {
  padding: 1rem 0;
}

.detail-meta {
  margin: 0.55rem 0 0.8rem;
}

.variable-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.rendered-text {
  background: var(--surface-soft);
  min-height: 9rem;
}

.detail-actions {
  margin-top: 0.85rem;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  padding: 1.2rem;
  color: var(--muted);
}

.about-dialog {
  width: min(760px, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  color: var(--ink);
}

.about-dialog::backdrop {
  background: rgba(16, 25, 34, 0.45);
}

.about-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.about-content {
  line-height: 1.6;
}

.about-content h3 {
  margin: 1.2rem 0 0.3rem;
}

.icon-btn {
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  font-size: 1.2rem;
}

@media (max-width: 980px) {
  .app-header,
  .workspace {
    width: min(100% - 1rem, 1280px);
  }

  .app-header,
  .workspace {
    grid-template-columns: 1fr;
  }

  .app-header {
    display: grid;
  }

  .sticky-card {
    position: static;
  }
}

@media (max-width: 680px) {
  .filter-grid,
  .stats-strip,
  .variable-grid {
    grid-template-columns: 1fr;
  }

  .phrase-head {
    display: grid;
  }

  button {
    width: 100%;
  }

  .toggle input {
    width: auto;
  }
}
