:root {
  --page: #0b0c0b;
  --surface: #141613;
  --surface-raised: #191c18;
  --surface-inset: #1e211d;
  --border: rgba(238, 241, 233, 0.08);
  --border-strong: rgba(238, 241, 233, 0.15);
  --text: #eef1e9;
  --text-2: #b3b9ab;
  --text-3: #92998c;
  --accent: #b6dc2a;
  --accent-hover: #c5e851;
  --accent-soft: rgba(182, 220, 42, 0.11);
  --on-accent: #12140d;
  --approved: #71d391;
  --approved-soft: rgba(113, 211, 145, 0.1);
  --declined: #ff7468;
  --declined-soft: rgba(255, 116, 104, 0.1);
  --declined-text: #ff9a91;
  --declined-muted: #d98a83;
  --warn: #e7a94b;
  --placeholder: #747c70;
  --icon-muted: #697063;
  --toast-bg: #242820;
  --toast-error-bg: #2b1b19;
  --shadow: 0 1px 3px rgba(4, 8, 3, 0.35);
  --radius-card: 16px;
  --radius-control: 11px;
  --nav-h: 76px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 1000;
  transform: translateY(-160%);
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  transition: transform 160ms var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
  background: var(--page);
  border-inline: 1px solid rgba(238, 241, 233, 0.03);
}

.top-bar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 7px 22px rgba(182, 220, 42, 0.16);
}

.brand-mark svg {
  width: 19px;
  height: 19px;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-meta,
.section-kicker {
  color: var(--text-3);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.gateway-badge,
.server-proxy-state {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 10px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.status-dot {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: var(--approved);
  box-shadow: 0 0 0 3px var(--approved-soft);
}

.auth-banner {
  margin: 10px 16px 0;
  padding: 11px 13px;
  border: 1px solid rgba(255, 116, 104, 0.25);
  border-radius: var(--radius-control);
  background: var(--declined-soft);
  color: var(--declined-text);
  font-size: 12px;
  line-height: 1.45;
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 20px 18px calc(var(--nav-h) + 22px);
  scrollbar-width: thin;
  scrollbar-color: var(--surface-inset) transparent;
}

.view.active {
  display: flex;
  flex-direction: column;
  animation: view-in 220ms var(--ease) both;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 18px;
}

.view-heading h1 {
  margin-top: 4px;
  font-size: 24px;
  line-height: 1.08;
  letter-spacing: -0.025em;
  font-weight: 680;
  text-wrap: balance;
}

.build-label {
  color: var(--text-3);
  font-family: "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  font-size: 10px;
}

.work-panel,
.control-panel,
.profile-card,
.stat-box,
.setting-row {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.work-panel {
  margin-bottom: 12px;
  padding: 15px;
  border-radius: var(--radius-card);
}

.panel-head {
  min-height: 34px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.field-description {
  margin-top: 3px;
  color: var(--text-3);
  font-size: 11px;
}

.input-count {
  min-width: 58px;
  padding: 4px 7px;
  border-radius: 7px;
  background: var(--surface-inset);
  color: var(--text-2);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.cards-textarea {
  width: 100%;
  height: 136px;
  min-height: 136px;
  max-height: 240px;
  display: block;
  resize: vertical;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  outline: none;
  appearance: none;
  background: var(--surface-inset) !important;
  color: var(--text) !important;
  -webkit-text-fill-color: var(--text);
  caret-color: var(--accent);
  font-family: "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  transition: border-color 150ms, box-shadow 150ms, background 150ms;
}

.cards-textarea:hover {
  border-color: var(--border-strong);
}

.cards-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.cards-textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.cards-textarea::placeholder {
  color: var(--placeholder) !important;
  -webkit-text-fill-color: var(--placeholder);
  opacity: 1;
}

.cards-textarea.small {
  height: 108px;
  min-height: 108px;
}

.format-hint {
  margin-top: 8px;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.45;
  text-wrap: pretty;
}

.format-hint code {
  margin-left: 3px;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: "SFMono-Regular", "Cascadia Code", Consolas, monospace;
}

.control-panel {
  display: grid;
  grid-template-columns: 1fr 176px;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  padding: 14px 15px;
  border-radius: var(--radius-card);
}

.control-copy .format-hint {
  margin-top: 4px;
}

.thread-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-inset);
}

.thread-btn {
  min-width: 40px;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: color 140ms, background 140ms, box-shadow 140ms;
}

.thread-btn:hover:not(:disabled) {
  color: var(--text);
}

.thread-btn.active {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 2px 8px rgba(8, 12, 4, 0.32);
}

.thread-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-start,
.btn-stop {
  width: 100%;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  border-radius: var(--radius-control);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  transition: transform 150ms var(--ease), background 150ms, border-color 150ms;
}

.btn-start {
  justify-content: space-between;
  padding: 0 17px 0 19px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 9px 28px rgba(182, 220, 42, 0.14);
}

.btn-start svg {
  width: 19px;
  height: 19px;
}

.btn-start:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-start:active:not(:disabled) {
  transform: translateY(0);
}

.btn-start:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-stop {
  padding: 0 16px;
  border: 1px solid rgba(255, 116, 104, 0.28);
  background: var(--declined-soft);
  color: var(--declined-text);
}

.stop-square {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: currentColor;
}

.hidden {
  display: none !important;
}

.progress-section {
  margin-bottom: 15px;
  padding: 2px 1px;
}

.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.run-status,
.progress-text {
  color: var(--text-3);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.run-status.is-running {
  color: var(--accent);
}

.progress-bar {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-inset);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 280ms var(--ease);
}

.results-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 9px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
}

.tab {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
  transition: color 140ms, background 140ms;
}

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

.tab.active {
  background: var(--surface-inset);
  color: var(--text);
}

.tab[data-tab="approved"].active {
  color: var(--approved);
}

.tab[data-tab="declined"].active {
  color: var(--declined);
}

.tab span {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  place-items: center;
  margin-left: 5px;
  padding-inline: 5px;
  border-radius: 6px;
  background: rgba(238, 241, 233, 0.06);
  color: currentColor;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.results-panel {
  min-height: 194px;
  max-height: 300px;
  overflow-y: auto;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.empty-state {
  min-height: 178px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--text-3);
  text-align: center;
}

.empty-state strong {
  margin-top: 5px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 650;
}

.empty-state p {
  font-size: 10.5px;
}

.empty-icon {
  width: 33px;
  height: 33px;
  color: var(--icon-muted);
}

.result-item {
  position: relative;
  margin-bottom: 5px;
  padding: 11px 40px 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  cursor: pointer;
  transition: background 140ms, border-color 140ms;
}

.result-item:last-child {
  margin-bottom: 0;
}

.result-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-inset);
}

.result-item::after {
  content: "COPY";
  position: absolute;
  top: 50%;
  right: 11px;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.result-item.approved {
  background: linear-gradient(90deg, var(--approved-soft), var(--surface-raised) 38%);
}

.result-item.declined {
  background: linear-gradient(90deg, var(--declined-soft), var(--surface-raised) 38%);
}

.result-line {
  overflow: hidden;
  color: var(--text);
  font-family: "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-reason {
  margin-top: 4px;
  color: var(--text-3);
  font-size: 10px;
  line-height: 1.35;
}

.result-item.approved .result-reason {
  color: var(--approved);
}

.result-item.declined .result-reason {
  color: var(--declined-muted);
}

.profile-card {
  margin-bottom: 12px;
  padding: 26px 18px 22px;
  border-radius: var(--radius-card);
  text-align: center;
}

.avatar {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border: 1px solid rgba(182, 220, 42, 0.3);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 21px;
  font-weight: 750;
  transform: translateY(-1px);
}

.profile-card h2 {
  font-size: 17px;
  letter-spacing: -0.015em;
}

.profile-id {
  margin-top: 5px;
  color: var(--text-3);
  font-family: "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  font-size: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 8px;
}

.stat-box {
  min-height: 94px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 15px 12px;
  border-radius: var(--radius-card);
  text-align: left;
}

.stat-value {
  color: var(--text);
  font-size: 25px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.035em;
}

.stat-label {
  color: var(--text-3);
  font-size: 10px;
}

.approved-color { color: var(--approved); }
.declined-color { color: var(--declined); }

.settings-group {
  margin-bottom: 16px;
}

.settings-group.work-panel {
  margin-bottom: 16px;
}

.settings-title {
  margin: 0 2px 7px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.setting-row {
  min-height: 51px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-control);
  color: var(--text-2);
  font-size: 12px;
}

.setting-row + .setting-row {
  margin-top: 6px;
}

.setting-value {
  color: var(--text);
  font-family: "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  font-size: 10.5px;
  font-weight: 650;
}

.about-text {
  padding: 2px;
  color: var(--text-3);
  font-size: 11px;
  line-height: 1.6;
  text-wrap: pretty;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  z-index: 100;
  width: 100%;
  max-width: 520px;
  height: var(--nav-h);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  transform: translateX(-50%);
  border-top: 1px solid var(--border);
  background: rgba(20, 22, 19, 0.96);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  position: relative;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 9.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color 150ms;
}

.nav-item::before {
  content: "";
  position: absolute;
  top: 0;
  width: 24px;
  height: 2px;
  border-radius: 0 0 3px 3px;
  background: transparent;
}

.nav-item.active {
  color: var(--accent);
}

.nav-item.active::before {
  background: var(--accent);
}

.nav-icon {
  width: 20px;
  height: 20px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 14px);
  z-index: 500;
  max-width: calc(100% - 36px);
  transform: translate(-50%, 12px);
  padding: 10px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--toast-bg);
  color: var(--text);
  box-shadow: 0 14px 36px rgba(3, 7, 2, 0.45);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.toast.error {
  border-color: rgba(255, 116, 104, 0.28);
  background: var(--toast-error-bg);
  color: var(--declined-text);
}

@media (max-width: 380px) {
  .top-bar,
  .view {
    padding-inline: 14px;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .thread-buttons {
    width: 100%;
  }

  .brand-meta {
    display: none;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-box {
    min-height: 76px;
  }
}

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