:root {
  --bg: #f3f7f5;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --line: #dbe5e1;
  --line-strong: #c7d6d0;
  --ink: #17231f;
  --muted: #64736d;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e1f2ee;
  --danger: #b4233c;
  --danger-soft: #fae8ec;
  --warning: #a15c06;
  --terminal: #111a18;
  --shadow: 0 18px 55px rgba(32, 61, 51, 0.08);
  --radius: 8px;
  --font-sans: Geist, "Avenir Next", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", "Cascadia Code", "Roboto Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  letter-spacing: 0;
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(rgba(15, 118, 110, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 118, 110, 0.025) 1px, transparent 1px),
    var(--bg);
  background-size: 24px 24px;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
summary,
select,
input[type="checkbox"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.2);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px max(24px, calc((100vw - 1440px) / 2));
  border-bottom: 1px solid rgba(199, 214, 208, 0.85);
  background: rgba(248, 251, 250, 0.92);
  backdrop-filter: blur(16px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.brand,
.brand > div:last-child,
.header-meta,
.panel-heading,
.result-heading,
.proxy-title,
.details-summary,
.actions,
.result-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand > div:last-child {
  align-items: baseline;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid #0a5c56;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}

.header-meta {
  gap: 8px;
}

.service-status,
.stack-badge,
.status-badge,
.country-badge,
.result-ready {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.service-status {
  gap: 7px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #25a36f;
  animation: breathe 2.4s ease-in-out infinite;
}

.stack-badge {
  font-family: var(--font-mono);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(320px, 0.72fr);
  gap: 18px;
  width: min(1440px, calc(100% - 48px));
  margin: 22px auto 0;
  align-items: start;
}

.workspace-panel,
.status-panel,
.log-panel,
.result-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.workspace-panel {
  overflow: hidden;
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 16px 20px 0;
  padding: 12px 14px;
  border: 1px solid #c7e2d9;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: #f1faf7;
}

.notice svg {
  flex: 0 0 auto;
  width: 18px;
  margin-top: 2px;
  color: var(--accent);
  stroke-width: 1.8;
}

.notice strong,
.notice p {
  display: block;
  margin: 0;
}

.notice p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.form-section,
.advanced-block.settings-block {
  padding: 26px 28px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.section-index {
  padding-top: 2px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
}

.section-heading h2,
.panel-heading strong,
.result-heading strong {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field > label,
.result-panel > label {
  color: #33423d;
  font-size: 12px;
  font-weight: 700;
}

.field-help {
  color: var(--muted);
  font-size: 11px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fbfdfc;
  color: var(--ink);
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

input,
select {
  min-height: 42px;
  padding: 9px 11px;
}

textarea {
  min-height: 90px;
  padding: 11px 12px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}

#credential {
  min-height: 142px;
}

input:hover,
textarea:hover,
select:hover {
  border-color: #aebfb8;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.08);
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: #93a19c;
}

.advanced-block {
  margin-top: 14px;
}

.advanced-block > summary {
  list-style: none;
}

.advanced-block > summary::-webkit-details-marker {
  display: none;
}

.details-summary {
  width: fit-content;
  gap: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.details-summary svg {
  width: 15px;
  stroke-width: 1.8;
}

.advanced-block[open] .details-summary {
  margin-bottom: 14px;
}

.route-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  list-style: none;
  overflow: hidden;
}

.route-strip li {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 78px;
  padding: 13px;
  background: var(--surface-soft);
}

.route-strip li + li {
  border-left: 1px solid var(--line);
}

.route-icon,
.result-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #c7e2d9;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}

.route-icon svg,
.result-icon svg {
  width: 17px;
  stroke-width: 1.8;
}

.route-strip strong,
.route-strip small {
  display: block;
}

.route-strip strong {
  font-size: 12px;
}

.route-strip small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.step-number {
  display: none;
}

.country-badge {
  min-height: 22px;
  padding: 2px 7px;
  border-color: #b8d9ce;
  background: #edf8f4;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
}

.proxy-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.proxy-column {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.proxy-title {
  justify-content: space-between;
  margin-bottom: 13px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  margin-top: 14px;
  color: #3d4c47;
  font-size: 12px;
  font-weight: 600;
}

.check-row input {
  width: 17px;
  min-height: 17px;
  accent-color: var(--accent);
}

.settings-block {
  margin-top: 0;
}

.settings-block fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.settings-block legend {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 11px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  background: var(--surface-soft);
}

.form-footer strong,
.form-footer small {
  display: block;
}

.form-footer strong {
  font-size: 12px;
}

.form-footer small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.actions,
.result-actions {
  gap: 8px;
}

.button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 750;
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), background 180ms ease, border-color 180ms ease;
}

.button {
  min-height: 40px;
  padding: 9px 14px;
  font-size: 12px;
}

.button svg,
.text-button svg {
  width: 15px;
  stroke-width: 2;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.secondary {
  border-color: var(--line-strong);
  background: var(--surface);
  color: #34433e;
}

.button.secondary:hover {
  border-color: #9db2aa;
  background: #f6f9f8;
}

.button:active,
.text-button:active {
  transform: translateY(1px) scale(0.99);
}

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

.spin {
  animation: spin 900ms linear infinite;
}

.task-rail {
  position: sticky;
  top: 94px;
  display: grid;
  gap: 14px;
}

.status-panel,
.log-panel,
.result-panel {
  padding: 18px;
}

.panel-heading {
  justify-content: space-between;
  gap: 12px;
}

.status-badge {
  min-height: 22px;
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 9px;
}

.status-badge.running {
  border-color: #b8d9ce;
  background: var(--accent-soft);
  color: var(--accent);
}

.status-badge.done {
  border-color: #b8d9ce;
  background: #e6f6ef;
  color: #18794e;
}

.status-badge.error {
  border-color: #efc3cc;
  background: var(--danger-soft);
  color: var(--danger);
}

.progress-ring {
  position: relative;
  display: grid;
  width: 142px;
  height: 142px;
  margin: 24px auto 18px;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--progress), #e6eeeb 0);
  transition: background 400ms ease;
}

.progress-ring::before {
  position: absolute;
  width: 116px;
  height: 116px;
  border: 1px solid rgba(199, 214, 208, 0.8);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  content: "";
}

.progress-value {
  position: relative;
  display: flex;
  align-items: baseline;
  color: var(--ink);
  font-family: var(--font-mono);
  font-weight: 800;
}

.progress-value span {
  font-size: 31px;
}

.progress-value small {
  margin-left: 2px;
  color: var(--muted);
  font-size: 12px;
}

.status-panel > h3 {
  margin: 0;
  text-align: center;
  font-size: 14px;
}

.status-panel > p {
  margin: 4px 0 18px;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
}

.status-steps {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
  list-style: none;
}

.status-steps li {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 9px;
  align-items: center;
  padding: 10px 2px;
  border-bottom: 1px solid #edf2f0;
}

.status-steps li:last-child {
  border-bottom: 0;
}

.step-dot {
  position: relative;
  width: 10px;
  height: 10px;
  border: 2px solid #c3cfca;
  border-radius: 50%;
  background: var(--surface);
}

.status-steps li.active .step-dot {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.status-steps li.done .step-dot {
  border-color: var(--accent);
  background: var(--accent);
}

.status-steps li.error .step-dot {
  border-color: var(--danger);
  background: var(--danger);
}

.status-steps strong,
.status-steps small {
  display: block;
}

.status-steps strong {
  font-size: 11px;
}

.status-steps small {
  margin-top: 1px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
}

.text-button {
  padding: 4px 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
}

.text-button:hover {
  color: var(--accent);
}

.terminal {
  position: relative;
  display: block;
  min-height: 184px;
  max-height: 260px;
  margin-top: 12px;
  padding: 14px;
  overflow: auto;
  border: 1px solid #24332f;
  border-radius: 6px;
  background: var(--terminal);
  color: #c8d6d1;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.terminal::before {
  position: sticky;
  top: 0;
  display: block;
  width: 6px;
  height: 6px;
  margin-bottom: 10px;
  border-radius: 50%;
  background: #53bc88;
  box-shadow: 12px 0 #c8a35d, 24px 0 #b96370;
  content: "";
}

.terminal-empty {
  position: absolute;
  inset: 45px 18px 18px;
  display: grid;
  place-items: center;
  align-content: center;
  color: #6f827b;
  text-align: center;
}

.terminal-empty svg {
  width: 24px;
  margin-bottom: 6px;
  stroke-width: 1.5;
}

.terminal-empty p {
  max-width: 22ch;
  margin: 0;
  font-family: var(--font-sans);
  font-size: 11px;
}

.terminal.has-logs .terminal-empty {
  display: none;
}

#terminal-lines {
  display: block;
}

.result-panel {
  border-top: 3px solid var(--accent);
}

.result-panel.is-hidden {
  display: none;
}

.result-heading {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
}

.result-heading small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.result-ready {
  min-height: 22px;
  border-color: #b8d9ce;
  background: #e6f6ef;
  color: #18794e;
  font-family: var(--font-mono);
  font-size: 9px;
}

.result-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 16px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
}

.result-meta > div {
  min-width: 0;
  padding: 10px;
  background: var(--surface-soft);
}

.result-meta span,
.result-meta strong {
  display: block;
}

.result-meta span {
  color: var(--muted);
  font-size: 9px;
}

.result-meta strong {
  margin-top: 3px;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#result-link {
  min-height: 70px;
  margin: 7px 0 10px;
  color: var(--accent-strong);
}

.result-actions .button {
  flex: 1;
}

.page-footer {
  display: flex;
  justify-content: space-between;
  width: min(1440px, calc(100% - 48px));
  margin: 22px auto 0;
  padding: 18px 2px 28px;
  color: #7b8984;
  font-family: var(--font-mono);
  font-size: 9px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(380px, calc(100vw - 32px));
  padding: 11px 14px;
  border: 1px solid #b8d9ce;
  border-radius: 6px;
  background: #173c36;
  color: white;
  box-shadow: 0 12px 36px rgba(23, 60, 54, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.toast.error {
  border-color: #8e2f42;
  background: #6f1d2d;
}

@keyframes breathe {
  0%, 100% { opacity: 0.55; transform: scale(0.86); }
  50% { opacity: 1; transform: scale(1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 1040px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 320px;
    width: min(100% - 28px, 1120px);
  }

  .route-strip {
    grid-template-columns: 1fr;
  }

  .route-strip li + li {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .proxy-grid,
  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 780px) {
  .topbar {
    position: static;
    min-height: auto;
    padding: 12px 16px;
  }

  .brand > div:last-child {
    display: block;
  }

  .brand p,
  .stack-badge {
    display: none;
  }

  .layout {
    grid-template-columns: 1fr;
    width: calc(100% - 24px);
    margin-top: 12px;
  }

  .task-rail {
    position: static;
  }

  .form-section,
  .advanced-block.settings-block {
    padding: 22px 18px;
  }

  .form-footer {
    align-items: stretch;
    flex-direction: column;
    padding: 16px 18px;
  }

  .actions,
  .actions .button {
    width: 100%;
  }

  .proxy-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .result-meta {
    grid-template-columns: 1fr;
  }

  .page-footer {
    width: calc(100% - 32px);
  }

  .page-footer span:last-child {
    display: none;
  }
}

@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;
  }
}
