:root {
  --bg: #f4f7f3;
  --card: #ffffff;
  --ink: #1f2a2f;
  --muted: #5d6b73;
  --line: #d8e0da;
  --brand: #0b7a75;
  --brand-2: #085f5b;
  --ok: #1f7b53;
  --warn: #8e5500;
  --danger: #b13636;
  --result-ink: #133a2d;
  --history-ink: #12372a;
  --card-border: rgba(22, 38, 43, 0.09);
  --shadow: 0 14px 36px rgba(10, 22, 27, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "IBM Plex Sans", sans-serif;
  background:
    radial-gradient(circle at 20% -20%, rgba(11, 122, 117, 0.16), transparent 32%),
    radial-gradient(circle at 100% 0, rgba(223, 111, 63, 0.14), transparent 32%),
    var(--bg);
}

.container {
  width: min(1140px, calc(100% - 2rem));
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(28, 40, 46, 0.08);
  background: rgba(244, 247, 243, 0.86);
  backdrop-filter: blur(8px);
}

.topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0;
}

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

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
}

.brand-title {
  font: 700 1.1rem/1.2 "Space Grotesk", sans-serif;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.38rem 0.75rem;
  font-size: 0.78rem;
}

.chip-ok {
  border-color: rgba(31, 123, 83, 0.4);
  color: var(--ok);
  background: rgba(31, 123, 83, 0.08);
}

.chip-warn {
  border-color: rgba(142, 85, 0, 0.4);
  color: var(--warn);
  background: rgba(142, 85, 0, 0.08);
}

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 0.52rem 0.85rem;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(15, 25, 30, 0.08);
}

.btn-primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(130deg, var(--brand), var(--brand-2));
}

.btn:focus-visible,
.sample-btn:focus-visible,
.chip:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel { padding: 1.15rem; }

.workspace-grid {
  margin: 1rem 0 2rem;
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  gap: 1rem;
}

.stack {
  display: grid;
  gap: 0.9rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}

.section-head h2,
.section-head h3 {
  margin: 0;
  font: 700 1.05rem/1.2 "Space Grotesk", sans-serif;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 0.65rem;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill {
  border: 1px solid rgba(11, 122, 117, 0.2);
  background: rgba(11, 122, 117, 0.07);
  color: var(--brand-2);
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.result-text {
  margin: 0.75rem 0 0.45rem;
  color: var(--result-ink);
  font-size: 1.14rem;
  line-height: 1.5;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

.textarea {
  width: 100%;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.66rem 0.76rem;
  outline: none;
  background: #fff;
}

.textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11, 122, 117, 0.14);
}

.textarea {
  min-height: 112px;
  resize: vertical;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.token-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}

.token-table th,
.token-table td {
  text-align: left;
  border-bottom: 1px solid var(--card-border);
  padding: 0.5rem 0.4rem;
  font-size: 0.84rem;
  white-space: nowrap;
}

.token-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.history-list {
  max-height: 520px;
  overflow: auto;
  display: grid;
  gap: 0.6rem;
}

.history-item {
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 0.62rem;
}

.history-item-original {
  margin-top: 0.35rem;
}

.history-item-formal {
  margin-top: 0.2rem;
  font-weight: 600;
  color: var(--history-ink);
}

.history-item-actions {
  margin-top: 0.4rem;
}

.alert {
  margin-top: 0.8rem;
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
}

.alert.warn {
  border: 1px dashed rgba(142, 85, 0, 0.38);
  background: rgba(142, 85, 0, 0.1);
  color: var(--warn);
}

.hidden {
  display: none !important;
}

.sample-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}

.sample-btn {
  font-size: 0.8rem;
  padding: 0.5rem 0.65rem;
  min-height: 44px;
  border-color: rgba(11, 122, 117, 0.18);
  background: rgba(11, 122, 117, 0.06);
  color: var(--brand-2);
  border-radius: 10px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s;
}

.sample-btn:hover {
  background: rgba(11, 122, 117, 0.14);
}

.sample-btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 130;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.62rem 0.8rem;
  min-width: 240px;
  max-width: 360px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.neutral {
  border-top: 3px solid var(--brand);
}

.toast.error {
  border-top: 3px solid var(--danger);
}

.toast.success {
  border-top: 3px solid var(--ok);
}

@media (max-width: 960px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .topbar-inner {
    align-items: flex-start;
  }

  .topbar-actions {
    justify-content: flex-start;
  }
}

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

  .toast {
    transition: none;
  }

  .btn:hover {
    transform: none;
    box-shadow: var(--shadow);
  }
}
