:root {
  --ink: #142028;
  --ink-soft: #3a4a56;
  --paper: #e8eef2;
  --paper-2: #f4f7f9;
  --panel: #ffffff;
  --line: #c5d0d8;
  --accent: #0f7a5f;
  --accent-hover: #0c634d;
  --amber: #c45c16;
  --danger: #b42318;
  --ok: #0f7a5f;
  --idle: #7a8a96;
  --shadow: 0 12px 40px rgba(20, 32, 40, 0.08);
  --radius: 10px;
  --font-display: "Outfit", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-display);
  color: var(--ink);
  background: linear-gradient(165deg, #d9e4eb 0%, var(--paper) 42%, #f0ebe3 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(20, 32, 40, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 32, 40, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at 50% 20%, black 20%, transparent 75%);
  z-index: 0;
}

.top,
.tool-nav,
.shell,
.foot {
  position: relative;
  z-index: 1;
}

.tool-nav {
  display: flex;
  gap: 0.3rem;
  padding: 0.4rem clamp(1rem, 4vw, 2.5rem) 0.8rem;
}

.tool-nav a {
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 700;
}

.tool-nav a[aria-current="page"] { background: var(--ink); color: white; }
.tool-nav a:hover:not([aria-current="page"]) { background: var(--panel); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { background: #b8e6d4; color: var(--ink); }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem clamp(1rem, 4vw, 2.5rem) 0.75rem;
  animation: rise 0.55s ease-out both;
}

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

.brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--accent) 0%, #1a9a78 55%, var(--amber) 100%);
  box-shadow: 0 6px 18px rgba(15, 122, 95, 0.28);
  position: relative;
  flex-shrink: 0;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 28% 18%;
  border-radius: 2px;
  background: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.9) 0 2px,
    transparent 2px 5px
  );
  opacity: 0.85;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 500;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  transition: border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.status-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--idle);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.status-pill[data-state="connected"] {
  color: var(--ok);
  border-color: rgba(15, 122, 95, 0.35);
  box-shadow: 0 0 0 3px rgba(15, 122, 95, 0.08);
}

.status-pill[data-state="connected"] .status-dot {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(15, 122, 95, 0.15);
  animation: pulse 1.8s ease-in-out infinite;
}

.status-pill[data-state="reconnecting"] {
  color: var(--amber);
  border-color: rgba(196, 92, 22, 0.4);
}

.status-pill[data-state="reconnecting"] .status-dot {
  background: var(--amber);
  animation: pulse 0.9s ease-in-out infinite;
}

.status-pill[data-state="error"] {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.35);
}

.status-pill[data-state="error"] .status-dot {
  background: var(--danger);
}

.shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.5rem clamp(0.75rem, 3vw, 2rem) 1.5rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  animation: rise 0.65s 0.08s ease-out both;
}

.workspace {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(260px, 340px);
  gap: 0.85rem;
  align-items: start;
}

.workspace[data-sidebar="closed"] {
  grid-template-columns: auto minmax(0, 1fr) minmax(260px, 340px);
}

.workspace-main {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}

.sidebar-open-btn {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 0.45rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  align-self: start;
  position: sticky;
  top: 1rem;
  transition: background 0.2s ease, color 0.2s ease;
}

.sidebar-open-btn:hover {
  background: var(--paper-2);
  color: var(--ink);
}

.workspace[data-sidebar="open"] .sidebar-open-btn {
  display: none;
}

.sidebar {
  display: none;
  width: min(280px, 78vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

.workspace[data-sidebar="open"] .sidebar {
  display: flex;
  flex-direction: column;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 0.95rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

.sidebar-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sidebar-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.95rem;
}

.sidebar-toggles {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.sidebar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

.front-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  padding: 0.75rem 0.95rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.front-toggle {
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-2);
}

#pauseBtn[aria-pressed="true"] {
  background: rgba(196, 92, 22, 0.12);
  border-color: rgba(196, 92, 22, 0.45);
  color: var(--amber);
}

.latest-panel {
  padding: 1.15rem 1.25rem;
  background: #101820;
  border: 1px solid #24313c;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.latest-caption {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8aa0b0;
}

.latest-value {
  margin: 0.55rem 0 0;
  font-family: var(--font-mono);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 500;
  color: #b8e6d4;
  word-break: break-word;
  line-height: 1.25;
}

.latest-meta {
  margin: 0.55rem 0 0;
  font-size: 0.85rem;
  color: #6f8798;
}

.workspace-main.latest-mode .monitor {
  max-height: 180px;
}

.workspace-main.latest-mode .output {
  min-height: 80px;
  max-height: 120px;
}

.toolbar,
.composer {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  padding: 0.95rem 1.1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field-group label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

select,
#sendInput {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select:focus,
#sendInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 122, 95, 0.15);
}

select:disabled,
#sendInput:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 0.5rem;
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  margin-left: auto;
  padding-bottom: 0.2rem;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
}

.btn {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease,
    box-shadow 0.2s ease, opacity 0.2s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.98);
}

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

.btn-primary {
  background: var(--ink);
  color: #f5f8fa;
}

.btn-primary:hover:not(:disabled) {
  background: #1e2f3a;
  box-shadow: 0 6px 16px rgba(20, 32, 40, 0.22);
}

.btn-accent {
  background: var(--accent);
  color: #f4fffb;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 6px 16px rgba(15, 122, 95, 0.28);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--paper-2);
  color: var(--ink);
}

.monitor {
  flex: 1;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  background: #101820;
  border-radius: var(--radius);
  border: 1px solid #24313c;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 0.7s 0.12s ease-out both;
}

.monitor-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #8aa0b0;
  background: #0c1319;
  border-bottom: 1px solid #1c2832;
}

.output {
  flex: 1;
  margin: 0;
  padding: 0.85rem 1rem 1.1rem;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.55;
  color: #d7e4ee;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 280px;
  max-height: min(58vh, 640px);
}

.output .ts {
  color: #6f8798;
  margin-right: 0.55rem;
}

.output .rx {
  color: #b8e6d4;
}

.output .tx {
  color: #f0c18a;
}

.output .sys {
  color: #8aa0b0;
  font-style: italic;
}

.output .hex {
  color: #9fd0ff;
}

.composer {
  align-items: flex-end;
}

.composer #sendInput {
  flex: 1;
  min-width: 160px;
}

.line-ending {
  min-width: 8.5rem;
}

.hint {
  margin: 0;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: rgba(180, 35, 24, 0.08);
  border: 1px solid rgba(180, 35, 24, 0.25);
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 500;
}

.hero-check {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding: 1.15rem 1.25rem 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  top: 1rem;
}

.result-card {
  padding: 1.1rem 1.2rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.result-label {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.result-detail {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.45;
  max-width: 40rem;
}

.result-card[data-result="waiting"] {
  border-color: rgba(196, 92, 22, 0.35);
  background: rgba(196, 92, 22, 0.08);
}

.result-card[data-result="waiting"] .result-label {
  color: var(--amber);
}

.result-card[data-result="working"],
.result-card[data-result="matched"] {
  border-color: rgba(15, 122, 95, 0.4);
  background: rgba(15, 122, 95, 0.1);
  box-shadow: 0 0 0 4px rgba(15, 122, 95, 0.08);
}

.result-card[data-result="working"] .result-label,
.result-card[data-result="matched"] .result-label {
  color: var(--ok);
}

.result-card[data-result="nodata"],
.result-card[data-result="error"] {
  border-color: rgba(180, 35, 24, 0.35);
  background: rgba(180, 35, 24, 0.07);
}

.result-card[data-result="nodata"] .result-label,
.result-card[data-result="error"] .result-label {
  color: var(--danger);
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.steps li {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  color: var(--ink-soft);
  font-size: 0.98rem;
  font-weight: 500;
  line-height: 1.4;
}

.step-num {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #f5f8fa;
  font-size: 0.8rem;
  font-weight: 700;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.hero-actions .btn {
  flex: 1 1 auto;
}

.btn-lg {
  padding: 0.75rem 1.35rem;
  font-size: 1.05rem;
}

.support-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.expect-field input,
#expectText,
.sidebar #sendInput {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  outline: none;
}

#expectText:focus,
.sidebar #sendInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 122, 95, 0.15);
}

.sidebar select {
  width: 100%;
}

.monitor {
  flex: 1;
  min-height: 360px;
}

.output {
  min-height: 280px;
  max-height: min(62vh, 640px);
}

.foot {
  padding: 0 1rem 1.4rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.foot a {
  color: var(--accent);
  font-weight: 600;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.7;
  }
}

@media (max-width: 980px) {
  .workspace,
  .workspace[data-sidebar="closed"],
  .workspace[data-sidebar="open"] {
    grid-template-columns: 1fr;
  }

  .sidebar-open-btn {
    writing-mode: horizontal-tb;
    transform: none;
    width: 100%;
    position: static;
    padding: 0.65rem 1rem;
  }

  .workspace[data-sidebar="open"] .sidebar-open-btn {
    display: none;
  }

  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
  }

  .hero-check {
    position: static;
    order: -1;
  }

  .sidebar-open-btn {
    order: 0;
  }

  .sidebar {
    order: 1;
  }

  .workspace-main {
    order: 2;
  }
}

@media (max-width: 720px) {
  .top {
    flex-direction: column;
    align-items: flex-start;
  }

  .toggles {
    margin-left: 0;
    width: 100%;
  }

  .composer {
    align-items: stretch;
  }

  .hero-actions .btn,
  .front-bar .btn {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* html2canvas re-runs entrance animations (opacity:0) — freeze UI while capturing */
html.capturing-screenshot,
html.capturing-screenshot * {
  animation: none !important;
  transition: none !important;
}

html.capturing-screenshot .top,
html.capturing-screenshot .shell,
html.capturing-screenshot .monitor,
html.capturing-screenshot .foot,
html.capturing-screenshot .hero-check,
html.capturing-screenshot .sidebar,
html.capturing-screenshot .front-bar,
html.capturing-screenshot .latest-panel {
  opacity: 1 !important;
  transform: none !important;
}
