:root {
  --bg: #06080b;
  --bg2: #0b1016;
  --panel: rgba(14, 19, 27, 0.9);
  --panel2: rgba(18, 25, 35, 0.95);
  --border: #263241;
  --border-strong: #3b4a5d;
  --text: #edf3fa;
  --muted: #93a4b8;
  --red: #d8443e;
  --red-bright: #ff5e56;
  --blue: #59a8ff;
  --green: #37d27d;
  --yellow: #f3c14f;
  --danger: #ff5f56;
  --shadow: 0 10px 70px rgba(0, 0, 0, 0.5);
  --radius: 22px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(216, 68, 62, 0.12), transparent 20%),
    radial-gradient(circle at bottom right, rgba(89, 168, 255, 0.08), transparent 22%),
    linear-gradient(180deg, #05070a 0%, #090d12 100%);
}

body {
  padding: 24px;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255,255,255,0.025) 0px,
      rgba(255,255,255,0.025) 1px,
      transparent 2px,
      transparent 4px
    );
  opacity: 0.08;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 55%, rgba(0,0,0,0.35) 100%);
}

.app {
  position: relative;
  max-width: 1240px;
  margin: 0 auto;
  background: rgba(10, 14, 19, 0.88);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 26px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)),
    linear-gradient(90deg, rgba(216, 68, 62, 0.08), rgba(89, 168, 255, 0.03));
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.logo-wrap {
  width: 66px;
  height: 66px;
  border-radius: 18px;
  background: linear-gradient(180deg, #181f2a, #0e131b);
  border: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.04),
    0 0 18px rgba(216, 68, 62, 0.12);
  flex-shrink: 0;
}

.logo-fallback {
  font-weight: 900;
  font-size: 28px;
  color: var(--red);
  letter-spacing: 1px;
  text-shadow: 0 0 12px rgba(216, 68, 62, 0.35);
}

.title {
  margin: 0;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.3px;
}

.title-row-wrap {
  min-width: 0;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.github-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: #5a5a5a;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.github-btn:hover {
  transform: translateY(-1px);
  background: #1a2432;
  border-color: var(--border-strong);
}

.github-btn:active {
  transform: translateY(0);
}

.github-btn svg {
  width: 14px;
  height: 14px;
  min-width: 14px;
  min-height: 14px;
  display: block;
}

.github-btn.icon-only {
  padding: 6px;
  width: 32px;
  height: 32px;
  justify-content: center;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  max-width: 760px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  border-radius: 999px;
  background: #0b1016;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 10px rgba(255, 95, 86, 0.45);
}

.dot.connected {
  background: var(--green);
  box-shadow: 0 0 10px rgba(55, 210, 125, 0.45);
}

.dot.waiting {
  background: var(--yellow);
  box-shadow: 0 0 10px rgba(243, 193, 79, 0.45);
}

.main {
  display: grid;
  grid-template-columns: 430px 1fr;
  min-height: 680px;
}

.sidebar {
  padding: 24px;
  border-right: 1px solid rgba(255,255,255,0.06);
  background:
    linear-gradient(180deg, rgba(14, 19, 27, 0.98), rgba(10, 15, 22, 0.98));
}

.workspace {
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(12, 16, 22, 0.98), rgba(8, 12, 18, 0.98));
}

.card {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.025),
    0 0 0 1px rgba(255,255,255,0.01);
  position: relative;
  overflow: hidden;
}

.card + .card { margin-top: 18px; }

.card-title {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.2px;
  position: relative;
  z-index: 1;
}

.card-subtitle {
  margin: -4px 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  position: relative;
  z-index: 1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.2px;
}

input, select {
  width: 100%;
  border: 1px solid var(--border);
  background: #091018;
  color: var(--text);
  border-radius: 13px;
  padding: 14px 15px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input::placeholder {
  color: #6c7d92;
}

input:focus, select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(216, 68, 62, 0.15);
  background: #0b131d;
}

.input-wrap {
  position: relative;
  width: 100%;
  overflow: visible;
}

#pass {
  width: 100%;
  padding-right: 78px;
}

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  height: 30px;
  min-width: 54px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #111822;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.password-toggle:hover,
.password-toggle:active {
  transform: translateY(-50%);
  background: #1a2432;
  color: var(--text);
}

.firmware-error {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 95, 86, 0.35);
  background: rgba(255, 95, 86, 0.08);
  color: #ffb4b0;
  font-size: 13px;
  font-weight: 700;
}

.manifest-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}

.manifest-pill {
  padding: 7px 10px;
  border-radius: 999px;
  background: #0b1016;
  border: 1px solid var(--border);
  font-weight: 800;
}

.firmware-box {
  display: grid;
  gap: 16px;
  margin-top: 6px;
}

.firmware-note {
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

button {
  border: none;
  border-radius: 13px;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: #1d2734;
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) { background: #243243; }

.btn-primary {
  background: linear-gradient(180deg, var(--red), #bc3934);
  color: white;
  box-shadow: 0 10px 24px rgba(216, 68, 62, 0.22);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--red-bright), #d6463f);
  box-shadow: 0 12px 28px rgba(216, 68, 62, 0.28);
}

.btn-flash {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  background: linear-gradient(180deg, #ff5e56, #d8443e);
  color: white;
  box-shadow: 0 6px 18px rgba(216,68,62,0.35);
  transition: all .15s ease;
}

.btn-flash:hover:not(:disabled) {
  background: linear-gradient(180deg, #ff726b, #e34d47);
}

.hint-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.hud-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.hud-box {
  padding: 15px;
  border-radius: 16px;
  background: linear-gradient(180deg, #101720, #0a1016);
  border: 1px solid var(--border);
}

.hud-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.45px;
  text-transform: uppercase;
}

.hud-value {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 900;
  color: var(--text);
}

.hud-value.red { color: #ff7a73; }
.hud-value.blue { color: #7ec0ff; }
.hud-value.green { color: #72e3a5; }

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.small-btn {
  background: #17212c;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 9px 12px;
  font-size: 12px;
  border-radius: 10px;
  font-weight: 800;
}

.small-btn:hover {
  background: #1c2937;
  color: var(--text);
}

.log {
  background: #060a0f;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  min-height: 440px;
  max-height: 640px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
  line-height: 1.55;
  color: #d9e5f2;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.25);
  margin-bottom: 2px;
}

.log div {
  margin-bottom: 3px;
}

.log-time {
  color: #6e8098;
  margin-right: 6px;
}

.log-info {
  color: #d9e5f2;
}

.log-esp {
  color: #7ec0ff;
}

.log-success {
  color: #72e3a5;
}

.log-error {
  color: #ff7a73;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  min-width: 300px;
  max-width: 380px;
  padding: 16px 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, #102017, #0d1813);
  border: 1px solid rgba(55, 210, 125, 0.34);
  color: #ebfff2;
  box-shadow: 0 18px 36px rgba(0,0,0,0.35);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 50;
}

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

.toast-title {
  font-size: 15px;
  font-weight: 900;
  margin-bottom: 4px;
}

.toast-text {
  font-size: 13px;
  color: #cbf3db;
  line-height: 1.45;
}

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

  .status-strip {
    justify-content: flex-start;
  }

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

  .sidebar {
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }
}

@media (max-width: 640px) {
  body { padding: 14px; }
  .topbar, .sidebar, .workspace { padding: 18px; }
  .actions, .hud-grid { grid-template-columns: 1fr; }
  .title { font-size: 24px; }
  .title-row { align-items: flex-start; }
  .github-btn { padding: 8px 11px; }
}